mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 15:55:31 +01:00
almost made the event handler into singleton having access problems
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1795 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
65590711e9
commit
a533a9dc3d
@ -4,12 +4,31 @@
|
|||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
EventHandler *EventHandler::m_Instance = 0;
|
||||||
|
|
||||||
EventHandler::EventHandler() {
|
EventHandler::EventHandler() {
|
||||||
memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0);
|
memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0);
|
||||||
memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
|
memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
|
||||||
memset(joys, sizeof(listenFuncPtr) * (sf::Joy::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) {
|
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
|
||||||
if (key.inputType == KeyboardInput) {
|
if (key.inputType == KeyboardInput) {
|
||||||
fprintf(stderr, "Registering %d\n", key.keyCode);
|
fprintf(stderr, "Registering %d\n", key.keyCode);
|
||||||
@ -270,3 +289,12 @@ void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EventHandlerCleaner
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~EventHandlerCleaner()
|
||||||
|
{
|
||||||
|
EventHandler::Destroy();
|
||||||
|
}
|
||||||
|
} EventHandlerCleanerInst;
|
||||||
|
@ -35,10 +35,20 @@ private:
|
|||||||
listenFuncPtr joys[sf::Joy::Count+1];
|
listenFuncPtr joys[sf::Joy::Count+1];
|
||||||
std::queue<sf::Event> eventQueue;
|
std::queue<sf::Event> eventQueue;
|
||||||
public:
|
public:
|
||||||
|
static EventHandler *m_Instance;
|
||||||
|
|
||||||
|
// protected:
|
||||||
|
EventHandler(const EventHandler&);
|
||||||
|
EventHandler& operator= (const EventHandler&);
|
||||||
|
|
||||||
EventHandler();
|
EventHandler();
|
||||||
|
~EventHandler();
|
||||||
|
|
||||||
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
||||||
bool RemoveEventListener(Keys key);
|
bool RemoveEventListener(Keys key);
|
||||||
void Update();
|
void Update();
|
||||||
|
static EventHandler *GetInstance();
|
||||||
|
static void Destroy();
|
||||||
bool addEvent(sf::Event *e);
|
bool addEvent(sf::Event *e);
|
||||||
static bool TestEvent (Keys k, sf::Event e);
|
static bool TestEvent (Keys k, sf::Event e);
|
||||||
#if defined HAVE_WX && HAVE_WX
|
#if defined HAVE_WX && HAVE_WX
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
|
|
||||||
EventHandler *eventHandler = NULL;
|
//EventHandler *eventHandler = NULL;
|
||||||
|
|
||||||
namespace InputCommon
|
namespace InputCommon
|
||||||
{
|
{
|
||||||
void Init() {
|
void Init() {
|
||||||
// init the event handler
|
// init the event handler
|
||||||
eventHandler = new EventHandler();
|
//EventHandler::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
if (eventHandler)
|
//if (eventHandler)
|
||||||
delete eventHandler;
|
// delete eventHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
|
|
||||||
extern EventHandler *eventHandler;
|
//extern EventHandler *eventHandler;
|
||||||
|
|
||||||
namespace InputCommon
|
namespace InputCommon
|
||||||
{
|
{
|
||||||
|
@ -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) {
|
bool registerKey(int nPad, int id, sf::Key::Code code, int mods) {
|
||||||
|
|
||||||
Keys key, oldKey;
|
Keys key, oldKey;
|
||||||
|
EventHandler *eventHandler = EventHandler::GetInstance();
|
||||||
|
|
||||||
key.inputType = KeyboardInput;
|
key.inputType = KeyboardInput;
|
||||||
key.keyCode = code;
|
key.keyCode = code;
|
||||||
key.mods = mods;
|
key.mods = mods;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user