More sweeping instance variables up

This commit is contained in:
Ilari Liusvaara 2014-06-02 11:41:41 +03:00
parent 2e36040731
commit 6ba5fdfca8
9 changed files with 102 additions and 100 deletions

View file

@ -55,17 +55,17 @@ void wxeditor_hotkeys_display(wxWindow* parent);
void wxeditor_memorywatches_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_subtitles_display(wxWindow* parent, emulator_instance& inst);
std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
void show_wxeditor_voicesub(wxWindow* parent);
void show_wxeditor_voicesub(wxWindow* parent, emulator_instance& inst);
void open_rom_select_window();
void open_new_project_window(wxWindow* parent, emulator_instance& inst);
void show_conflictwindow(wxWindow* parent);
void open_vumeter_window(wxWindow* parent);
void wxeditor_movie_display(wxWindow* parent);
void wxeditor_movie_update();
void open_vumeter_window(wxWindow* parent, emulator_instance& inst);
void wxeditor_movie_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_movie_update(emulator_instance& inst);
void wxeditor_autohold_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_tasinput_display(wxWindow* parent);
void wxeditor_tasinput_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_macro_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_hexedit_display(wxWindow* parent);
void wxeditor_hexedit_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_multitrack_display(wxWindow* parent, emulator_instance& inst);
bool wxeditor_plugin_manager_display(wxWindow* parent);
void wxeditor_tracelog_display(wxWindow* parent, emulator_instance& inst, int cpuid, const std::string& cpuname);
@ -73,14 +73,14 @@ void wxeditor_disassembler_display(wxWindow* parent, emulator_instance& inst);
void wxeditor_plugin_manager_notify_fail(const std::string& libname);
//Auxillary windows.
void wxwindow_memorysearch_display();
void wxwindow_memorysearch_update();
void wxeditor_hexeditor_update();
void wxwindow_memorysearch_display(emulator_instance& inst);
void wxwindow_memorysearch_update(emulator_instance& inst);
void wxeditor_hexeditor_update(emulator_instance& inst);
class memory_search;
memory_search* wxwindow_memorysearch_active();
bool wxeditor_hexeditor_available();
bool wxeditor_hexeditor_jumpto(uint64_t addr);
void wxwindow_tasinput_update();
memory_search* wxwindow_memorysearch_active(emulator_instance& inst);
bool wxeditor_hexeditor_available(emulator_instance& inst);
bool wxeditor_hexeditor_jumpto(emulator_instance& inst, uint64_t addr);
void wxwindow_tasinput_update(emulator_instance& inst);
template<typename T>
void runuifun(T fn)

View file

