#ifndef DEF_XENGINE_H #define DEF_XENGINE_H #include "SDL.h" #include "SDL_image.h" #include #include #include #include #include #include #include "xDrawable.h" #include "xController.h" #include "xOrchestrable.h" using namespace std; enum xAppState { RUNNING, STOPPING, STOPPED }; class xApplication{ public: /** Singleton */ static xApplication* create(const char *t, int w, int h); static xApplication* get(); ~xApplication(); SDL_Window *window(); SDL_Renderer *renderer(); void 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, vector& cols); // 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 /** scene */ void push(xDrawable* sprite); void pull(xDrawable *sprite); void clear(); void render(); // manage main loop and thread loops void setFps(const uint32_t fps=0); void schedule(); // manage orchestrables void addOrchestrable(xOrchestrable* o); void removeOrchestrable(xOrchestrable* o); xAppState state; private: /** Singleton */ xApplication(const char *t, int w, int h); static xApplication* _instance; void syncFps(); // fps management uint32_t _lasttick { 0 }; uint32_t _fpstime { (int) 1000.0/60 }; // event management xController _controller; // sprites set _sprites; // execution pool set _orchestrables; // sdl objects SDL_Window *_window { NULL }; SDL_Rect _winrect { 0, 0, 0, 0 }; SDL_Renderer *_renderer { NULL }; SDL_Texture *_texture { NULL }; // thread safety mutex _mutex_draw; mutex _mutex_orchestrate; }; #endif