Remove direct emulation thread references from keyboard.cpp

This commit is contained in:
Ilari Liusvaara 2014-05-31 22:34:43 +03:00
parent 77abaa2d98
commit c3b1031498
3 changed files with 19 additions and 10 deletions

View file

@ -17,6 +17,8 @@ UI services.
class emulator_instance; class emulator_instance;
class dumper_factory_base; class dumper_factory_base;
namespace keyboard { class modifier_set; }
namespace keyboard { class key_key; }
struct project_author_info struct project_author_info
{ {
@ -108,5 +110,10 @@ void UI_start_dump(emulator_instance& inst, dumper_factory_base& factory, const
* End dumping. * End dumping.
*/ */
void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory); void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory);
/**
* Send a keypress event.
*/
void UI_do_keypress(emulator_instance& inst, const keyboard::modifier_set& mods, keyboard::key_key& key,
bool polarity);
#endif #endif

View file

@ -6,6 +6,7 @@
#include "core/project.hpp" #include "core/project.hpp"
#include "core/queue.hpp" #include "core/queue.hpp"
#include "core/ui-services.hpp" #include "core/ui-services.hpp"
#include "library/keyboard.hpp"
namespace namespace
{ {
@ -201,3 +202,12 @@ void UI_end_dump(emulator_instance& inst, dumper_factory_base& factory)
delete in; delete in;
}); });
} }
void UI_do_keypress(emulator_instance& inst, const keyboard::modifier_set& mods, keyboard::key_key& key,
bool polarity)
{
auto _key = &key;
inst.iqueue->run_async([mods, _key, polarity]() {
_key->set_state(mods, polarity ? 1 : 0);
}, [](std::exception& e) {});
}

View file

@ -3,6 +3,7 @@
#include "core/instance.hpp" #include "core/instance.hpp"
#include "core/queue.hpp" #include "core/queue.hpp"
#include "core/window.hpp" #include "core/window.hpp"
#include "core/ui-services.hpp"
#include <cstdint> #include <cstdint>
#include <map> #include <map>
@ -265,15 +266,6 @@ namespace
std::map<int, keyboard::key_key*> key_map; std::map<int, keyboard::key_key*> key_map;
std::map<std::string, int> keys_allocated; std::map<std::string, int> keys_allocated;
std::set<int> keys_held; std::set<int> keys_held;
//Request keypress event to happen.
void do_keypress(keyboard::modifier_set mods, keyboard::key_key& key, bool polarity)
{
auto _key = &key;
lsnes_instance.iqueue->run_async([mods, _key, polarity]() {
_key->set_state(mods, polarity ? 1 : 0);
}, [](std::exception& e) {});
}
} }
std::string map_keycode_to_key(int kcode) std::string map_keycode_to_key(int kcode)
@ -323,7 +315,7 @@ void handle_wx_keyboard(wxKeyEvent& e, bool polarity)
k++; k++;
} }
if(grp) if(grp)
do_keypress(mset, *grp, polarity); UI_do_keypress(lsnes_instance, mset, *grp, polarity);
e.Skip(); e.Skip();
} }