@ -30,7 +30,7 @@ class wxeditor_hexedit;
namespace
{
const size_t maxvaluelen = 8; //The length of longest value type.
wxeditor_hexedit* editor;
std::map<emulator_instance*, wxeditor_hexedit*> editor;
struct val_type
{
@ -280,7 +280,7 @@ public:
~wxeditor_hexedit()
{
destructing = true;
editor = NULL;
editor.erase(&inst);
}
bool ShouldPreventAppExit() const
{
@ -288,7 +288,7 @@ public:
}
void set_search_status()
{
bool e = wxwindow_memorysearch_active();
bool e = wxwindow_memorysearch_active(inst);
searchmenu->FindItem(wxID_SEARCH_DISQUALIFY)->Enable(e);
searchmenu->FindItem(wxID_SEARCH_PREV)->Enable(e);
searchmenu->FindItem(wxID_SEARCH_NEXT)->Enable(e);
@ -481,12 +481,12 @@ public:
}
void on_search_discard(wxCommandEvent& e)
{
auto p = wxwindow_memorysearch_active();
auto p = wxwindow_memorysearch_active(inst);
if(!p)
return;
if(hpanel->seloff < hpanel->vmasize) {
p->dq_range(hpanel->vmabase + hpanel->seloff, hpanel->vmabase + hpanel->seloff);
wxwindow_memorysearch_update();
wxwindow_memorysearch_update(inst);
hpanel->seloff = p->cycle_candidate_vma(hpanel->vmabase + hpanel->seloff, true) -
hpanel->vmabase;
rescroll_panel();
@ -524,7 +524,7 @@ public:
}
void on_search_prevnext(wxCommandEvent& e)
{
auto p = wxwindow_memorysearch_active();
auto p = wxwindow_memorysearch_active(inst);
if(!p)
return;
if(hpanel->seloff < hpanel->vmasize) {
@ -791,7 +791,7 @@ invalid_bookmark:
uint8_t* _value = value;
inst.iqueue->run([_vmabase, _vmasize, paint_offset, _seloff, _value, _lines,
this]() {
memory_search* memsearch = wxwindow_memorysearch_active();
memory_search* memsearch = wxwindow_memorysearch_active(inst);
//Paint the stuff
for(ssize_t j = 0; j < _lines; j++) {
uint64_t addr = paint_offset + j * 16;
@ -904,31 +904,33 @@ private:
int hex_input_state;
};
void wxeditor_hexedit_display(wxWindow* parent)
void wxeditor_hexedit_display(wxWindow* parent, emulator_instance& inst)
{
if(editor)
if(editor.count(&inst))
return;
try {
editor = new wxeditor_hexedit(parent, lsnes_instance);
editor->Show();
editor[&inst] = new wxeditor_hexedit(parent, inst);
editor[&inst]->Show();
} catch(...) {
}
}
void wxeditor_hexeditor_update()
void wxeditor_hexeditor_update(emulator_instance& inst)
{
if(editor)
editor->updated();
if(editor.count(&inst))
editor[&inst]->updated();
}
bool wxeditor_hexeditor_available()
bool wxeditor_hexeditor_available(emulator_instance& inst)
{
return editor;
return editor.count(&inst);
}
bool wxeditor_hexeditor_jumpto(uint64_t addr)
bool wxeditor_hexeditor_jumpto(emulator_instance& inst, uint64_t addr)
{
if(editor)
editor->jumpto(addr);
return editor;
if(editor.count(&inst)) {
editor[&inst]->jumpto(addr);
return true;
} else
return false;
}

View file

@ -833,7 +833,7 @@ private:
namespace
{
wxeditor_movie* movieeditor_open;
std::map<emulator_instance*, wxeditor_movie*> movieeditor_open;
//Find the first real editable subframe.
//Call only in emulator thread.
@ -2354,7 +2354,7 @@ bool wxeditor_movie::ShouldPreventAppExit() const { return false; }
void wxeditor_movie::on_close(wxCommandEvent& e)
{
movieeditor_open = NULL;
movieeditor_open.erase(&inst);
Destroy();
closing = true;
}
@ -2363,7 +2363,7 @@ void wxeditor_movie::on_wclose(wxCloseEvent& e)
{
bool wasc = closing;
closing = true;
movieeditor_open = NULL;
movieeditor_open.erase(&inst);
if(!wasc)
Destroy();
}
@ -2383,13 +2383,13 @@ void wxeditor_movie::on_focus_wrong(wxFocusEvent& e)
moviepanel->SetFocus();
}
void wxeditor_movie_display(wxWindow* parent)
void wxeditor_movie_display(wxWindow* parent, emulator_instance& inst)
{
if(movieeditor_open)
if(movieeditor_open.count(&inst))
return;
wxeditor_movie* v = new wxeditor_movie(parent, lsnes_instance);
wxeditor_movie* v = new wxeditor_movie(parent, inst);
v->Show();
movieeditor_open = v;
movieeditor_open[&inst] = v;
}
void wxeditor_movie::on_keyboard_down(wxKeyEvent& e)
@ -2402,8 +2402,8 @@ void wxeditor_movie::on_keyboard_up(wxKeyEvent& e)
handle_wx_keyboard(inst, e, false);
}
void wxeditor_movie_update()
void wxeditor_movie_update(emulator_instance& inst)
{
if(movieeditor_open)
movieeditor_open->update();
if(movieeditor_open.count(&inst))
movieeditor_open[&inst]->update();
}

View file

@ -175,7 +175,7 @@ private:
namespace
{
wxeditor_tasinput* tasinput_open;
std::map<emulator_instance*, wxeditor_tasinput*> tasinput_open;
}
wxeditor_tasinput::xypanel::xypanel(wxWindow* win, emulator_instance& _inst, wxSizer* s, control_triple _t,
@ -350,7 +350,7 @@ wxeditor_tasinput::wxeditor_tasinput(wxWindow* parent, emulator_instance& _inst)
//Close the window.
bool wasc = closing;
closing = true;
tasinput_open = NULL;
tasinput_open.erase(&this->inst);
inst.controls->tasinput_enable(false);
if(!wasc)
Destroy();
@ -545,7 +545,7 @@ void wxeditor_tasinput::on_wclose(wxCloseEvent& e)
{
bool wasc = closing;
closing = true;
tasinput_open = NULL;
tasinput_open.erase(&inst);
inst.controls->tasinput_enable(false);
if(!wasc)
Destroy();
@ -720,24 +720,24 @@ wxeditor_tasinput::control_triple* wxeditor_tasinput::find_triple(unsigned contr
return NULL;
}
void wxeditor_tasinput_display(wxWindow* parent)
void wxeditor_tasinput_display(wxWindow* parent, emulator_instance& inst)
{
if(tasinput_open)
if(tasinput_open.count(&inst) || tasinput_open[&inst])
return;
wxeditor_tasinput* v;
try {
v = new wxeditor_tasinput(parent, lsnes_instance);
v = new wxeditor_tasinput(parent, inst);
} catch(std::runtime_error& e) {
wxMessageBox(_T("No controllers present"), _T("Error"), wxICON_EXCLAMATION | wxOK, parent);
return;
}
v->Show();
tasinput_open = v;
lsnes_instance.controls->tasinput_enable(true);
tasinput_open[&inst] = v;
inst.controls->tasinput_enable(true);
}
void wxwindow_tasinput_update()
void wxwindow_tasinput_update(emulator_instance& inst)
{
if(tasinput_open)
tasinput_open->call_screen_update();
}
if(tasinput_open.count(&inst))
tasinput_open[&inst]->call_screen_update();
}

View file

@ -19,7 +19,7 @@
namespace
{
bool voicesub_open = false;
std::set<emulator_instance*> voicesub_open;
}
class wxeditor_voicesub : public wxDialog
@ -319,8 +319,8 @@ void wxeditor_voicesub::on_refresh(wxCommandEvent& e)
void wxeditor_voicesub::on_close(wxCommandEvent& e)
{
voicesub_open.erase(&inst);
Destroy();
voicesub_open = false;
}
void wxeditor_voicesub::refresh()
@ -368,16 +368,16 @@ void wxeditor_voicesub::on_wclose(wxCloseEvent& e)
closing = true;
if(!wasc)
Destroy();
voicesub_open = false;
voicesub_open.erase(&inst);
}
bool wxeditor_voicesub::ShouldPreventAppExit() const { return false; }
void show_wxeditor_voicesub(wxWindow* parent)
void show_wxeditor_voicesub(wxWindow* parent, emulator_instance& inst)
{
if(voicesub_open)
if(voicesub_open.count(&inst))
return;
wxeditor_voicesub* v = new wxeditor_voicesub(parent, lsnes_instance);
wxeditor_voicesub* v = new wxeditor_voicesub(parent, inst);
v->Show();
voicesub_open = true;
voicesub_open.insert(&inst);
}

View file

@ -430,8 +430,8 @@ bool lsnes_app::OnInit()
{ threads::alock h(if_mutex); if_update_screen = false; }
if(main_window)
main_window->notify_update();
wxwindow_memorysearch_update();
wxwindow_tasinput_update();
wxwindow_memorysearch_update(lsnes_instance);
wxwindow_tasinput_update(lsnes_instance);
});
});
statusupdate.set(lsnes_instance.dispatch->status_update, []() {
@ -442,8 +442,8 @@ bool lsnes_app::OnInit()
{ threads::alock h(if_mutex); if_update_status = false; }
if(main_window)
main_window->notify_update_status();
wxeditor_movie_update();
wxeditor_hexeditor_update();
wxeditor_movie_update(lsnes_instance);
wxeditor_hexeditor_update(lsnes_instance);
});
});
actionupdate.set(lsnes_instance.dispatch->action_update, []() { main_window->action_updated(); });

