From 964d982b31d196f3955baed8a4914833d4d841df Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 6 Nov 2019 22:48:47 +0100 Subject: [PATCH] Fix xController macro --- xSDL/xController.cpp | 6 +++--- xSDL/xController.h | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xSDL/xController.cpp b/xSDL/xController.cpp index c17f032..1f83cd0 100644 --- a/xSDL/xController.cpp +++ b/xSDL/xController.cpp @@ -12,7 +12,7 @@ xController::~xController(){ void xController::handleEvent(SDL_Event* event){ _mutex.lock(); - map::iterator found = _handlers.find( (SDL_EventType) event->type ); + map::iterator found = _handlers.find( (SDL_EventType) event->type ); // ignore no handler found if( found == _handlers.end() ){ @@ -26,14 +26,14 @@ void xController::handleEvent(SDL_Event* event){ } // bind a new handler -void xController::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ){ +void xController::attachEvent(SDL_EventType t, EventHandlerArg){ _mutex.lock(); _handlers[ t ] = handler; _mutex.unlock(); } // removes an existing handler -void xController::detachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ){ +void xController::detachEvent(SDL_EventType t){ _mutex.lock(); _handlers.erase(t); _mutex.unlock(); diff --git a/xSDL/xController.h b/xSDL/xController.h index 3a3d8f9..56d8fbd 100644 --- a/xSDL/xController.h +++ b/xSDL/xController.h @@ -6,7 +6,8 @@ #include using namespace std; - #define EventListener void(*)(SDL_Event*) + #define EventHandlerArg void(* handler)(SDL_Event*) + #define EventHandler void(*)(SDL_Event*) class xController{ @@ -18,12 +19,12 @@ void handleEvent(SDL_Event* event); // manage handlers - void attachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ); - void detachEvent(SDL_EventType t, void(*handler)(SDL_Event*) ); + void attachEvent(SDL_EventType t, EventHandlerArg); + void detachEvent(SDL_EventType t); private: // event handlers - map _handlers; + map _handlers; // thread safety mutex _mutex;