Get rid of direct references from dumpmenu.cpp to emulation thread
This commit is contained in:
parent
aa7e15aa27
commit
77abaa2d98
5 changed files with 90 additions and 47 deletions
|
@ -16,6 +16,7 @@ UI services.
|
||||||
*********************************************************************************************************************/
|
*********************************************************************************************************************/
|
||||||
|
|
||||||
class emulator_instance;
|
class emulator_instance;
|
||||||
|
class dumper_factory_base;
|
||||||
|
|
||||||
struct project_author_info
|
struct project_author_info
|
||||||
{
|
{
|
||||||
|
@ -37,6 +38,23 @@ struct project_author_info
|
||||||
std::string prefix;
|
std::string prefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct dumper_information_1
|
||||||
|
{
|
||||||
|
//The factory for this dumper.
|
||||||
|
dumper_factory_base* factory;
|
||||||
|
//Name of this dumper.
|
||||||
|
std::string name;
|
||||||
|
//Is this dumper active?
|
||||||
|
bool active;
|
||||||
|
//Modes available (first is internal name, second is human-readable one).
|
||||||
|
std::map<std::string, std::string> modes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct dumper_information
|
||||||
|
{
|
||||||
|
std::map<std::string, dumper_information_1> dumpers;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill branch name map.
|
* Fill branch name map.
|
||||||
*/
|
*/
|
||||||
|
@ -77,5 +95,18 @@ project_author_info UI_load_author_info(emulator_instance& instance);
|
||||||
* Save project author info.
|
* Save project author info.
|
||||||
*/
|
*/
|
||||||
void UI_save_author_info(emulator_instance& instance, project_author_info& info);
|
void UI_save_author_info(emulator_instance& instance, project_author_info& info);
|
||||||
|
/**
|
||||||
|
* Get available dumpers.
|
||||||
|
*/
|
||||||
|
dumper_information UI_get_dumpers(emulator_instance& instance);
|
||||||
|
/**
|
||||||
|
* Start dumping.
|
||||||
|
*/
|
||||||
|
void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const std::string& mode,
|
||||||
|
const std::string& prefix);
|
||||||
|
/**
|
||||||
|
* End dumping.
|
||||||
|
*/
|
||||||
|
void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
class dumper_menu_monitor;
|
class dumper_menu_monitor;
|
||||||
class dumper_info;
|
class dumper_info;
|
||||||
|
class dumper_information_1;
|
||||||
|
|
||||||
class dumper_menu : public wxMenu
|
class dumper_menu : public wxMenu
|
||||||
{
|
{
|
||||||
|
@ -14,12 +15,13 @@ public:
|
||||||
dumper_menu(wxWindow* win, int wxid_low, int wxid_high);
|
dumper_menu(wxWindow* win, int wxid_low, int wxid_high);
|
||||||
~dumper_menu();
|
~dumper_menu();
|
||||||
void on_select(wxCommandEvent& e);
|
void on_select(wxCommandEvent& e);
|
||||||
void update(const std::map<std::string, dumper_info>& new_dumpers);
|
void update();
|
||||||
private:
|
private:
|
||||||
dumper_menu_monitor* monitor;
|
dumper_menu_monitor* monitor;
|
||||||
wxWindow* pwin;
|
wxWindow* pwin;
|
||||||
int wxid_range_low;
|
int wxid_range_low;
|
||||||
int wxid_range_high;
|
int wxid_range_high;
|
||||||
|
std::map<std::string, dumper_information_1> existing_dumpers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "core/advdumper.hpp"
|
||||||
#include "core/command.hpp"
|
#include "core/command.hpp"
|
||||||
#include "core/dispatch.hpp"
|
#include "core/dispatch.hpp"
|
||||||
#include "core/instance.hpp"
|
#include "core/instance.hpp"
|
||||||
|
@ -17,6 +18,19 @@ namespace
|
||||||
fill_namemap(p, i, namemap, childmap);
|
fill_namemap(p, i, namemap, childmap);
|
||||||
childmap[id] = s;
|
childmap[id] = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_dumperinfo(emulator_instance& inst, std::map<std::string, dumper_information_1>& new_dumpers,
|
||||||
|
dumper_factory_base* d)
|
||||||
|
{
|
||||||
|
struct dumper_information_1 inf;
|
||||||
|
inf.factory = d;
|
||||||
|
inf.name = d->name();
|
||||||
|
std::set<std::string> mset = d->list_submodes();
|
||||||
|
for(auto i : mset)
|
||||||
|
inf.modes[i] = d->modename(i);
|
||||||
|
inf.active = inst.mdumper->busy(d);
|
||||||
|
new_dumpers[d->id()] = inf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_movie_state();
|
void update_movie_state();
|
||||||
|
@ -160,3 +174,30 @@ void UI_save_author_info(emulator_instance& inst, project_author_info& info)
|
||||||
inst.command->invoke("run-lua " + i);
|
inst.command->invoke("run-lua " + i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dumper_information UI_get_dumpers(emulator_instance& inst)
|
||||||
|
{
|
||||||
|
dumper_information x;
|
||||||
|
inst.iqueue->run([&inst, &x]() {
|
||||||
|
std::set<dumper_factory_base*> dset = dumper_factory_base::get_dumper_set();
|
||||||
|
for(auto i : dset)
|
||||||
|
update_dumperinfo(inst, x.dumpers, i);
|
||||||
|
});
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const std::string& mode,
|
||||||
|
const std::string& prefix)
|
||||||
|
{
|
||||||
|
lsnes_instance.iqueue->run([&inst, &factory, mode, prefix]() {
|
||||||
|
inst.mdumper->start(factory, mode, prefix);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory)
|
||||||
|
{
|
||||||
|
lsnes_instance.iqueue->run([&inst, &factory]() {
|
||||||
|
auto in = inst.mdumper->get_instance(&factory);
|
||||||
|
delete in;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "core/dispatch.hpp"
|
#include "core/dispatch.hpp"
|
||||||
#include "core/instance.hpp"
|
#include "core/instance.hpp"
|
||||||
#include "core/project.hpp"
|
#include "core/project.hpp"
|
||||||
|
#include "core/ui-services.hpp"
|
||||||
|
|
||||||
#include "platform/wxwidgets/menu_dump.hpp"
|
#include "platform/wxwidgets/menu_dump.hpp"
|
||||||
#include "platform/wxwidgets/platform.hpp"
|
#include "platform/wxwidgets/platform.hpp"
|
||||||
|
@ -16,8 +17,6 @@ struct dumper_info
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::map<std::string, dumper_info> existing_dumpers;
|
|
||||||
|
|
||||||
struct dumper_menu_struct
|
struct dumper_menu_struct
|
||||||
{
|
{
|
||||||
int end_wxid;
|
int end_wxid;
|
||||||
|
@ -30,17 +29,6 @@ namespace
|
||||||
std::string last_processed;
|
std::string last_processed;
|
||||||
bool first;
|
bool first;
|
||||||
|
|
||||||
void update_dumperinfo(std::map<std::string, dumper_info>& new_dumpers, dumper_factory_base* d)
|
|
||||||
{
|
|
||||||
struct dumper_info inf;
|
|
||||||
inf.instance = d;
|
|
||||||
inf.name = d->name();
|
|
||||||
std::set<std::string> mset = d->list_submodes();
|
|
||||||
for(auto i : mset)
|
|
||||||
inf.modes[i] = d->modename(i);
|
|
||||||
inf.active = lsnes_instance.mdumper->busy(d);
|
|
||||||
new_dumpers[d->id()] = inf;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class dumper_menu_monitor : public master_dumper::notifier
|
class dumper_menu_monitor : public master_dumper::notifier
|
||||||
|
@ -57,11 +45,7 @@ public:
|
||||||
|
|
||||||
void dumpers_updated() throw()
|
void dumpers_updated() throw()
|
||||||
{
|
{
|
||||||
new_dumpers.clear();
|
runuifun([this]() { if(this->linked) this->linked->update(); });
|
||||||
std::set<dumper_factory_base*> dset = dumper_factory_base::get_dumper_set();
|
|
||||||
for(auto i : dset)
|
|
||||||
update_dumperinfo(new_dumpers, i);
|
|
||||||
runuifun([this]() { if(this->linked) this->linked->update(this->new_dumpers); });
|
|
||||||
}
|
}
|
||||||
void dump_status_change() throw()
|
void dump_status_change() throw()
|
||||||
{
|
{
|
||||||
|
@ -69,7 +53,6 @@ public:
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
dumper_menu* linked;
|
dumper_menu* linked;
|
||||||
std::map<std::string, dumper_info> new_dumpers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,13 +66,7 @@ dumper_menu::dumper_menu(wxWindow* win, int wxid_low, int wxid_high)
|
||||||
wxid_range_high = wxid_high;
|
wxid_range_high = wxid_high;
|
||||||
monitor = new dumper_menu_monitor(this);
|
monitor = new dumper_menu_monitor(this);
|
||||||
lsnes_instance.mdumper->add_notifier(*monitor);
|
lsnes_instance.mdumper->add_notifier(*monitor);
|
||||||
std::map<std::string, dumper_info> new_dumpers;
|
update();
|
||||||
lsnes_instance.iqueue->run([&new_dumpers]() {
|
|
||||||
std::set<dumper_factory_base*> dset = dumper_factory_base::get_dumper_set();
|
|
||||||
for(auto i : dset)
|
|
||||||
update_dumperinfo(new_dumpers, i);
|
|
||||||
});
|
|
||||||
update(new_dumpers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dumper_menu::~dumper_menu()
|
dumper_menu::~dumper_menu()
|
||||||
|
@ -104,14 +81,9 @@ void dumper_menu::on_select(wxCommandEvent& e)
|
||||||
if(id < wxid_range_low || id > wxid_range_high)
|
if(id < wxid_range_low || id > wxid_range_high)
|
||||||
return;
|
return;
|
||||||
for(auto i : menustructure) {
|
for(auto i : menustructure) {
|
||||||
std::string error_str;
|
dumper_factory_base* t = existing_dumpers[i.first].factory;
|
||||||
dumper_factory_base* t = existing_dumpers[i.first].instance;
|
|
||||||
if(i.second.end_wxid == id) {
|
if(i.second.end_wxid == id) {
|
||||||
//Execute end of dump operation.
|
UI_end_dump(lsnes_instance, *t);
|
||||||
lsnes_instance.iqueue->run([t, &error_str]() {
|
|
||||||
auto in = lsnes_instance.mdumper->get_instance(t);
|
|
||||||
delete in;
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(i.second.start_wxids.count(id)) {
|
if(i.second.start_wxids.count(id)) {
|
||||||
|
@ -156,22 +128,19 @@ void dumper_menu::on_select(wxCommandEvent& e)
|
||||||
}
|
}
|
||||||
if(prefix == "")
|
if(prefix == "")
|
||||||
return;
|
return;
|
||||||
lsnes_instance.iqueue->run([t, mode, prefix, &error_str]() {
|
|
||||||
try {
|
try {
|
||||||
CORE().mdumper->start(*t, mode, prefix);
|
UI_start_dump(lsnes_instance, *t, mode, prefix);
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
error_str = e.what();
|
show_exception(this->pwin, "Error starting dump", "", e);
|
||||||
}});
|
}
|
||||||
if(error_str != "")
|
|
||||||
wxMessageBox(towxstring(error_str), _T("Error starting dump"), wxICON_EXCLAMATION |
|
|
||||||
wxOK, pwin);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumper_menu::update(const std::map<std::string, dumper_info>& new_dumpers)
|
void dumper_menu::update()
|
||||||
{
|
{
|
||||||
|
dumper_information dinfo = UI_get_dumpers(lsnes_instance);
|
||||||
//Destroy all old entries.
|
//Destroy all old entries.
|
||||||
for(auto i : menustructure) {
|
for(auto i : menustructure) {
|
||||||
struct dumper_menu_struct& m = i.second;
|
struct dumper_menu_struct& m = i.second;
|
||||||
|
@ -186,7 +155,7 @@ void dumper_menu::update(const std::map<std::string, dumper_info>& new_dumpers)
|
||||||
int id = wxid_range_low;
|
int id = wxid_range_low;
|
||||||
first = true;
|
first = true;
|
||||||
menustructure.clear();
|
menustructure.clear();
|
||||||
for(auto i : new_dumpers) {
|
for(auto i : dinfo.dumpers) {
|
||||||
if(!first)
|
if(!first)
|
||||||
menustructure[last_processed].sep = AppendSeparator();
|
menustructure[last_processed].sep = AppendSeparator();
|
||||||
last_processed = i.first;
|
last_processed = i.first;
|
||||||
|
@ -209,5 +178,5 @@ void dumper_menu::update(const std::map<std::string, dumper_info>& new_dumpers)
|
||||||
menustructure[i.first].end_wxid = id++;
|
menustructure[i.first].end_wxid = id++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
existing_dumpers = new_dumpers;
|
existing_dumpers = dinfo.dumpers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ void wxeditor_authors::on_luasel(wxCommandEvent& e)
|
||||||
void wxeditor_authors_display(wxWindow* parent)
|
void wxeditor_authors_display(wxWindow* parent)
|
||||||
{
|
{
|
||||||
modal_pause_holder hld;
|
modal_pause_holder hld;
|
||||||
if(!lsnes_instance.mlogic) {
|
if(!*lsnes_instance.mlogic) {
|
||||||
show_message_ok(parent, "No movie", "Can't edit authors of nonexistent movie", wxICON_EXCLAMATION);
|
show_message_ok(parent, "No movie", "Can't edit authors of nonexistent movie", wxICON_EXCLAMATION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue