lab.cpp/SDL#4/xSDL/xManager.h

75 lines
1.5 KiB
C++

#ifndef DEF_XMANAGER_H
#define DEF_XMANAGER_H
class xManager{
public:
xManager(const char *t, int w, int h);
~xManager();
SDL_Window *window();
SDL_Renderer *renderer();
bool status();
bool setBackground(Uint8 r=0xff, Uint8 g=0xff, Uint8 b=0xff, Uint8 a=0xff);
bool setImage(const char *url);
bool collide(SDL_Rect a, SDL_Rect b); // Collision entre 2 SDL_Rect
bool hit(xSprite *current, int movex=0, int movey=0); // Gestion des collisions
bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
xSprite* get(string index); // retourne une sprite
void push(string index, xSprite* sprite);
void pull(string index);
void pull(xSprite *sprite);
void update();
void manageFps(const int fps=0);
// Gestion des evenements
void attachEvent(SDL_EventType t, void(*handler)(SDL_Event*) );
void manageEvents(SDL_Event* event);
// DEBUG
void debug();
private:
// gestion FPS
Uint32 _lasttick;
Uint32 _fpstime;
// Gestion evenements
vector<SDL_EventType> _events;
vector<void(*)(SDL_Event*)> _handlers;
// status de l'initialisation
bool _status;
// Elements utiles
SDL_Window *_window;
SDL_Rect _winrect;
SDL_Renderer *_renderer;
SDL_Texture *_texture;
// Gestion des textures
vector<string> _indexes;
vector<xSprite*> _sprites;
// Protection thread-safe
mutex _mutex_push;
mutex _mutex_pull;
mutex _mutex_update;
mutex _mutex_hit;
// DEBUG
SDL_Rect _debug;
};
#endif