diff --git a/include/core/instance.hpp b/include/core/instance.hpp index 2ec47345..f388f3d4 100644 --- a/include/core/instance.hpp +++ b/include/core/instance.hpp @@ -1,6 +1,7 @@ #ifndef _instance__hpp__included__ #define _instance__hpp__included__ +#include #include "core/command.hpp" #include "core/emustatus.hpp" #include "core/inthread.hpp" @@ -16,6 +17,54 @@ #include "library/keyboard.hpp" #include "library/keyboard-mapper.hpp" +/** + * Information about keypress. + */ +struct keypress_info +{ +/** + * Create null keypress (no modifiers, NULL key and released). + */ + keypress_info(); +/** + * Create new keypress. + */ + keypress_info(keyboard::modifier_set mod, keyboard::key& _key, short _value); +/** + * Create new keypress (two keys). + */ + keypress_info(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value); +/** + * Modifier set. + */ + keyboard::modifier_set modifiers; +/** + * The actual key (first) + */ + keyboard::key* key1; +/** + * The actual key (second) + */ + keyboard::key* key2; +/** + * Value for the press + */ + short value; +}; + +template +void functor_call_helper(void* args) +{ + (*reinterpret_cast(args))(); +} + +template +void functor_call_helper2(void* args) +{ + (*reinterpret_cast(args))(); + delete reinterpret_cast(args); +} + struct emulator_instance { emulator_instance(); @@ -38,6 +87,66 @@ struct emulator_instance command::group command; alias_binds_manager abindmanager; rrdata nrrdata; + //Queue stuff. + threads::lock queue_lock; + threads::cv queue_condition; + std::deque keypresses; + std::deque commands; + std::deque> functions; + volatile uint64_t functions_executed; + volatile uint64_t next_function; + volatile bool system_thread_available; + bool queue_function_run; + +/** + * Queue keypress. + * + * - Can be called from any thread. + * + * Parameter k: The keypress to queue. + */ + void queue(const keypress_info& k) throw(std::bad_alloc); +/** + * Queue command. + * + * - Can be called from any thread. + * + * Parameter c: The command to queue. + */ + void queue(const std::string& c) throw(std::bad_alloc); +/** + * Queue function to be called in emulation thread. + * + * - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads). + * + * Parameter f: The function to execute. + * Parameter arg: Argument to pass to the function. + * Parameter sync: If true, execute function call synchronously, else asynchronously. + */ + void queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc); +/** + * Run all queues. + */ + void run_queues() throw(); +/** + * Call function synchronously in emulation thread. + */ + template + void run(T fn) + { + queue(functor_call_helper, &fn, true); + } +/** + * Queue asynchrous function in emulation thread. + */ + template void run_async(T fn) + { + queue(functor_call_helper2, new T(fn), false); + } +/** + * Run internal queues. + */ + void run_queue(bool unlocked) throw(); }; extern emulator_instance lsnes_instance; diff --git a/include/core/window.hpp b/include/core/window.hpp index 939fcf0c..8edf2735 100644 --- a/include/core/window.hpp +++ b/include/core/window.hpp @@ -11,40 +11,6 @@ #include #include -/** - * Information about keypress. - */ -struct keypress -{ -/** - * Create null keypress (no modifiers, NULL key and released). - */ - keypress(); -/** - * Create new keypress. - */ - keypress(keyboard::modifier_set mod, keyboard::key& _key, short _value); -/** - * Create new keypress (two keys). - */ - keypress(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value); -/** - * Modifier set. - */ - keyboard::modifier_set modifiers; -/** - * The actual key (first) - */ - keyboard::key* key1; -/** - * The actual key (second) - */ - keyboard::key* key2; -/** - * Value for the press - */ - short value; -}; //ROM request. struct rom_request @@ -268,40 +234,10 @@ struct platform * Parameter enable: If true, enable modal pause, else disable it. */ static void set_modal_pause(bool enable) throw(); -/** - * Queue keypress. - * - * - Can be called from any thread. - * - * Parameter k: The keypress to queue. - */ - static void queue(const keypress& k) throw(std::bad_alloc); -/** - * Queue command. - * - * - Can be called from any thread. - * - * Parameter c: The command to queue. - */ - static void queue(const std::string& c) throw(std::bad_alloc); -/** - * Queue function to be called in emulation thread. - * - * - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads). - * - * Parameter f: The function to execute. - * Parameter arg: Argument to pass to the function. - * Parameter sync: If true, execute function call synchronously, else asynchronously. - */ - static void queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc); /** * Run all queues. */ static void run_queues() throw(); -/** - * Set availablinty of system thread. - */ - static void system_thread_available(bool av) throw(); static bool pausing_allowed; static double global_volume; @@ -320,18 +256,6 @@ private: modal_pause_holder& operator=(const modal_pause_holder&); }; -template -void functor_call_helper(void* args) -{ - (*reinterpret_cast(args))(); -} - -template -void runemufn(T fn) -{ - platform::queue(functor_call_helper, &fn, true); -} - /** * If set, queueing synchronous function produces a warning. */ diff --git a/include/platform/wxwidgets/platform.hpp b/include/platform/wxwidgets/platform.hpp index a9380d46..57655e03 100644 --- a/include/platform/wxwidgets/platform.hpp +++ b/include/platform/wxwidgets/platform.hpp @@ -1,6 +1,7 @@ #ifndef _plat_wxwidgets__platform__hpp__included__ #define _plat_wxwidgets__platform__hpp__included__ +#include "core/instance.hpp" #include "core/moviefile.hpp" #include "core/window.hpp" @@ -80,13 +81,6 @@ bool wxeditor_hexeditor_available(); bool wxeditor_hexeditor_jumpto(uint64_t addr); void wxwindow_tasinput_update(); -template -void functor_call_helper2(void* args) -{ - (*reinterpret_cast(args))(); - delete reinterpret_cast(args); -} - template void runuifun(T fn) { @@ -119,9 +113,5 @@ extern bool wxwidgets_exiting; //Some important settings. extern std::map core_selections; -template void runemufn_async(T fn) -{ - platform::queue(functor_call_helper2, new T(fn), false); -} #endif diff --git a/src/core/instance.cpp b/src/core/instance.cpp index 337b7303..5c66215c 100644 --- a/src/core/instance.cpp +++ b/src/core/instance.cpp @@ -2,11 +2,14 @@ #include "core/settings.hpp" #include "core/command.hpp" #include "core/keymapper.hpp" +#include "core/random.hpp" emulator_instance::emulator_instance() : setcache(settings), subtitles(&mlogic), mbranch(&mlogic), mteditor(&mlogic), status(status_A, status_B, status_C), mapper(keyboard, command), abindmanager(*this) { + system_thread_available = false; + queue_function_run = false; status_A.valid = false; status_B.valid = false; status_C.valid = false; @@ -21,3 +24,105 @@ emulator_instance& CORE() { return lsnes_instance; } + +keypress_info::keypress_info() +{ + key1 = NULL; + key2 = NULL; + value = 0; +} + +keypress_info::keypress_info(keyboard::modifier_set mod, keyboard::key& _key, short _value) +{ + modifiers = mod; + key1 = &_key; + key2 = NULL; + value = _value; +} + +keypress_info::keypress_info(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value) +{ + modifiers = mod; + key1 = &_key; + key2 = &_key2; + value = _value; +} + + +void emulator_instance::queue(const keypress_info& k) throw(std::bad_alloc) +{ + threads::alock h(queue_lock); + keypresses.push_back(k); + queue_condition.notify_all(); +} + +void emulator_instance::queue(const std::string& c) throw(std::bad_alloc) +{ + threads::alock h(queue_lock); + commands.push_back(c); + queue_condition.notify_all(); +} + +void emulator_instance::queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc) +{ + if(!system_thread_available) { + f(arg); + return; + } + threads::alock h(queue_lock); + ++next_function; + functions.push_back(std::make_pair(f, arg)); + queue_condition.notify_all(); + if(sync) + while(functions_executed < next_function && system_thread_available) { + threads::cv_timed_wait(queue_condition, h, threads::ustime(10000)); + random_mix_timing_entropy(); + } +} + +void emulator_instance::run_queue(bool unlocked) throw() +{ + if(!unlocked) + queue_lock.lock(); + try { + //Flush keypresses. + while(!keypresses.empty()) { + keypress_info k = keypresses.front(); + keypresses.pop_front(); + queue_lock.unlock(); + if(k.key1) + k.key1->set_state(k.modifiers, k.value); + if(k.key2) + k.key2->set_state(k.modifiers, k.value); + queue_lock.lock(); + queue_function_run = true; + } + //Flush commands. + while(!commands.empty()) { + std::string c = commands.front(); + commands.pop_front(); + queue_lock.unlock(); + lsnes_instance.command.invoke(c); + queue_lock.lock(); + queue_function_run = true; + } + //Flush functions. + while(!functions.empty()) { + std::pair f = functions.front(); + functions.pop_front(); + queue_lock.unlock(); + f.first(f.second); + queue_lock.lock(); + ++functions_executed; + queue_function_run = true; + } + queue_condition.notify_all(); + } catch(std::bad_alloc& e) { + OOM_panic(); + } catch(std::exception& e) { + std::cerr << "Fault inside platform::run_queues(): " << e.what() << std::endl; + exit(1); + } + if(!unlocked) + queue_lock.unlock(); +} diff --git a/src/core/keymapper.cpp b/src/core/keymapper.cpp index 712a1082..e3389079 100644 --- a/src/core/keymapper.cpp +++ b/src/core/keymapper.cpp @@ -33,17 +33,18 @@ void lsnes_gamepads_init() lsnes_gamepads.set_button_cb([](unsigned jnum, unsigned num, bool val) { if(!buttons.count(std::make_pair(jnum, num))) return; - platform::queue(keypress(keyboard::modifier_set(), *buttons[std::make_pair(jnum, num)], val)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), *buttons[std::make_pair(jnum, num)], + val)); }); lsnes_gamepads.set_hat_cb([](unsigned jnum, unsigned num, unsigned val) { if(!hats.count(std::make_pair(jnum, num))) return; - platform::queue(keypress(keyboard::modifier_set(), *hats[std::make_pair(jnum, num)], val)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), *hats[std::make_pair(jnum, num)], val)); }); lsnes_gamepads.set_axis_cb([](unsigned jnum, unsigned num, int16_t val) { if(!axes.count(std::make_pair(jnum, num))) return; - platform::queue(keypress(keyboard::modifier_set(), *axes[std::make_pair(jnum, num)], val)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), *axes[std::make_pair(jnum, num)], val)); }); lsnes_gamepads.set_axismode_cb([](unsigned jnum, unsigned num, int mode, double tolerance) { if(!axes.count(std::make_pair(jnum, num))) diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index 92d14f52..43da3691 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -1226,7 +1226,7 @@ void init_main_callbacks() void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_to_succeed) throw(std::bad_alloc, std::runtime_error) { - platform::system_thread_available(true); + CORE().system_thread_available = true; //Basic initialization. dispatch_set_error_streams(&messages.getstream()); emulation_thread = threads::this_id(); @@ -1341,7 +1341,7 @@ void main_loop(struct loaded_rom& rom, struct moviefile& initial, bool load_has_ information_dispatch::do_dump_end(); core_core::uninstall_all_handlers(); CORE().commentary.kill(); - platform::system_thread_available(false); + CORE().system_thread_available = false; //Kill some things to avoid crashes. debug_core_change(); project_set(NULL, true); diff --git a/src/core/window.cpp b/src/core/window.cpp index 244ca507..19c6f006 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -33,40 +33,10 @@ #define MAXMESSAGES 5000 #define INIT_WIN_SIZE 6 -namespace -{ - volatile bool _system_thread_available = false; -} - -keypress::keypress() -{ - key1 = NULL; - key2 = NULL; - value = 0; -} - -keypress::keypress(keyboard::modifier_set mod, keyboard::key& _key, short _value) -{ - modifiers = mod; - key1 = &_key; - key2 = NULL; - value = _value; -} - -keypress::keypress(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value) -{ - modifiers = mod; - key1 = &_key; - key2 = &_key2; - value = _value; -} - volatile bool platform::do_exit_dummy_event_loop = false; namespace { - bool queue_function_run = false; - command::fnptr<> identify_key(lsnes_cmds, "show-plugins", "Show plugins in use", "Syntax: show-plugins\nShows plugins in use.\n", []() throw(std::bad_alloc, std::runtime_error) { @@ -261,68 +231,10 @@ void platform::fatal_error() throw() namespace { - threads::lock queue_lock; - threads::cv queue_condition; - std::deque keypresses; - std::deque commands; - std::deque> functions; volatile bool normal_pause; volatile bool modal_pause; volatile uint64_t continue_time; - volatile uint64_t next_function; - volatile uint64_t functions_executed; - void init_threading() - { - } - - void internal_run_queues(bool unlocked) throw() - { - init_threading(); - if(!unlocked) - queue_lock.lock(); - try { - //Flush keypresses. - while(!keypresses.empty()) { - keypress k = keypresses.front(); - keypresses.pop_front(); - queue_lock.unlock(); - if(k.key1) - k.key1->set_state(k.modifiers, k.value); - if(k.key2) - k.key2->set_state(k.modifiers, k.value); - queue_lock.lock(); - queue_function_run = true; - } - //Flush commands. - while(!commands.empty()) { - std::string c = commands.front(); - commands.pop_front(); - queue_lock.unlock(); - lsnes_instance.command.invoke(c); - queue_lock.lock(); - queue_function_run = true; - } - //Flush functions. - while(!functions.empty()) { - std::pair f = functions.front(); - functions.pop_front(); - queue_lock.unlock(); - f.first(f.second); - queue_lock.lock(); - ++functions_executed; - queue_function_run = true; - } - queue_condition.notify_all(); - } catch(std::bad_alloc& e) { - OOM_panic(); - } catch(std::exception& e) { - std::cerr << "Fault inside platform::run_queues(): " << e.what() << std::endl; - exit(1); - } - if(!unlocked) - queue_lock.unlock(); - } uint64_t on_idle_time; uint64_t on_timer_time; @@ -330,7 +242,7 @@ namespace { on_idle_time = lua_timed_hook(LUA_TIMED_HOOK_IDLE); on_timer_time = lua_timed_hook(LUA_TIMED_HOOK_TIMER); - queue_function_run = false; + lsnes_instance.queue_function_run = false; } } @@ -338,31 +250,28 @@ namespace void platform::dummy_event_loop() throw() { - init_threading(); while(!do_exit_dummy_event_loop) { - threads::alock h(queue_lock); - internal_run_queues(true); - threads::cv_timed_wait(queue_condition, h, threads::ustime(MAXWAIT)); + threads::alock h(lsnes_instance.queue_lock); + lsnes_instance.run_queue(true); + threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(MAXWAIT)); random_mix_timing_entropy(); } } void platform::exit_dummy_event_loop() throw() { - init_threading(); do_exit_dummy_event_loop = true; - threads::alock h(queue_lock); - queue_condition.notify_all(); + threads::alock h(lsnes_instance.queue_lock); + lsnes_instance.queue_condition.notify_all(); usleep(200000); } void platform::flush_command_queue() throw() { reload_lua_timers(); - queue_function_run = false; + lsnes_instance.queue_function_run = false; if(modal_pause || normal_pause) freeze_time(get_utime()); - init_threading(); bool run_idle = false; while(true) { uint64_t now = get_utime(); @@ -375,11 +284,11 @@ void platform::flush_command_queue() throw() reload_lua_timers(); run_idle = false; } - threads::alock h(queue_lock); - internal_run_queues(true); + threads::alock h(lsnes_instance.queue_lock); + lsnes_instance.run_queue(true); if(!pausing_allowed) break; - if(queue_function_run) + if(lsnes_instance.queue_function_run) reload_lua_timers(); now = get_utime(); uint64_t waitleft = 0; @@ -396,7 +305,7 @@ void platform::flush_command_queue() throw() if(on_timer_time >= now) waitleft = min(waitleft, on_timer_time - now); if(waitleft > 0) { - threads::cv_timed_wait(queue_condition, h, threads::ustime(waitleft)); + threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(waitleft)); random_mix_timing_entropy(); } } else @@ -416,7 +325,6 @@ void platform::wait(uint64_t usec) throw() { reload_lua_timers(); continue_time = get_utime() + usec; - init_threading(); bool run_idle = false; while(true) { uint64_t now = get_utime(); @@ -429,9 +337,9 @@ void platform::wait(uint64_t usec) throw() run_idle = false; reload_lua_timers(); } - threads::alock h(queue_lock); - internal_run_queues(true); - if(queue_function_run) + threads::alock h(lsnes_instance.queue_lock); + lsnes_instance.run_queue(true); + if(lsnes_instance.queue_function_run) reload_lua_timers(); //If usec is 0, never wait (waitleft can be nonzero if time counting screws up). if(!usec) @@ -450,7 +358,7 @@ void platform::wait(uint64_t usec) throw() if(on_timer_time >= now) waitleft = min(waitleft, on_timer_time - now); if(waitleft > 0) { - threads::cv_timed_wait(queue_condition, h, threads::ustime(waitleft)); + threads::cv_timed_wait(lsnes_instance.queue_condition, h, threads::ustime(waitleft)); random_mix_timing_entropy(); } } else @@ -460,10 +368,9 @@ void platform::wait(uint64_t usec) throw() void platform::cancel_wait() throw() { - init_threading(); continue_time = 0; - threads::alock h(queue_lock); - queue_condition.notify_all(); + threads::alock h(lsnes_instance.queue_lock); + lsnes_instance.queue_condition.notify_all(); } void platform::set_modal_pause(bool enable) throw() @@ -471,48 +378,9 @@ void platform::set_modal_pause(bool enable) throw() modal_pause = enable; } -void platform::queue(const keypress& k) throw(std::bad_alloc) -{ - init_threading(); - threads::alock h(queue_lock); - keypresses.push_back(k); - queue_condition.notify_all(); -} - -void platform::queue(const std::string& c) throw(std::bad_alloc) -{ - init_threading(); - threads::alock h(queue_lock); - commands.push_back(c); - queue_condition.notify_all(); -} - -void platform::queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc) -{ - if(!_system_thread_available) { - f(arg); - return; - } - init_threading(); - threads::alock h(queue_lock); - ++next_function; - functions.push_back(std::make_pair(f, arg)); - queue_condition.notify_all(); - if(sync) - while(functions_executed < next_function && _system_thread_available) { - threads::cv_timed_wait(queue_condition, h, threads::ustime(10000)); - random_mix_timing_entropy(); - } -} - void platform::run_queues() throw() { - internal_run_queues(false); -} - -void platform::system_thread_available(bool av) throw() -{ - _system_thread_available = av; + lsnes_instance.run_queue(false); } namespace diff --git a/src/platform/wxwidgets/branchesmenu.cpp b/src/platform/wxwidgets/branchesmenu.cpp index 260085b3..e9bb206c 100644 --- a/src/platform/wxwidgets/branchesmenu.cpp +++ b/src/platform/wxwidgets/branchesmenu.cpp @@ -66,7 +66,7 @@ namespace std::map namemap; std::map> childmap; uint64_t cur = 0; - runemufn([&cur, &namemap, &childmap]() { + lsnes_instance.run([&cur, &namemap, &childmap]() { auto p = project_get(); if(!p) return; fill_namemap(*p, 0, namemap, childmap); @@ -103,7 +103,7 @@ namespace } void call_project_flush() { - runemufn_async([] { + lsnes_instance.run_async([] { auto p = project_get(); if(p) p->flush(); }); @@ -234,7 +234,7 @@ namespace } catch(canceled_exception& e) { return; } - runemufn([this, id, newname]() { + lsnes_instance.run([this, id, newname]() { try { auto p = project_get(); if(p) p->create_branch(id, newname); @@ -252,7 +252,7 @@ namespace { uint64_t id = get_selected_id(); if(id == 0xFFFFFFFFFFFFFFFFULL) return; - runemufn([this, id]() { + lsnes_instance.run([this, id]() { try { auto p = project_get(); if(p) p->set_current_branch(id); @@ -278,7 +278,7 @@ namespace } catch(canceled_exception& e) { return; } - runemufn([this, id, newname]() { + lsnes_instance.run([this, id, newname]() { try { auto p = project_get(); if(p) p->set_branch_name(id, newname); @@ -307,7 +307,7 @@ namespace pid = bsel->get_selection(); if(pid == 0xFFFFFFFFFFFFFFFFULL) return; bsel->Destroy(); - runemufn([this, id, pid]() { + lsnes_instance.run([this, id, pid]() { try { auto p = project_get(); if(p) p->set_parent_branch(id, pid); @@ -326,7 +326,7 @@ namespace { uint64_t id = get_selected_id(); if(id == 0xFFFFFFFFFFFFFFFFULL) return; - runemufn([this, id]() { + lsnes_instance.run([this, id]() { try { auto p = project_get(); if(p) p->delete_branch(id); @@ -433,7 +433,7 @@ void branches_menu::on_select(wxCommandEvent& e) if(!branch_ids.count(id)) return; uint64_t bid = branch_ids[id]; std::string err; - runemufn_async([this, bid]() { + lsnes_instance.run_async([this, bid]() { auto p = project_get(); try { if(p) p->set_current_branch(bid); @@ -453,7 +453,7 @@ void branches_menu::update() { std::map namemap; std::map> childmap; - runemufn([&namemap, &childmap]() { + lsnes_instance.run([&namemap, &childmap]() { auto p = project_get(); if(!p) return; fill_namemap(*p, 0, namemap, childmap); diff --git a/src/platform/wxwidgets/dumpmenu.cpp b/src/platform/wxwidgets/dumpmenu.cpp index 523d448c..9c8d5eae 100644 --- a/src/platform/wxwidgets/dumpmenu.cpp +++ b/src/platform/wxwidgets/dumpmenu.cpp @@ -79,7 +79,7 @@ dumper_menu::dumper_menu(wxWindow* win, int wxid_low, int wxid_high) wxid_range_high = wxid_high; monitor = new dumper_menu_monitor(this); std::map new_dumpers; - runemufn([&new_dumpers]() { + lsnes_instance.run([&new_dumpers]() { std::set dset = adv_dumper::get_dumper_set(); for(auto i : dset) update_dumperinfo(new_dumpers, i); @@ -102,7 +102,7 @@ void dumper_menu::on_select(wxCommandEvent& e) adv_dumper* t = existing_dumpers[i.first].instance; if(i.second.end_wxid == id) { //Execute end of dump operation. - runemufn([t, &error_str]() { + lsnes_instance.run([t, &error_str]() { try { t->end(); } catch(std::exception& e) { @@ -151,7 +151,7 @@ void dumper_menu::on_select(wxCommandEvent& e) } if(prefix == "") return; - runemufn([t, mode, prefix, &error_str]() { + lsnes_instance.run([t, mode, prefix, &error_str]() { try { t->start(mode, prefix); } catch(std::exception& e) { diff --git a/src/platform/wxwidgets/editor-authors.cpp b/src/platform/wxwidgets/editor-authors.cpp index 6d0dbfd8..fd1bae2b 100644 --- a/src/platform/wxwidgets/editor-authors.cpp +++ b/src/platform/wxwidgets/editor-authors.cpp @@ -153,7 +153,7 @@ wxeditor_authors::wxeditor_authors(wxWindow* parent) std::list luascriptlist; std::string gamename; std::string x; - runemufn([&gamename, &x, &luascriptlist, proj]() { + lsnes_instance.run([&gamename, &x, &luascriptlist, proj]() { if(proj) { luascriptlist = proj->luascripts; gamename = proj->gamename; @@ -217,7 +217,7 @@ void wxeditor_authors::on_ok(wxCommandEvent& e) luascriptlist.push_back(tostdstring(luascripts->GetString(i))); bool run_new = autorunlua ? autorunlua->GetValue() : false; - runemufn([gamename, newauthors, pfx, dir, prjname, luascriptlist, run_new, proj]() { + lsnes_instance.run([gamename, newauthors, pfx, dir, prjname, luascriptlist, run_new, proj]() { std::set oldscripts; if(proj) { for(auto i : proj->luascripts) diff --git a/src/platform/wxwidgets/editor-autohold.cpp b/src/platform/wxwidgets/editor-autohold.cpp index 28e5d6bc..f3f487aa 100644 --- a/src/platform/wxwidgets/editor-autohold.cpp +++ b/src/platform/wxwidgets/editor-autohold.cpp @@ -129,7 +129,7 @@ void wxeditor_autohold::on_checkbox(wxCommandEvent& e) bool isaf = (t.afid == id); bool newstate = isaf ? t.afcheck->IsChecked() : t.check->IsChecked(); bool state = false; - runemufn([t, newstate, &state, isaf]() { + lsnes_instance.run([t, newstate, &state, isaf]() { if(isaf) { auto _state = controls.autofire2(t.port, t.controller, t.index); state = (_state.first != 0); @@ -170,7 +170,7 @@ void wxeditor_autohold::update_controls() panels.clear(); std::vector _autoholds; std::vector _controller_labels; - runemufn([&_autoholds, &_controller_labels](){ + lsnes_instance.run([&_autoholds, &_controller_labels](){ std::map next_in_class; controller_frame model = controls.get_blank(); const port_type_set& pts = model.porttypes(); diff --git a/src/platform/wxwidgets/editor-hexedit.cpp b/src/platform/wxwidgets/editor-hexedit.cpp index 9be8b406..2810f145 100644 --- a/src/platform/wxwidgets/editor-hexedit.cpp +++ b/src/platform/wxwidgets/editor-hexedit.cpp @@ -517,7 +517,7 @@ public: } e.endianess = hostendian ? 0 : (littleendian ? -1 : 1); e.scale_div = 1ULL << datatypes[curtype].scale; - runemufn([n, &e]() { lsnes_instance.mwatch.set(n, e); }); + lsnes_instance.run([n, &e]() { lsnes_instance.mwatch.set(n, e); }); } catch(canceled_exception& e) { } } @@ -755,7 +755,7 @@ invalid_bookmark: hex_input_state = -1; if(hpanel->seloff + 1 < hpanel->vmasize) hpanel->seloff++; - runemufn([addr, byte]() {lsnes_instance.memory.write(addr, byte); }); + lsnes_instance.run([addr, byte]() {lsnes_instance.memory.write(addr, byte); }); } hpanel->request_paint(); } @@ -786,7 +786,7 @@ invalid_bookmark: uint64_t _seloff = seloff; int _lines = lines; uint8_t* _value = value; - runemufn([_vmabase, _vmasize, paint_offset, _seloff, _value, _lines, this]() { + lsnes_instance.run([_vmabase, _vmasize, paint_offset, _seloff, _value, _lines, this]() { memory_search* memsearch = wxwindow_memorysearch_active(); //Paint the stuff for(ssize_t j = 0; j < _lines; j++) { diff --git a/src/platform/wxwidgets/editor-memorywatch.cpp b/src/platform/wxwidgets/editor-memorywatch.cpp index 771a3c0e..7294650c 100644 --- a/src/platform/wxwidgets/editor-memorywatch.cpp +++ b/src/platform/wxwidgets/editor-memorywatch.cpp @@ -504,7 +504,7 @@ void wxeditor_memorywatch::on_ok(wxCommandEvent& e) } bool did_error = false; std::string error; - runemufn([this, &it, &did_error, &error]() { + lsnes_instance.run([this, &it, &did_error, &error]() { try { lsnes_instance.mwatch.set(name, it); } catch(std::exception& e) { @@ -622,7 +622,7 @@ void wxeditor_memorywatches::on_rename(wxCommandEvent& e) try { bool exists = false; std::string newname = pick_text(this, "Rename watch", "Enter New name for watch:"); - runemufn([watch, newname, &exists]() { + lsnes_instance.run([watch, newname, &exists]() { exists = !lsnes_instance.mwatch.rename(watch, newname); }); if(exists) @@ -638,7 +638,7 @@ void wxeditor_memorywatches::on_delete(wxCommandEvent& e) { std::string watch = tostdstring(watches->GetStringSelection()); if(watch != "") - runemufn([watch]() { lsnes_instance.mwatch.clear(watch); }); + lsnes_instance.run([watch]() { lsnes_instance.mwatch.clear(watch); }); refresh(); on_memorywatch_change(e); } @@ -668,7 +668,7 @@ void wxeditor_memorywatches::on_close(wxCommandEvent& e) void wxeditor_memorywatches::refresh() { std::set bind; - runemufn([&bind]() { + lsnes_instance.run([&bind]() { bind = lsnes_instance.mwatch.enumerate(); }); watches->Clear(); diff --git a/src/platform/wxwidgets/editor-movie.cpp b/src/platform/wxwidgets/editor-movie.cpp index 21903875..f3c4e722 100644 --- a/src/platform/wxwidgets/editor-movie.cpp +++ b/src/platform/wxwidgets/editor-movie.cpp @@ -1063,7 +1063,7 @@ void wxeditor_movie::_moviepanel::do_toggle_buttons(unsigned idx, uint64_t row1, if(_press_line > line) std::swap(_press_line, line); recursing = true; - runemufn([idx, _press_line, line, _fcontrols, _force_false]() { + lsnes_instance.run([idx, _press_line, line, _fcontrols, _force_false]() { if(!lsnes_instance.mlogic.get_movie().readonly_mode()) return; uint64_t fedit = real_first_editable(*_fcontrols, idx); @@ -1092,7 +1092,7 @@ void wxeditor_movie::_moviepanel::do_alter_axis(unsigned idx, uint64_t row1, uin uint64_t line2 = row2; short value; bool valid = true; - runemufn([idx, line, &value, _fcontrols, &valid]() { + lsnes_instance.run([idx, line, &value, _fcontrols, &valid]() { if(!lsnes_instance.mlogic.get_movie().readonly_mode()) { valid = false; return; @@ -1120,7 +1120,7 @@ void wxeditor_movie::_moviepanel::do_alter_axis(unsigned idx, uint64_t row1, uin } if(line > line2) std::swap(line, line2); - runemufn([idx, line, line2, value, _fcontrols]() { + lsnes_instance.run([idx, line, line2, value, _fcontrols]() { uint64_t fedit = real_first_editable(*_fcontrols, idx); controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; controller_frame_vector::notify_freeze freeze(fv); @@ -1144,7 +1144,7 @@ void wxeditor_movie::_moviepanel::do_sweep_axis(unsigned idx, uint64_t row1, uin bool valid = true; if(line > line2) std::swap(line, line2); - runemufn([idx, line, line2, &value, &value2, _fcontrols, &valid]() { + lsnes_instance.run([idx, line, line2, &value, &value2, _fcontrols, &valid]() { if(!lsnes_instance.mlogic.get_movie().readonly_mode()) { valid = false; return; @@ -1162,7 +1162,7 @@ void wxeditor_movie::_moviepanel::do_sweep_axis(unsigned idx, uint64_t row1, uin }); if(!valid) return; - runemufn([idx, line, line2, value, value2, _fcontrols]() { + lsnes_instance.run([idx, line, line2, value, value2, _fcontrols]() { uint64_t fedit = real_first_editable(*_fcontrols, idx); controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; controller_frame_vector::notify_freeze freeze(fv); @@ -1183,7 +1183,7 @@ void wxeditor_movie::_moviepanel::do_append_frames(uint64_t count) { recursing = true; uint64_t _count = count; - runemufn([_count]() { + lsnes_instance.run([_count]() { if(!lsnes_instance.mlogic.get_movie().readonly_mode()) return; controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; @@ -1228,7 +1228,7 @@ void wxeditor_movie::_moviepanel::do_insert_frame_after(uint64_t row, bool multi recursing = true; frame_controls* _fcontrols = &fcontrols; uint64_t _row = row; - runemufn([_row, _fcontrols, multicount]() { + lsnes_instance.run([_row, _fcontrols, multicount]() { if(!lsnes_instance.mlogic.get_movie().readonly_mode()) return; controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; @@ -1264,7 +1264,7 @@ void wxeditor_movie::_moviepanel::do_delete_frame(uint64_t row1, uint64_t row2, bool _wholeframe = wholeframe; frame_controls* _fcontrols = &fcontrols; if(_row1 > _row2) std::swap(_row1, _row2); - runemufn([_row1, _row2, _wholeframe, _fcontrols]() { + lsnes_instance.run([_row1, _row2, _wholeframe, _fcontrols]() { controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; uint64_t vsize = fv.size(); if(_row1 >= vsize) @@ -1333,7 +1333,7 @@ void wxeditor_movie::_moviepanel::do_truncate(uint64_t row) recursing = true; uint64_t _row = row; frame_controls* _fcontrols = &fcontrols; - runemufn([_row, _fcontrols]() { + lsnes_instance.run([_row, _fcontrols]() { controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; uint64_t vsize = fv.size(); if(_row >= vsize) @@ -1355,7 +1355,7 @@ void wxeditor_movie::_moviepanel::do_set_stop_at_frame() { uint64_t curframe; uint64_t frame; - runemufn([&curframe]() { + lsnes_instance.run([&curframe]() { curframe = lsnes_instance.mlogic.get_movie().get_current_frame(); }); try { @@ -1372,7 +1372,7 @@ void wxeditor_movie::_moviepanel::do_set_stop_at_frame() wxMessageBox(wxT("The movie is already past that point"), _T("Error"), wxICON_EXCLAMATION | wxOK, m); return; } - runemufn([frame]() { + lsnes_instance.run([frame]() { set_stop_at_frame(frame); }); } @@ -1438,7 +1438,7 @@ void wxeditor_movie::_moviepanel::popup_axis_panel(uint64_t row, control_info ci frame_controls* _fcontrols = &fcontrols; if(ciX.index == ciY.index) { auto c = prompt_coodinates_window(m, NULL, 256, 0, ciX, ciX, screenX, screenY); - runemufn([ciX, row, c, _fcontrols]() { + lsnes_instance.run([ciX, row, c, _fcontrols]() { uint64_t fedit = real_first_editable(*_fcontrols, ciX.index); if(row < fedit) return; controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; @@ -1473,7 +1473,7 @@ void wxeditor_movie::_moviepanel::popup_axis_panel(uint64_t row, control_info ci sws_freeContext(ctx); auto c = prompt_coodinates_window(m, &buf[0], (ciX.rmax - ciX.rmin + 1), (ciY.rmax - ciY.rmin + 1), ciX, ciY, screenX, screenY); - runemufn([ciX, ciY, row, c, _fcontrols]() { + lsnes_instance.run([ciX, ciY, row, c, _fcontrols]() { uint64_t fedit = real_first_editable(*_fcontrols, ciX.index); fedit = max(fedit, real_first_editable(*_fcontrols, ciY.index)); if(row < fedit) return; @@ -1485,7 +1485,7 @@ void wxeditor_movie::_moviepanel::popup_axis_panel(uint64_t row, control_info ci signal_repaint(); } else { auto c = prompt_coodinates_window(m, NULL, 256, 256, ciX, ciY, screenX, screenY); - runemufn([ciX, ciY, row, c, _fcontrols]() { + lsnes_instance.run([ciX, ciY, row, c, _fcontrols]() { uint64_t fedit = real_first_editable(*_fcontrols, ciX.index); fedit = max(fedit, real_first_editable(*_fcontrols, ciY.index)); if(row < fedit) return; @@ -1653,10 +1653,10 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) try { std::string newname; std::string oldname; - runemufn([&oldname]() { oldname = lsnes_instance.mbranch.get(); }); + lsnes_instance.run([&oldname]() { oldname = lsnes_instance.mbranch.get(); }); newname = pick_text(this, "Enter new branch name", "Enter name for a new branch (to fork " "from " + lsnes_instance.mbranch.name(oldname) + "):", "", false); - runemufn_async([this, oldname, newname] { + lsnes_instance.run_async([this, oldname, newname] { try { lsnes_instance.mbranch._new(newname, oldname); } catch(std::exception& e) { @@ -1683,7 +1683,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) if(mode == MBRANCH_IMPORT_MOVIE) { std::set brlist; bool failed = false; - runemufn([this, filename, &brlist, &failed]() { + lsnes_instance.run([this, filename, &brlist, &failed]() { try { brlist = lsnes_instance.mbranch._movie_branches(filename); } catch(std::exception& e) { @@ -1713,7 +1713,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) } dbranch = pick_text(this, "Enter new branch name", "Enter name for an imported branch:", branch, false); - runemufn_async([this, filename, branch, dbranch, mode]() { + lsnes_instance.run_async([this, filename, branch, dbranch, mode]() { try { lsnes_instance.mbranch.import(filename, branch, dbranch, mode); } catch(std::exception& e) { @@ -1735,7 +1735,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) exp_imp_type()); file = g.first; mode = g.second; - runemufn_async([this, file, mode]() { + lsnes_instance.run_async([this, file, mode]() { try { std::string bname = lsnes_instance.mbranch.get(); lsnes_instance.mbranch._export(file, bname, mode == MBRANCH_IMPORT_BINARY); @@ -1755,13 +1755,13 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) std::string newname; std::string oldname; std::set list; - runemufn([&list]() { list = lsnes_instance.mbranch.enumerate(); }); + lsnes_instance.run([&list]() { list = lsnes_instance.mbranch.enumerate(); }); std::vector choices(list.begin(), list.end()); oldname = pick_among(this, "Select branch to rename", "Select branch to rename", choices, 0); newname = pick_text(this, "Enter new branch name", "Enter name for a new branch (to rename " "'" + lsnes_instance.mbranch.name(oldname) + "'):", oldname, false); - runemufn_async([this, oldname, newname] { + lsnes_instance.run_async([this, oldname, newname] { try { lsnes_instance.mbranch.rename(oldname, newname); } catch(std::exception& e) { @@ -1779,11 +1779,11 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) try { std::string oldname; std::set list; - runemufn([&list]() { list = lsnes_instance.mbranch.enumerate(); }); + lsnes_instance.run([&list]() { list = lsnes_instance.mbranch.enumerate(); }); std::vector choices(list.begin(), list.end()); oldname = pick_among(this, "Select branch to delete", "Select branch to delete", choices, 0); - runemufn_async([this, oldname] { + lsnes_instance.run_async([this, oldname] { try { lsnes_instance.mbranch._delete(oldname); } catch(std::exception& e) { @@ -1801,7 +1801,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) if(id >= wxID_MBRANCH_FIRST && id <= wxID_MBRANCH_LAST) { if(!branch_names.count(id)) return; std::string name = branch_names[id]; - runemufn_async([this, name]() { + lsnes_instance.run_async([this, name]() { try { lsnes_instance.mbranch.set(name); } catch(std::exception& e) { @@ -2009,7 +2009,7 @@ void wxeditor_movie::_moviepanel::on_mouse2(unsigned x, unsigned y, bool polarit std::set list; std::string current; bool ro; - runemufn([&list, ¤t, &ro]() { + lsnes_instance.run([&list, ¤t, &ro]() { list = lsnes_instance.mbranch.enumerate(); current = lsnes_instance.mbranch.get(); ro = lsnes_instance.mlogic.get_movie().readonly_mode(); @@ -2052,7 +2052,7 @@ void wxeditor_movie::_moviepanel::signal_repaint() uint32_t prev_width, prev_height; bool done_again = false; do_again: - runemufn([&lines, &width, &height, m2, this]() { + lsnes_instance.run([&lines, &width, &height, m2, this]() { lines = this->get_lines(); if(lines < lines_to_display) this->moviepos = 0; @@ -2142,7 +2142,7 @@ void wxeditor_movie::_moviepanel::do_copy(uint64_t row1, uint64_t row2, unsigned if(line2 < line) std::swap(line, line2); std::string copied; - runemufn([port, controller, line, line2, _fcontrols, &copied]() { + lsnes_instance.run([port, controller, line, line2, _fcontrols, &copied]() { controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; uint64_t vsize = fv.size(); if(!vsize) @@ -2161,7 +2161,7 @@ void wxeditor_movie::_moviepanel::do_copy(uint64_t row1, uint64_t row2) if(line2 < line) std::swap(line, line2); std::string copied; - runemufn([line, line2, &copied]() { + lsnes_instance.run([line, line2, &copied]() { controller_frame_vector& fv = *lsnes_instance.mlogic.get_mfile().input; uint64_t vsize = fv.size(); if(!vsize) @@ -2191,7 +2191,7 @@ void wxeditor_movie::_moviepanel::do_paste(uint64_t row, bool append) recursing = true; uint64_t _gapstart = row; std::string cliptext = copy_from_clipboard(); - runemufn([_fcontrols, &cliptext, _gapstart, append]() { + lsnes_instance.run([_fcontrols, &cliptext, _gapstart, append]() { //Insert enough lines for the pasted content. uint64_t gapstart = _gapstart; if(!lsnes_instance.mlogic.get_movie().readonly_mode()) @@ -2247,7 +2247,7 @@ void wxeditor_movie::_moviepanel::do_paste(uint64_t row, unsigned port, unsigned recursing = true; uint64_t _gapstart = row; std::string cliptext = copy_from_clipboard(); - runemufn([_fcontrols, iset, &cliptext, _gapstart, port, controller, append]() { + lsnes_instance.run([_fcontrols, iset, &cliptext, _gapstart, port, controller, append]() { //Insert enough lines for the pasted content. uint64_t gapstart = _gapstart; if(!lsnes_instance.mlogic.get_movie().readonly_mode()) @@ -2302,7 +2302,7 @@ void wxeditor_movie::_moviepanel::do_insert_controller(uint64_t row, unsigned po auto iset = controller_index_set(fcontrols, port, controller); recursing = true; uint64_t gapstart = row; - runemufn([_fcontrols, iset, gapstart, port, controller]() { + lsnes_instance.run([_fcontrols, iset, gapstart, port, controller]() { //Insert enough lines for the pasted content. if(!lsnes_instance.mlogic.get_movie().readonly_mode()) return; @@ -2331,7 +2331,7 @@ void wxeditor_movie::_moviepanel::do_delete_controller(uint64_t row1, uint64_t r if(row1 > row2) std::swap(row1, row2); uint64_t gapstart = row1; uint64_t gaplen = row2 - row1 + 1; - runemufn([_fcontrols, iset, gapstart, gaplen, port, controller]() { + lsnes_instance.run([_fcontrols, iset, gapstart, gaplen, port, controller]() { //Insert enough lines for the pasted content. if(!lsnes_instance.mlogic.get_movie().readonly_mode()) return; diff --git a/src/platform/wxwidgets/editor-multitrack.cpp b/src/platform/wxwidgets/editor-multitrack.cpp index 527acc40..db5902f8 100644 --- a/src/platform/wxwidgets/editor-multitrack.cpp +++ b/src/platform/wxwidgets/editor-multitrack.cpp @@ -95,7 +95,7 @@ wxeditor_multitrack::wxeditor_multitrack(wxWindow* parent) bool wasc = closing; closing = true; multitrack_open = NULL; - runemufn([]() { lsnes_instance.mteditor.enable(false); }); + lsnes_instance.run([]() { lsnes_instance.mteditor.enable(false); }); if(!wasc) Destroy(); } @@ -136,7 +136,7 @@ void wxeditor_multitrack::on_control(wxCommandEvent& e) return; controller_info& ci = controllers[ctrl]; std::string mode = tostdstring(ci.mode->GetStringSelection()); - runemufn([ci, mode]() { + lsnes_instance.run([ci, mode]() { if(mode == MTMODE_PRESERVE) lsnes_instance.mteditor.set(ci.port, ci.controller, multitrack_edit::MT_PRESERVE); else if(mode == MTMODE_OVERWRITE) @@ -160,7 +160,7 @@ void wxeditor_multitrack::update_controls() } controllers.clear(); std::vector info; - runemufn([this, &info](){ + lsnes_instance.run([this, &info](){ std::map next_in_class; controller_frame model = controls.get_blank(); const port_type_set& pts = model.porttypes(); @@ -231,7 +231,7 @@ void wxeditor_multitrack::on_wclose(wxCloseEvent& e) bool wasc = closing; closing = true; multitrack_open = NULL; - runemufn([]() { lsnes_instance.mteditor.enable(false); }); + lsnes_instance.run([]() { lsnes_instance.mteditor.enable(false); }); if(!wasc) Destroy(); } @@ -249,5 +249,5 @@ void wxeditor_multitrack_display(wxWindow* parent) } v->Show(); multitrack_open = v; - runemufn([]() { lsnes_instance.mteditor.enable(true); }); + lsnes_instance.run([]() { lsnes_instance.mteditor.enable(true); }); } diff --git a/src/platform/wxwidgets/editor-subtitles.cpp b/src/platform/wxwidgets/editor-subtitles.cpp index 159eda5e..2a69bbf0 100644 --- a/src/platform/wxwidgets/editor-subtitles.cpp +++ b/src/platform/wxwidgets/editor-subtitles.cpp @@ -221,7 +221,7 @@ void wxeditor_subtitles::refresh() if(closing) return; std::map, std::string> _subtitles; - runemufn([&_subtitles]() -> void { + lsnes_instance.run([&_subtitles]() -> void { auto keys = lsnes_instance.subtitles.get_all(); for(auto i : keys) _subtitles[i] = lsnes_instance.subtitles.get(i.first, i.second); diff --git a/src/platform/wxwidgets/editor-tasinput.cpp b/src/platform/wxwidgets/editor-tasinput.cpp index 7570ff5a..a0dbb168 100644 --- a/src/platform/wxwidgets/editor-tasinput.cpp +++ b/src/platform/wxwidgets/editor-tasinput.cpp @@ -380,7 +380,7 @@ void wxeditor_tasinput::on_control(wxCommandEvent& e) xstate = t.panel->get_x(); ystate = t.panel->get_y(); } - runemufn_async([t, xstate, ystate]() { + lsnes_instance.run_async([t, xstate, ystate]() { controls.tasinput(t.port, t.controller, t.xindex, xstate); if(t.yindex != std::numeric_limits::max()) controls.tasinput(t.port, t.controller, t.yindex, ystate); @@ -404,7 +404,7 @@ void wxeditor_tasinput::update_controls() std::vector _inputs; std::vector _controller_labels; - runemufn([&_inputs, &_controller_labels](){ + lsnes_instance.run([&_inputs, &_controller_labels](){ std::map next_in_class; controller_frame model = controls.get_blank(); const port_type_set& pts = model.porttypes(); @@ -582,7 +582,7 @@ void wxeditor_tasinput::on_keyboard_down(wxKeyEvent& e) } return; } - if(key == WXK_F5) runemufn_async([this]() { lsnes_instance.command.invoke("+advance-frame"); }); + if(key == WXK_F5) lsnes_instance.run_async([this]() { lsnes_instance.command.invoke("+advance-frame"); }); } void wxeditor_tasinput::on_keyboard_up(wxKeyEvent& e) @@ -696,11 +696,11 @@ void wxeditor_tasinput::on_keyboard_up(wxKeyEvent& e) return; } } - if(key == WXK_F1) runemufn_async([this]() { lsnes_instance.command.invoke("cycle-jukebox-backward"); }); - if(key == WXK_F2) runemufn_async([this]() { lsnes_instance.command.invoke("cycle-jukebox-forward"); }); - if(key == WXK_F3) runemufn_async([this]() { lsnes_instance.command.invoke("save-jukebox"); }); - if(key == WXK_F4) runemufn_async([this]() { lsnes_instance.command.invoke("load-jukebox"); }); - if(key == WXK_F5) runemufn_async([this]() { lsnes_instance.command.invoke("-advance-frame"); }); + if(key == WXK_F1) lsnes_instance.queue("cycle-jukebox-backward"); + if(key == WXK_F2) lsnes_instance.queue("cycle-jukebox-forward"); + if(key == WXK_F3) lsnes_instance.queue("save-jukebox"); + if(key == WXK_F4) lsnes_instance.queue("load-jukebox"); + if(key == WXK_F5) lsnes_instance.queue("-advance-frame"); } wxeditor_tasinput::control_triple* wxeditor_tasinput::find_triple(unsigned controller, unsigned control) diff --git a/src/platform/wxwidgets/keyboard.cpp b/src/platform/wxwidgets/keyboard.cpp index df46a412..db1f19eb 100644 --- a/src/platform/wxwidgets/keyboard.cpp +++ b/src/platform/wxwidgets/keyboard.cpp @@ -265,25 +265,13 @@ namespace std::map keys_allocated; std::set keys_held; - struct keypress_request - { - keyboard::modifier_set mods; - keyboard::key_key* key; - bool polarity; - }; - //Request keypress event to happen. void do_keypress(keyboard::modifier_set mods, keyboard::key_key& key, bool polarity) { - struct keypress_request* req = new keypress_request; - req->mods = mods; - req->key = &key; - req->polarity = polarity; - platform::queue([](void* args) -> void { - struct keypress_request* x = reinterpret_cast(args); - x->key->set_state(x->mods, x->polarity ? 1 : 0); - delete x; - }, req, false); + auto _key = &key; + lsnes_instance.run_async([mods, _key, polarity]() { + _key->set_state(mods, polarity ? 1 : 0); + }); } } diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index d25eb3ca..fbdaa848 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -241,7 +241,7 @@ namespace show_message_ok(w, "Error downloading movie", old->errormsg, wxICON_EXCLAMATION); } else { - platform::queue("load-movie $MEMORY:wxwidgets_download_tmp"); + lsnes_instance.queue("load-movie $MEMORY:wxwidgets_download_tmp"); } delete old; Stop(); @@ -392,7 +392,7 @@ namespace return; try { auto p = prompt_action_params(pwin, act->get_title(), act->params); - runemufn([act_id,p]() { our_rom.rtype->execute_action(act_id, p); }); + lsnes_instance.run([act_id,p]() { our_rom.rtype->execute_action(act_id, p); }); } catch(canceled_exception& e) { } catch(std::bad_alloc& e) { OOM_panic(); @@ -559,7 +559,7 @@ namespace req.region = file.region; for(unsigned i = 0; i < file.files.size() && i < ROM_SLOT_COUNT; i++) req.files[i] = file.files[i]; - runemufn_async([req]() { + lsnes_instance.run_async([req]() { lsnes_instance.command.invoke("unpause-emulator"); load_new_rom(req); }); @@ -567,12 +567,12 @@ namespace void recent_movie_selected(const recentfiles::path& file) { - platform::queue("load-smart " + file.get_path()); + lsnes_instance.queue("load-smart " + file.get_path()); } void recent_script_selected(const recentfiles::path& file) { - platform::queue("run-lua " + file.get_path()); + lsnes_instance.queue("run-lua " + file.get_path()); } wxString getname() @@ -646,30 +646,30 @@ namespace { auto sfactors = calc_scale_factors(video_scale_factor, arcorrect_enabled, (our_rom.rtype) ? our_rom.rtype->get_PAR() : 1.0); - platform::queue(keypress(keyboard::modifier_set(), mouse_x, e.GetX() / sfactors.first)); - platform::queue(keypress(keyboard::modifier_set(), mouse_y, e.GetY() / sfactors.second)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_x, e.GetX() / sfactors.first)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_y, e.GetY() / sfactors.second)); if(e.Entering()) - platform::queue(keypress(keyboard::modifier_set(), mouse_i, 1)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_i, 1)); if(e.Leaving()) - platform::queue(keypress(keyboard::modifier_set(), mouse_i, 0)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_i, 0)); if(e.LeftDown()) - platform::queue(keypress(keyboard::modifier_set(), mouse_l, 1)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_l, 1)); if(e.LeftUp()) - platform::queue(keypress(keyboard::modifier_set(), mouse_l, 0)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_l, 0)); if(e.MiddleDown()) - platform::queue(keypress(keyboard::modifier_set(), mouse_m, 1)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_m, 1)); if(e.MiddleUp()) - platform::queue(keypress(keyboard::modifier_set(), mouse_m, 0)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_m, 0)); if(e.RightDown()) - platform::queue(keypress(keyboard::modifier_set(), mouse_r, 1)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_r, 1)); if(e.RightUp()) - platform::queue(keypress(keyboard::modifier_set(), mouse_r, 0)); + lsnes_instance.queue(keypress_info(keyboard::modifier_set(), mouse_r, 0)); } bool is_readonly_mode() { bool ret; - runemufn([&ret]() { + lsnes_instance.run([&ret]() { ret = lsnes_instance.mlogic ? lsnes_instance.mlogic.get_movie().readonly_mode() : false; }); return ret; @@ -678,7 +678,7 @@ namespace std::pair UI_controller_index_by_logical(unsigned lid) { std::pair ret; - runemufn([&ret, lid]() { ret = controls.lcid_to_pcid(lid); }); + lsnes_instance.run([&ret, lid]() { ret = controls.lcid_to_pcid(lid); }); return ret; } @@ -754,7 +754,7 @@ namespace if(amov == bmov) return false; if(amov) std::swap(a, b); - runemufn_async([a, b]() { + lsnes_instance.run_async([a, b]() { lsnes_instance.command.invoke("unpause-emulator"); romload_request req; req.packfile = a; @@ -767,13 +767,13 @@ namespace std::string a = tostdstring(filenames[0]); bool amov = is_lsnes_movie(a); if(amov) { - platform::queue("load-smart " + a); + lsnes_instance.queue("load-smart " + a); pwin->recent_movies->add(a); ret = true; } else { romload_request req; req.packfile = a; - runemufn_async([req]() { + lsnes_instance.run_async([req]() { lsnes_instance.command.invoke("unpause-emulator"); load_new_rom(req); }); @@ -1239,7 +1239,7 @@ void wxwin_mainwindow::on_close(wxCloseEvent& e) { //Veto it for now, latter things will delete it. e.Veto(); - platform::queue("quit-emulator"); + lsnes_instance.queue("quit-emulator"); } void wxwin_mainwindow::notify_update() throw() @@ -1442,7 +1442,7 @@ void wxwin_mainwindow::project_selected(const std::string& id) { std::string filename, displayname; bool load_ok = false; - runemufn([id, &filename, &displayname, &load_ok]() -> void { + lsnes_instance.run([id, &filename, &displayname, &load_ok]() -> void { try { auto& p = project_load(id); //Check. filename = p.filename; @@ -1470,79 +1470,79 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) bool s; switch(e.GetId()) { case wxID_FRAMEADVANCE: - platform::queue("+advance-frame"); - platform::queue("-advance-frame"); + lsnes_instance.queue("+advance-frame"); + lsnes_instance.queue("-advance-frame"); return; case wxID_SUBFRAMEADVANCE: - platform::queue("+advance-poll"); - platform::queue("-advance-poll"); + lsnes_instance.queue("+advance-poll"); + lsnes_instance.queue("-advance-poll"); return; case wxID_NEXTPOLL: - platform::queue("advance-skiplag"); + lsnes_instance.queue("advance-skiplag"); return; case wxID_PAUSE: - platform::queue("pause-emulator"); + lsnes_instance.queue("pause-emulator"); return; case wxID_EXIT: - platform::queue("quit-emulator"); + lsnes_instance.queue("quit-emulator"); return; case wxID_AUDIO_ENABLED: platform::sound_enable(menu_ischecked(wxID_AUDIO_ENABLED)); return; case wxID_CANCEL_SAVES: - platform::queue("cancel-saves"); + lsnes_instance.queue("cancel-saves"); return; case wxID_LOAD_MOVIE: filename = choose_file_load(this, "Load Movie", project_moviepath(), filetype_movie).second; recent_movies->add(filename); - platform::queue("load-movie " + filename); + lsnes_instance.queue("load-movie " + filename); return; case wxID_LOAD_STATE: filename2 = choose_file_load(this, "Load State", project_moviepath(), filetype_savestate); recent_movies->add(filename2.second); - platform::queue("load" + filename2.first + " " + filename2.second); + lsnes_instance.queue("load" + filename2.first + " " + filename2.second); return; case wxID_REWIND_MOVIE: - platform::queue("rewind-movie"); + lsnes_instance.queue("rewind-movie"); return; case wxID_SAVE_MOVIE: filename2 = choose_file_save(this, "Save Movie", project_moviepath(), filetype_movie, project_prefixname("lsmv")); recent_movies->add(filename2.second); - platform::queue("save-movie" + filename2.first + " " + filename2.second); + lsnes_instance.queue("save-movie" + filename2.first + " " + filename2.second); return; case wxID_SAVE_SUBTITLES: - platform::queue("save-subtitle " + choose_file_save(this, "Save subtitles", project_moviepath(), + lsnes_instance.queue("save-subtitle " + choose_file_save(this, "Save subtitles", project_moviepath(), filetype_sub, project_prefixname("sub"))); return; case wxID_SAVE_STATE: filename2 = choose_file_save(this, "Save State", project_moviepath(), filetype_savestate); recent_movies->add(filename2.second); - platform::queue("save-state" + filename2.first + " " + filename2.second); + lsnes_instance.queue("save-state" + filename2.first + " " + filename2.second); return; case wxID_SAVE_SCREENSHOT: - platform::queue("take-screenshot " + choose_file_save(this, "Save Screenshot", project_moviepath(), - filetype_png, get_default_screenshot_name())); + lsnes_instance.queue("take-screenshot " + choose_file_save(this, "Save Screenshot", + project_moviepath(), filetype_png, get_default_screenshot_name())); return; case wxID_RUN_SCRIPT: - platform::queue("run-script " + pick_file_member(this, "Select Script", project_otherpath())); + lsnes_instance.queue("run-script " + pick_file_member(this, "Select Script", project_otherpath())); return; case wxID_RUN_LUA: { std::string f = choose_file_load(this, "Select Lua Script", project_otherpath(), filetype_lua_script); - platform::queue("run-lua " + f); + lsnes_instance.queue("run-lua " + f); recent_scripts->add(f); return; } case wxID_RESET_LUA: - platform::queue("reset-lua"); + lsnes_instance.queue("reset-lua"); return; case wxID_EVAL_LUA: - platform::queue("evaluate-lua " + pick_text(this, "Evaluate Lua", "Enter Lua Statement:")); + lsnes_instance.queue("evaluate-lua " + pick_text(this, "Evaluate Lua", "Enter Lua Statement:")); return; case wxID_READONLY_MODE: s = menu_ischecked(wxID_READONLY_MODE); - runemufn([s]() { + lsnes_instance.run([s]() { if(!s) lua_callback_movie_lost("readwrite"); if(lsnes_instance.mlogic) lsnes_instance.mlogic.get_movie().readonly_mode(s); @@ -1574,13 +1574,13 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_SAVE_MEMORYWATCH: { modal_pause_holder hld; std::set old_watches; - runemufn([&old_watches]() { old_watches = lsnes_instance.mwatch.enumerate(); }); + lsnes_instance.run([&old_watches]() { old_watches = lsnes_instance.mwatch.enumerate(); }); std::string filename = choose_file_save(this, "Save watches to file", project_otherpath(), filetype_watch); std::ofstream out(filename.c_str()); for(auto i : old_watches) { std::string val; - runemufn([i, &val]() { + lsnes_instance.run([i, &val]() { try { val = lsnes_instance.mwatch.get_string(i); } catch(std::exception& e) { @@ -1596,7 +1596,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_LOAD_MEMORYWATCH: { modal_pause_holder hld; std::set old_watches; - runemufn([&old_watches]() { old_watches = lsnes_instance.mwatch.enumerate(); }); + lsnes_instance.run([&old_watches]() { old_watches = lsnes_instance.mwatch.enumerate(); }); std::map new_watches; std::string filename = choose_file_load(this, "Choose memory watch file", project_otherpath(), filetype_watch); @@ -1616,7 +1616,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) return; } - runemufn([&new_watches, &old_watches]() { + lsnes_instance.run([&new_watches, &old_watches]() { handle_watch_load(new_watches, old_watches); }); return; @@ -1740,7 +1740,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) wxeditor_plugin_manager_display(this); return; case wxID_RELOAD_ROM_IMAGE: - runemufn([]() { + lsnes_instance.run([]() { lsnes_instance.command.invoke("unpause-emulator"); reload_current_rom(); }); @@ -1767,10 +1767,10 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) open_new_project_window(this); return; case wxID_CLOSE_PROJECT: - runemufn([]() -> void { project_set(NULL); }); + lsnes_instance.run([]() -> void { project_set(NULL); }); return; case wxID_CLOSE_ROM: - runemufn([]() -> void { close_rom(); }); + lsnes_instance.run([]() -> void { close_rom(); }); return; case wxID_ENTER_FULLSCREEN: wx_escape_count = 0; diff --git a/src/platform/wxwidgets/memorysearch.cpp b/src/platform/wxwidgets/memorysearch.cpp index 8ae30e84..09b608f8 100644 --- a/src/platform/wxwidgets/memorysearch.cpp +++ b/src/platform/wxwidgets/memorysearch.cpp @@ -739,7 +739,7 @@ void wxwindow_memorysearch::panel::prepare_paint() uint64_t addr_count; bool toomany = false; auto _parent = parent; - runemufn([&toomany, &first, &last, ms, &lines, &addrs, &addr_count, _parent]() { + lsnes_instance.run([&toomany, &first, &last, ms, &lines, &addrs, &addr_count, _parent]() { addr_count = ms->get_candidate_count(); if(last > addr_count) { uint64_t delta = last - addr_count; @@ -821,7 +821,7 @@ void wxwindow_memorysearch::dump_candidates_text() filetype_textfile); std::ofstream out(filename); auto ms = msearch; - runemufn([ms, this, &out]() { + lsnes_instance.run([ms, this, &out]() { std::list addrs2 = ms->get_candidates(); for(auto i : addrs2) { std::string row = format_address(i) + " "; @@ -1058,7 +1058,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e) endianess = j->endian; } e.endianess = endianess; - runemufn([n, &e]() { lsnes_instance.mwatch.set(n, e); }); + lsnes_instance.run([n, &e]() { lsnes_instance.mwatch.set(n, e); }); } catch(canceled_exception& e) { } } @@ -1076,7 +1076,7 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e) return; uint64_t addr = addresses[r]; auto ms = msearch; - runemufn([addr, ms]() { ms->dq_range(addr, addr); }); + lsnes_instance.run([addr, ms]() { ms->dq_range(addr, addr); }); } matches->set_selection(0, 0); wxeditor_hexeditor_update(); diff --git a/src/platform/wxwidgets/messages.cpp b/src/platform/wxwidgets/messages.cpp index 3ef16a40..3c868454 100644 --- a/src/platform/wxwidgets/messages.cpp +++ b/src/platform/wxwidgets/messages.cpp @@ -287,7 +287,7 @@ void wxwin_messages::on_execute(wxCommandEvent& e) //Delete old commands to prevent box becoming unmageable. if(command->GetCount() > COMMAND_HISTORY_SIZE) command->Delete(command->GetCount() - 1); - platform::queue(cmd); + lsnes_instance.queue(cmd); } void wxwin_messages::notify_update() throw() diff --git a/src/platform/wxwidgets/requestrom.cpp b/src/platform/wxwidgets/requestrom.cpp index dcffb44b..cd4b77b2 100644 --- a/src/platform/wxwidgets/requestrom.cpp +++ b/src/platform/wxwidgets/requestrom.cpp @@ -146,7 +146,7 @@ namespace mr.singlefile = req.singlefile = filename; } parent->recent_roms->add(mr); - runemufn_async([req]() { + lsnes_instance.run_async([req]() { lsnes_instance.command.invoke("unpause-emulator"); load_new_rom(req); }); @@ -388,7 +388,7 @@ namespace req.files[i] = files[i]; } parent->recent_roms->add(mr); - runemufn([req]() { + lsnes_instance.run([req]() { lsnes_instance.command.invoke("unpause-emulator"); load_new_rom(req); }); diff --git a/src/platform/wxwidgets/romselect.cpp b/src/platform/wxwidgets/romselect.cpp index dea25d1b..53e75cc3 100644 --- a/src/platform/wxwidgets/romselect.cpp +++ b/src/platform/wxwidgets/romselect.cpp @@ -631,7 +631,7 @@ void wxwin_project::on_load(wxCommandEvent& e) mov.start_paused = false; rrdata_set tmp_rdata; mov.save("$MEMORY:wxwidgets-romload-tmp", 0, true, tmp_rdata); - platform::queue("load-state $MEMORY:wxwidgets-romload-tmp"); + lsnes_instance.queue("load-state $MEMORY:wxwidgets-romload-tmp"); EndModal(0); } catch(std::exception& e) { show_message_ok(this, "Error loading movie", e.what(), wxICON_EXCLAMATION); diff --git a/src/platform/wxwidgets/settings-advanced.cpp b/src/platform/wxwidgets/settings-advanced.cpp index 05331c56..900791c6 100644 --- a/src/platform/wxwidgets/settings-advanced.cpp +++ b/src/platform/wxwidgets/settings-advanced.cpp @@ -286,7 +286,7 @@ namespace } bool error = false; std::string errorstr; - runemufn([&error, &errorstr, name, value]() { + lsnes_instance.run([&error, &errorstr, name, value]() { try { lsnes_instance.setcache.set(name, value); } catch(std::exception& e) { diff --git a/src/platform/wxwidgets/tracelogger.cpp b/src/platform/wxwidgets/tracelogger.cpp index d2ee3cf2..45023a23 100644 --- a/src/platform/wxwidgets/tracelogger.cpp +++ b/src/platform/wxwidgets/tracelogger.cpp @@ -158,7 +158,7 @@ namespace { std::map> regions; std::set disasms; - runemufn([®ions, &disasms]() { + lsnes_instance.run([®ions, &disasms]() { for(auto i : lsnes_instance.memory.get_regions()) regions[i->name] = std::make_pair(i->base, i->size); disasms = disassembler::list(); @@ -320,7 +320,7 @@ namespace std::string _vma = tostdstring(vma->GetStringSelection()); if(_endian <= 0 || _endian > 3) { _endian = 1; - runemufn([&_endian, _vma]() { + lsnes_instance.run([&_endian, _vma]() { for(auto i : lsnes_instance.memory.get_regions()) { if(i->name == _vma) { _endian = i->endian + 2; @@ -350,7 +350,7 @@ namespace uint64_t base = 0; if(vma->GetSelection() && vma->GetSelection() != wxNOT_FOUND) { std::string _vma = tostdstring(vma->GetStringSelection()); - runemufn([&base, _vma]() { + lsnes_instance.run([&base, _vma]() { for(auto i : lsnes_instance.memory.get_regions()) { if(i->name == _vma) { base = i->base; @@ -578,7 +578,7 @@ namespace return; } if(trace_active) - runemufn([this]() { kill_debug_hooks(); }); + lsnes_instance.run([this]() { kill_debug_hooks(); }); trace_active = false; if(!closing) Destroy(); @@ -714,7 +714,7 @@ namespace void wxwin_tracelog::on_enabled(wxCommandEvent& e) { bool enable = enabled->GetValue(); - runemufn([this, enable]() { + lsnes_instance.run([this, enable]() { if(enable) { threads::alock h(buffer_mutex); broken = broken2; @@ -848,7 +848,7 @@ namespace return; } if(trace_active) { - runemufn([this]() { this->kill_debug_hooks(); }); + lsnes_instance.run([this]() { this->kill_debug_hooks(); }); } trace_active = false; Destroy(); @@ -923,17 +923,17 @@ namespace } scroll_pane(find_line); } else if(e.GetId() == wxID_SINGLESTEP) { - runemufn_async([this]() { + lsnes_instance.run_async([this]() { this->singlestepping = true; lsnes_instance.command.invoke("unpause-emulator"); }); } else if(e.GetId() == wxID_FRAMEADVANCE) { - runemufn_async([this]() { + lsnes_instance.run_async([this]() { lsnes_instance.command.invoke("+advance-frame"); lsnes_instance.command.invoke("-advance-frame"); }); } else if(e.GetId() == wxID_CONTINUE) { - runemufn_async([this]() { lsnes_instance.command.invoke("unpause-emulator"); }); + lsnes_instance.run_async([this]() { lsnes_instance.command.invoke("unpause-emulator"); }); } else if(e.GetId() == wxID_BREAKPOINTS) { dialog_breakpoints* d = new dialog_breakpoints(this); d->ShowModal(); @@ -1037,7 +1037,7 @@ back: std::set> wxwin_tracelog::get_breakpoints() { std::set> ret; - runemufn([this, &ret]() { + lsnes_instance.run([this, &ret]() { for(auto i : rwx_breakpoints) ret.insert(i.first); }); @@ -1306,13 +1306,13 @@ back: uint64_t addr = d->get_address(); uint64_t count = d->get_count(); d->Destroy(); - runemufn_async([this, disasm, addr, count]() { + lsnes_instance.run_async([this, disasm, addr, count]() { this->run_disassembler(disasm, addr, count); }); } else if(e.GetId() == wxID_GOTO) { try { std::string to = pick_text(this, "Goto", "Enter address to go to:", ""); - runemufn_async([this, to]() { + lsnes_instance.run_async([this, to]() { uint64_t addr; uint64_t base = 0; std::string vma; @@ -1416,7 +1416,7 @@ back: uint64_t count = d->get_count(); d->Destroy(); auto pp = p; - runemufn_async([pp, disasm, addr, count]() { + lsnes_instance.run_async([pp, disasm, addr, count]() { pp->run_disassembler(disasm, addr, count); }); //Delete entries in (rbase, addr) if addr = base. @@ -1804,7 +1804,7 @@ back: } rpair(addr, dtype) = d->get_result(); d->Destroy(); - runemufn_async([this, addr, dtype]() { pwin->add_breakpoint(addr, dtype); }); + lsnes_instance.run_async([this, addr, dtype]() { pwin->add_breakpoint(addr, dtype); }); auto ent = std::make_pair(addr, dtype); std::string line = format_line(ent); unsigned insert_pos = get_insert_pos(ent); @@ -1821,7 +1821,7 @@ back: debug_type dtype; addr = listsyms[idx].first; dtype = listsyms[idx].second; - runemufn_async([this, addr, dtype]() { pwin->remove_breakpoint(addr, dtype); }); + lsnes_instance.run_async([this, addr, dtype]() { pwin->remove_breakpoint(addr, dtype); }); brklist->Delete(idx); listsyms.erase(listsyms.begin() + idx); }