diff --git a/Source/Core/InputCommon/Src/EventHandler.cpp b/Source/Core/InputCommon/Src/EventHandler.cpp index 158b7fe6b4..d639de22d2 100644 --- a/Source/Core/InputCommon/Src/EventHandler.cpp +++ b/Source/Core/InputCommon/Src/EventHandler.cpp @@ -4,12 +4,31 @@ #include #endif +EventHandler *EventHandler::m_Instance = 0; + EventHandler::EventHandler() { memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0); memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0); memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0); } +EventHandler::~EventHandler() { +} + +EventHandler::EventHandler *GetInstance() { + if (! EventHandler::m_Instance) + EventHandler::m_Instance = new EventHandler(); + + return EventHandler::m_Instance; +} + +void EventHandler::Destroy() { + if (EventHandler::m_Instance) + delete EventHandler::m_Instance; + + EventHandler::m_Instance = 0; +} + bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) { if (key.inputType == KeyboardInput) { fprintf(stderr, "Registering %d\n", key.keyCode); @@ -270,3 +289,12 @@ void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr) { break; } } + +class EventHandlerCleaner +{ +public: + ~EventHandlerCleaner() + { + EventHandler::Destroy(); + } +} EventHandlerCleanerInst; diff --git a/Source/Core/InputCommon/Src/EventHandler.h b/Source/Core/InputCommon/Src/EventHandler.h index d9b665df99..7596942c2b 100644 --- a/Source/Core/InputCommon/Src/EventHandler.h +++ b/Source/Core/InputCommon/Src/EventHandler.h @@ -35,10 +35,20 @@ private: listenFuncPtr joys[sf::Joy::Count+1]; std::queue eventQueue; public: + static EventHandler *m_Instance; + + // protected: + EventHandler(const EventHandler&); + EventHandler& operator= (const EventHandler&); + EventHandler(); + ~EventHandler(); + bool RegisterEventListener(listenFuncPtr func, Keys key); bool RemoveEventListener(Keys key); void Update(); + static EventHandler *GetInstance(); + static void Destroy(); bool addEvent(sf::Event *e); static bool TestEvent (Keys k, sf::Event e); #if defined HAVE_WX && HAVE_WX diff --git a/Source/Core/InputCommon/Src/InputCommon.cpp b/Source/Core/InputCommon/Src/InputCommon.cpp index 2d2188477d..beed506f8e 100644 --- a/Source/Core/InputCommon/Src/InputCommon.cpp +++ b/Source/Core/InputCommon/Src/InputCommon.cpp @@ -1,16 +1,16 @@ #include "EventHandler.h" -EventHandler *eventHandler = NULL; +//EventHandler *eventHandler = NULL; namespace InputCommon { void Init() { // init the event handler - eventHandler = new EventHandler(); + //EventHandler::GetInstance(); } void Shutdown() { - if (eventHandler) - delete eventHandler; + //if (eventHandler) + // delete eventHandler; } } diff --git a/Source/Core/InputCommon/Src/InputCommon.h b/Source/Core/InputCommon/Src/InputCommon.h index aaf0934510..d29ed674c6 100644 --- a/Source/Core/InputCommon/Src/InputCommon.h +++ b/Source/Core/InputCommon/Src/InputCommon.h @@ -1,6 +1,6 @@ #include "EventHandler.h" -extern EventHandler *eventHandler; +//extern EventHandler *eventHandler; namespace InputCommon { diff --git a/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp b/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp index dc2c7184a2..0a1d4ddf0b 100644 --- a/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp +++ b/Source/Plugins/Plugin_PadSimpleEvnt/Src/PadSimple.cpp @@ -89,7 +89,8 @@ void __Logv(int log, int v, const char *format, ...) {} bool registerKey(int nPad, int id, sf::Key::Code code, int mods) { Keys key, oldKey; - + EventHandler *eventHandler = EventHandler::GetInstance(); + key.inputType = KeyboardInput; key.keyCode = code; key.mods = mods;