2019-11-05 20:45:41 +00:00
|
|
|
#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*)
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
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);
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// event handlers
|
2019-11-06 21:48:47 +00:00
|
|
|
map<SDL_EventType, EventHandler> _handlers;
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
// thread safety
|
|
|
|
mutex _mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|