Fix xController macro
This commit is contained in:
parent
57025d9ef3
commit
964d982b31
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue