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:
nakeee 2009-01-05 13:39:54 +00:00
parent 65590711e9
commit a533a9dc3d
5 changed files with 45 additions and 6 deletions

View File

@ -4,12 +4,31 @@
#include <wx/wx.h>
#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;

View File

@ -35,10 +35,20 @@ private:
listenFuncPtr joys[sf::Joy::Count+1];
std::queue<sf::Event> 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

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
#include "EventHandler.h"
extern EventHandler *eventHandler;
//extern EventHandler *eventHandler;
namespace InputCommon
{

View File

@ -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;