xmario/xSDL/xController.h

33 lines
605 B
C
Raw Permalink Normal View History

#ifndef DEF_XCONTROLLER_H
#define DEF_XCONTROLLER_H
#include "SDL.h"
#include <mutex>
#include <map>
using namespace std;
2019-11-06 21:48:47 +00:00
#define EventHandlerArg void(* handler)(SDL_Event*)
#define EventHandler void(*)(SDL_Event*)
class xController{
public:
xController();
~xController();
// called in scheduling
void handleEvent(SDL_Event* event);
// manage handlers
2019-11-06 21:48:47 +00:00
void attachEvent(SDL_EventType t, EventHandlerArg);
void detachEvent(SDL_EventType t);
private:
// event handlers
2019-11-06 21:48:47 +00:00
map<SDL_EventType, EventHandler> _handlers;
// thread safety
mutex _mutex;
};
#endif