Fix xController macro

This commit is contained in:
Adrien Marquès 2019-11-06 22:48:47 +01:00
parent 57025d9ef3
commit 964d982b31
2 changed files with 8 additions and 7 deletions

View File

@ -12,7 +12,7 @@ xController::~xController(){
void xController::handleEvent(SDL_Event* event){
_mutex.lock();
map<SDL_EventType, EventListener>::iterator found = _handlers.find( (SDL_EventType) event->type );
map<SDL_EventType, EventHandler>::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();

View File

@ -6,7 +6,8 @@
#include <map>
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<SDL_EventType, EventListener> _handlers;
map<SDL_EventType, EventHandler> _handlers;
// thread safety
mutex _mutex;