View file

@ -1585,7 +1585,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
wxeditor_subtitles_display(this, inst);
return;
case wxID_EDIT_VSUBTITLES:
show_wxeditor_voicesub(this);
show_wxeditor_voicesub(this, inst);
return;
case wxID_EDIT_MEMORYWATCH:
wxeditor_memorywatches_display(this, inst);
@ -1641,10 +1641,10 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
return;
}
case wxID_MEMORY_SEARCH:
wxwindow_memorysearch_display();
wxwindow_memorysearch_display(inst);
return;
case wxID_TASINPUT:
wxeditor_tasinput_display(this);
wxeditor_tasinput_display(this, inst);
return;
case wxID_ABOUT: {
std::ostringstream str;
@ -1775,13 +1775,13 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
show_conflictwindow(this);
return;
case wxID_VUDISPLAY:
open_vumeter_window(this);
open_vumeter_window(this, inst);
return;
case wxID_DISASSEMBLER:
wxeditor_disassembler_display(this, inst);
return;
case wxID_MOVIE_EDIT:
wxeditor_movie_display(this);
wxeditor_movie_display(this, inst);
return;
case wxID_NEW_PROJECT:
open_new_project_window(this, inst);
@ -1800,7 +1800,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
do_load_rom_image(NULL);
return;
case wxID_HEXEDITOR:
wxeditor_hexedit_display(this);
wxeditor_hexedit_display(this, inst);
return;
case wxID_MULTITRACK:
wxeditor_multitrack_display(this, inst);

View file

@ -70,7 +70,7 @@ namespace
{8, 2, ""},
};
wxwindow_memorysearch* mwatch;
std::map<emulator_instance*, wxwindow_memorysearch*> mwatch;
const char* datatypes[] = {
"signed byte",
@ -307,7 +307,7 @@ public:
}
void dump_candidates_text();
private:
friend memory_search* wxwindow_memorysearch_active();
friend memory_search* wxwindow_memorysearch_active(emulator_instance& inst);
friend class panel;
template<typename T> T promptvalue(bool& bad);
void update();
@ -811,7 +811,7 @@ void wxwindow_memorysearch::panel::get_selection(uint64_t& first, uint64_t& last
wxwindow_memorysearch::~wxwindow_memorysearch()
{
delete msearch;
mwatch = NULL;
mwatch.erase(&inst);
}
bool wxwindow_memorysearch::ShouldPreventAppExit() const
@ -981,7 +981,7 @@ void wxwindow_memorysearch::on_mouse2(wxMouseEvent& e)
}
menu.Append(wxID_ADD, wxT("Add watch..."))->Enable(some_selected);
menu.Append(wxID_SHOW_HEXEDITOR, wxT("Select in hex editor"))->Enable(selcount == 1 &&
wxeditor_hexeditor_available());
wxeditor_hexeditor_available(inst));
menu.Append(wxID_POKE, wxT("Poke..."))->Enable(selcount == 1);
menu.AppendSeparator();
menu.Append(wxID_DISQUALIFY, wxT("Disqualify"))->Enable(some_selected);
@ -996,7 +996,7 @@ void wxwindow_memorysearch::on_mouse2(wxMouseEvent& e)
void wxwindow_memorysearch::on_close(wxCloseEvent& e)
{
Destroy();
mwatch = NULL;
mwatch.erase(&inst);
}
void wxwindow_memorysearch::auto_update()
@ -1022,7 +1022,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
msearch->dq_range(i->base, i->last_address());
vma_info[i->name] = std::make_pair(i->base, i->size);
}
wxeditor_hexeditor_update();
wxeditor_hexeditor_update(inst);
} else if(id == wxID_UPDATE) {
update();
} else if(id == wxID_TYPESELECT) {
@ -1084,7 +1084,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
inst.iqueue->run([addr, ms]() { ms->dq_range(addr, addr); });
}
matches->set_selection(0, 0);
wxeditor_hexeditor_update();
wxeditor_hexeditor_update(inst);
} else if(id == wxID_SET_REGIONS) {
wxwindow_memorysearch_vmasel* d = new wxwindow_memorysearch_vmasel(this, inst, vmas_enabled);
if(d->ShowModal() == wxID_OK)
@ -1098,7 +1098,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
for(auto i : inst.memory->get_regions())
if(memory_search::searchable_region(i) && !vmas_enabled.count(i->name))
msearch->dq_range(i->base, i->last_address());
wxeditor_hexeditor_update();
wxeditor_hexeditor_update(inst);
} else if(id == wxID_POKE) {
uint64_t start, end;
matches->get_selection(start, end);
@ -1126,7 +1126,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
for(uint64_t r = start; r < end; r++) {
if(!addresses.count(r))
continue;
wxeditor_hexeditor_jumpto(addresses[r]);
wxeditor_hexeditor_jumpto(inst, addresses[r]);
return;
}
} else if(id >= wxID_BUTTONS_BASE && id < wxID_BUTTONS_BASE +
@ -1140,7 +1140,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
undohistory.pop_back(); //Shouldn't be undoable.
undoitem->Enable(undohistory.size());
}
wxeditor_hexeditor_update();
wxeditor_hexeditor_update(inst);
} else if(id == wxID_MENU_DUMP_CANDIDATES) {
dump_candidates_text();
} else if(id == wxID_MENU_SAVE_PREVMEM) {
@ -1212,26 +1212,26 @@ template<typename T> T wxwindow_memorysearch::promptvalue(bool& bad)
return val2;
}
void wxwindow_memorysearch_display()
void wxwindow_memorysearch_display(emulator_instance& inst)
{
if(mwatch) {
mwatch->Raise();
if(mwatch.count(&inst)) {
mwatch[&inst]->Raise();
return;
}
mwatch = new wxwindow_memorysearch(lsnes_instance);
mwatch->Show();
mwatch[&inst] = new wxwindow_memorysearch(inst);
mwatch[&inst]->Show();
}
void wxwindow_memorysearch_update()
void wxwindow_memorysearch_update(emulator_instance& inst)
{
if(mwatch)
mwatch->auto_update();
if(mwatch.count(&inst))
mwatch[&inst]->auto_update();
}
memory_search* wxwindow_memorysearch_active()
memory_search* wxwindow_memorysearch_active(emulator_instance& inst)
{
if(mwatch)
return mwatch->msearch;
if(mwatch.count(&inst))
return mwatch[&inst]->msearch;
else
return NULL;
}

View file

@ -13,7 +13,7 @@
namespace
{
bool vumeter_open = false;
std::set<emulator_instance*> vumeter_open;
unsigned vu_to_pixels(float vu)
{
@ -396,7 +396,7 @@ void wxwin_vumeter::on_close(wxCommandEvent& e)
{
closing = true;
Destroy();
vumeter_open = false;
vumeter_open.erase(&inst);
}
void wxwin_vumeter::on_wclose(wxCloseEvent& e)
@ -405,16 +405,16 @@ void wxwin_vumeter::on_wclose(wxCloseEvent& e)
closing = true;
if(!wasc)
Destroy();
vumeter_open = false;
vumeter_open.erase(&inst);
}
bool wxwin_vumeter::ShouldPreventAppExit() const { return false; }
void open_vumeter_window(wxWindow* parent)
void open_vumeter_window(wxWindow* parent, emulator_instance& inst)
{
if(vumeter_open)
if(vumeter_open.count(&inst))
return;
wxwin_vumeter* v = new wxwin_vumeter(parent, lsnes_instance);
wxwin_vumeter* v = new wxwin_vumeter(parent, inst);
v->Show();
vumeter_open = true;
vumeter_open.insert(&inst);
}