2019-11-05 20:45:41 +00:00
|
|
|
#ifndef DEF_XENGINE_H
|
|
|
|
#define DEF_XENGINE_H
|
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_image.h"
|
|
|
|
#include <vector>
|
2019-11-06 21:48:25 +00:00
|
|
|
#include <set>
|
2019-11-05 20:45:41 +00:00
|
|
|
#include <string>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <stdexcept>
|
2020-02-02 15:17:52 +00:00
|
|
|
#include "xDrawable.h"
|
2019-11-05 20:45:41 +00:00
|
|
|
#include "xController.h"
|
2019-11-06 21:48:25 +00:00
|
|
|
#include "xOrchestrable.h"
|
2019-11-05 20:45:41 +00:00
|
|
|
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<bool>& 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 */
|
2020-02-02 15:17:52 +00:00
|
|
|
void push(xDrawable* sprite);
|
|
|
|
void pull(xDrawable *sprite);
|
2019-11-05 20:45:41 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
void render();
|
|
|
|
|
|
|
|
// manage main loop and thread loops
|
2019-11-06 21:43:46 +00:00
|
|
|
void setFps(const uint32_t fps=0);
|
2019-11-05 20:45:41 +00:00
|
|
|
void schedule();
|
|
|
|
|
2019-11-06 21:48:25 +00:00
|
|
|
// manage orchestrables
|
|
|
|
void addOrchestrable(xOrchestrable* o);
|
|
|
|
void removeOrchestrable(xOrchestrable* o);
|
|
|
|
|
2019-11-05 20:45:41 +00:00
|
|
|
xAppState state;
|
|
|
|
private:
|
|
|
|
/** Singleton */
|
|
|
|
xApplication(const char *t, int w, int h);
|
|
|
|
static xApplication* _instance;
|
|
|
|
|
2019-11-06 21:43:46 +00:00
|
|
|
void syncFps();
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
// fps management
|
|
|
|
uint32_t _lasttick;
|
|
|
|
uint32_t _fpstime;
|
|
|
|
|
|
|
|
// event management
|
|
|
|
xController _controller;
|
|
|
|
|
2019-11-06 21:47:11 +00:00
|
|
|
// sprites
|
2020-02-02 15:17:52 +00:00
|
|
|
set<xDrawable*> _sprites;
|
2019-11-06 21:47:11 +00:00
|
|
|
|
2019-11-06 21:48:25 +00:00
|
|
|
// execution pool
|
|
|
|
set<xOrchestrable*> _orchestrables;
|
|
|
|
|
2019-11-05 20:45:41 +00:00
|
|
|
// sdl objects
|
|
|
|
SDL_Window *_window;
|
|
|
|
SDL_Rect _winrect;
|
|
|
|
|
|
|
|
SDL_Renderer *_renderer;
|
|
|
|
SDL_Texture *_texture;
|
|
|
|
|
|
|
|
// thread safety
|
|
|
|
mutex _mutex_draw;
|
2019-11-06 21:48:25 +00:00
|
|
|
mutex _mutex_orchestrate;
|
2019-11-05 20:45:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|