2016-03-12 23:22:28 +00:00
|
|
|
/* [CONSTRUCTOR] Constructeur de la classe
|
|
|
|
=========================================================*/
|
|
|
|
xManager::xManager(const char *t, int w, int h){
|
|
|
|
// default values
|
2016-03-13 13:53:39 +00:00
|
|
|
_lasttick = SDL_GetTicks();
|
2016-03-12 23:22:28 +00:00
|
|
|
_fpstime = 1000/60;
|
|
|
|
_window = NULL;
|
|
|
|
_renderer = NULL;
|
|
|
|
_texture = NULL;
|
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
_debug = (SDL_Rect){0, 0, 0, 0};
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// Initialisation des sous-sys. SDL
|
2016-03-15 22:54:12 +00:00
|
|
|
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Creation de la fenetre
|
|
|
|
_window = SDL_CreateWindow(
|
|
|
|
t,
|
|
|
|
SDL_WINDOWPOS_CENTERED,
|
|
|
|
SDL_WINDOWPOS_CENTERED,
|
|
|
|
w,
|
|
|
|
h,
|
2016-03-15 22:54:12 +00:00
|
|
|
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL
|
2016-03-12 23:22:28 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Gestion erreur
|
|
|
|
if( _window == NULL )
|
|
|
|
return;
|
|
|
|
|
2016-03-15 22:54:12 +00:00
|
|
|
cerr << "WINDOW CREATED" << endl;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// On enregistre les dimensions de la fenetre
|
2016-03-15 21:56:39 +00:00
|
|
|
_winrect.x = 0; _winrect.y = 0;
|
2016-03-14 22:46:10 +00:00
|
|
|
_winrect.w = w; _winrect.h = h;
|
2016-03-13 13:53:39 +00:00
|
|
|
SDL_GetWindowSize(_window, &_winrect.w, &_winrect.h);
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// Creation du renderer
|
|
|
|
_renderer = SDL_CreateRenderer(
|
|
|
|
_window,
|
|
|
|
-1,
|
|
|
|
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
|
|
|
|
);
|
|
|
|
|
2016-03-15 22:54:12 +00:00
|
|
|
// Gestion erreur
|
|
|
|
if( _renderer == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cerr << "RENDERER CREATED" << endl;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [DESTROYER] Destructeur de la classe
|
|
|
|
=========================================================*/
|
|
|
|
xManager::~xManager(){
|
|
|
|
SDL_DestroyTexture(_texture);
|
|
|
|
SDL_DestroyRenderer(_renderer);
|
|
|
|
SDL_DestroyWindow( _window );
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [STATUS] Retourne le status
|
|
|
|
=========================================================*/
|
|
|
|
bool xManager::status(){
|
|
|
|
return _window != NULL && _renderer != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [WINDOW] Retourne la fenetre
|
|
|
|
=========================================================*/
|
|
|
|
SDL_Window* xManager::window(){ return _window; }
|
|
|
|
|
|
|
|
|
|
|
|
/* [SCREEN] Retourne la fenetre
|
|
|
|
=========================================================*/
|
|
|
|
SDL_Renderer* xManager::renderer(){ return _renderer; }
|
|
|
|
|
|
|
|
|
|
|
|
/* [SETBACKGROUND] Modifie la couleur de fond
|
|
|
|
=========================================================*/
|
|
|
|
bool xManager::setBackground(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return false;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
SDL_SetRenderDrawColor( _renderer, r, g, b, a );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [SETIMAGE] Met une image en fond
|
|
|
|
=========================================================*/
|
|
|
|
bool xManager::setImage(const char *url){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return false;
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// On cree la texture associee
|
|
|
|
_texture = IMG_LoadTexture( _renderer, url );
|
|
|
|
|
|
|
|
return _texture != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-14 22:46:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
/* [COLLIDE] Retourne si 2 objets sont en collision
|
2016-03-13 19:36:16 +00:00
|
|
|
=========================================================*/
|
2016-03-17 22:18:52 +00:00
|
|
|
// collisions <vector<bool>*>
|
|
|
|
// [0] -> VRAI si collision a droite
|
|
|
|
// [1] -> VRAI si collision a gauche
|
|
|
|
// [2] -> VRAI si collision en haut
|
|
|
|
// [3] -> VRAI si collision en bas
|
|
|
|
bool xManager::collide(SDL_Rect a, SDL_Rect b, vector<bool>& cols){
|
|
|
|
if( !this->status() ) return true;
|
2016-03-14 22:46:10 +00:00
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
// Verification de collisions
|
|
|
|
bool outLeft = (a.x >= b.x+b.w ); // Trop a droite
|
|
|
|
bool outRight = (a.x+a.w <= b.x ); // Trop a gauche
|
|
|
|
bool outUp = (a.y >= b.y+b.h ); // Trop en haut
|
|
|
|
bool outDown = (a.y+a.h <= b.y ); // Trop en bas
|
2016-03-14 22:46:10 +00:00
|
|
|
|
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
// Calcule du bord en question
|
|
|
|
int distLeft = abs( (a.x+a.w) - b.x );
|
|
|
|
int distRight = abs( a.x - (b.x+b.w) );
|
|
|
|
int distBottom = abs( a.y - (b.y+b.h) );
|
|
|
|
int distTop = abs( (a.y+a.h) - b.y );
|
2016-03-14 22:46:10 +00:00
|
|
|
|
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
// Valeurs de retour pointeur
|
|
|
|
cols[0] = !outRight && distRight <= 1; // plus proche de droite
|
|
|
|
cols[1] = !outLeft && distLeft <= 2; // plus proche de gauche
|
|
|
|
cols[2] = !outUp && distTop <= 2; // plus proche du haut
|
|
|
|
cols[3] = !outDown && distBottom <= 1; // plus proche du bas
|
2016-03-15 21:56:39 +00:00
|
|
|
|
2016-03-15 22:54:12 +00:00
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
// On retourne si il y a collision ou pas
|
|
|
|
return !( outRight || outLeft || outUp || outDown );
|
2016-03-15 21:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [HIT] Retourne si une texture est en collision avec une autre
|
|
|
|
=========================================================*/
|
2016-03-15 23:15:18 +00:00
|
|
|
bool xManager::hit(xSprite* current, int movex, int movey){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return true;
|
|
|
|
|
2016-03-16 12:56:52 +00:00
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
// Anti conflit inter-thread
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_hit.try_lock();
|
2016-03-15 21:56:39 +00:00
|
|
|
|
|
|
|
/* (1) On recupere le SDL_Rect destination du sprite courant */
|
|
|
|
int xIndex = -1;
|
|
|
|
for( int i = 0 ; i < _sprites.size() ; i++ )
|
|
|
|
if( _sprites[i] == current ){
|
|
|
|
xIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( xIndex == -1 ){
|
|
|
|
_mutex_hit.unlock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-15 23:15:18 +00:00
|
|
|
SDL_Rect a = *current->dst();
|
|
|
|
a.x += movex;
|
|
|
|
a.y += movey;
|
2016-03-15 21:56:39 +00:00
|
|
|
|
2016-03-16 09:17:28 +00:00
|
|
|
// Contiendra le sens de collision
|
2016-03-17 22:18:52 +00:00
|
|
|
vector<bool> collideFrom(4, false);
|
|
|
|
// Contiendra le sens de collision
|
|
|
|
vector<bool> collideTo(4, false);
|
2016-03-16 09:17:28 +00:00
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
|
|
|
|
/* (2) On regarde si en dehors de la fenetre */
|
|
|
|
if( (a.x < _winrect.x ) // Inclus a droite
|
|
|
|
|| (a.x+a.w > _winrect.x+_winrect.w ) // Inclus a gauche
|
|
|
|
|| (a.y < _winrect.y ) // Inclus en haut
|
|
|
|
|| (a.y+a.h > _winrect.y+_winrect.h ) // Inclus en bas
|
2016-03-16 13:36:46 +00:00
|
|
|
){
|
|
|
|
// Si on tombe, on meurt
|
|
|
|
if( a.y+a.h > _winrect.y+_winrect.h )
|
|
|
|
state = 2;
|
|
|
|
|
2016-03-16 09:17:28 +00:00
|
|
|
cerr << _indexes[xIndex] << " collide with WINDOW" << endl;
|
2016-03-15 21:56:39 +00:00
|
|
|
_mutex_hit.unlock();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) On compare avec toutes les autres textures */
|
|
|
|
for( int i = 0 ; i < _sprites.size() ; i++ ){
|
|
|
|
|
|
|
|
// Si c'est pas le sprite courant
|
|
|
|
if( _sprites[i] != current ){
|
|
|
|
|
|
|
|
// On verifie que le sprite n'entre pas en collision
|
2016-03-17 22:18:52 +00:00
|
|
|
if( this->collide(a, *(_sprites[i])->dst(), collideTo) ){
|
|
|
|
|
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
// On recupere la surface en collision inverse
|
|
|
|
collideFrom[0] = collideTo[1]; // On inverse Droite
|
|
|
|
collideFrom[1] = collideTo[0]; // et Gauche
|
|
|
|
collideFrom[2] = collideTo[3]; // On inverse Haut
|
|
|
|
collideFrom[3] = collideTo[2]; // et Bas
|
2016-03-16 09:17:28 +00:00
|
|
|
|
|
|
|
// On lance les listeners de collision
|
2016-03-17 22:18:52 +00:00
|
|
|
_sprites[i]->onCollide(collideTo, current);
|
|
|
|
current->onCollide(collideFrom, _sprites[i]);
|
2016-03-15 21:56:39 +00:00
|
|
|
|
2016-03-15 23:15:18 +00:00
|
|
|
_debug = *(_sprites[i])->dst();
|
2016-03-16 09:17:28 +00:00
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
_mutex_hit.unlock();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// On debloque la ressource
|
|
|
|
_mutex_hit.unlock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
|
|
|
|
|
2016-03-14 22:46:10 +00:00
|
|
|
/* [HIT] Retourne si une texture est en collision avec une autre
|
|
|
|
=========================================================*/
|
|
|
|
bool xManager::hit(string current, int movex, int movey){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return true;
|
|
|
|
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_hit.try_lock();
|
2016-03-14 22:46:10 +00:00
|
|
|
|
|
|
|
/* (1) On recupere le SDL_Rect destination du sprite courant */
|
2016-03-15 23:15:18 +00:00
|
|
|
xSprite *sprite = NULL;
|
|
|
|
sprite = this->get(current);
|
2016-03-13 19:36:16 +00:00
|
|
|
|
2016-03-14 22:46:10 +00:00
|
|
|
// Gestion erreur
|
2016-03-15 23:15:18 +00:00
|
|
|
if( sprite == NULL ){
|
2016-03-14 22:46:10 +00:00
|
|
|
_mutex_hit.unlock();
|
|
|
|
return false;
|
2016-03-13 19:36:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-14 22:46:10 +00:00
|
|
|
// Retour du resultat
|
2016-03-13 23:06:33 +00:00
|
|
|
_mutex_hit.unlock();
|
2016-03-15 23:15:18 +00:00
|
|
|
return this->hit(sprite, movex, movey);
|
2016-03-13 19:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 17:33:47 +00:00
|
|
|
|
2016-03-15 23:15:18 +00:00
|
|
|
/* [GET] Renvoie le sprite
|
2016-03-13 17:33:47 +00:00
|
|
|
=========================================================*/
|
2016-03-15 23:15:18 +00:00
|
|
|
xSprite *xManager::get(string index){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return NULL;
|
|
|
|
|
2016-03-13 17:33:47 +00:00
|
|
|
|
|
|
|
// On cherche la texture avec l'index
|
|
|
|
for( int i = 0 ; i < _indexes.size() ; i++ )
|
|
|
|
if( _indexes[i] == index )
|
|
|
|
return _sprites[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
/* [PUSH] Ajoute une texture au rendu principal
|
|
|
|
=========================================================*/
|
2016-03-15 23:15:18 +00:00
|
|
|
void xManager::push(string index, xSprite* sprite){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// On bloque l'acces inter-thread
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_push.try_lock();
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 17:33:47 +00:00
|
|
|
_indexes.push_back( index );
|
2016-03-15 23:15:18 +00:00
|
|
|
_sprites.push_back( sprite );
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// On debloque l'acces
|
2016-03-13 23:06:33 +00:00
|
|
|
_mutex_push.unlock();
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [PULL] Retire une texture du rendu principal
|
|
|
|
=========================================================*/
|
2016-03-13 19:36:16 +00:00
|
|
|
void xManager::pull(string index){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// On bloque l'acces inter-thread
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_pull.try_lock();
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// On cherche l'indice de la texture
|
2016-03-13 17:33:47 +00:00
|
|
|
int xIndex = -1;
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 17:33:47 +00:00
|
|
|
for( int i = 0 ; i < _indexes.size() ; i++ )
|
|
|
|
if( _indexes[i] == index ) xIndex = i;
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// Si on a rien trouve
|
2016-03-13 17:33:47 +00:00
|
|
|
if( xIndex == -1 )
|
2016-03-12 23:22:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// On supprime la texture et ses dimensions
|
2016-03-13 17:33:47 +00:00
|
|
|
_indexes.erase( _indexes.begin() + xIndex );
|
|
|
|
_sprites.erase( _sprites.begin() + xIndex );
|
2016-03-13 19:36:16 +00:00
|
|
|
|
|
|
|
// On debloque l'acces
|
2016-03-13 23:06:33 +00:00
|
|
|
_mutex_pull.unlock();
|
2016-03-13 19:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [PULL] Retire une texture du rendu principal
|
|
|
|
=========================================================*/
|
2016-03-15 23:15:18 +00:00
|
|
|
void xManager::pull(xSprite* sprite){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-13 19:36:16 +00:00
|
|
|
// On bloque l'acces inter-thread
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_pull.try_lock();
|
2016-03-13 19:36:16 +00:00
|
|
|
|
|
|
|
// On cherche l'indice de la texture
|
|
|
|
int xIndex = -1;
|
|
|
|
|
|
|
|
for( int i = 0 ; i < _sprites.size() ; i++ )
|
2016-03-15 23:15:18 +00:00
|
|
|
if( _sprites[i] == sprite ) xIndex = i;
|
2016-03-13 19:36:16 +00:00
|
|
|
|
|
|
|
// Si on a rien trouve
|
|
|
|
if( xIndex == -1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// On supprime la texture et ses dimensions
|
|
|
|
_indexes.erase( _indexes.begin() + xIndex );
|
|
|
|
_sprites.erase( _sprites.begin() + xIndex );
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// On debloque l'acces
|
2016-03-13 23:06:33 +00:00
|
|
|
_mutex_pull.unlock();
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
|
2016-03-16 13:36:46 +00:00
|
|
|
/* [CLEARALL] Supprime toutes les sprites
|
|
|
|
=========================================================*/
|
|
|
|
void xManager::clearAll(){
|
|
|
|
_indexes.erase( _indexes.begin(), _indexes.end() );
|
|
|
|
_sprites.erase( _sprites.begin(), _sprites.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
|
|
|
|
/* [MANAGEFTP] Gestion de la vitesse de boucle
|
|
|
|
=========================================================*/
|
|
|
|
void xManager::manageFps(const int fps){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* (1) Definition de fps */
|
|
|
|
if( fps != 0 )
|
|
|
|
_fpstime = 1000/fps;
|
|
|
|
|
|
|
|
if( _lasttick == 0 )
|
|
|
|
_lasttick = SDL_GetTicks()-_fpstime;
|
|
|
|
|
|
|
|
/* (2) Utilisation en fin de boucle */
|
|
|
|
|
|
|
|
// 1 > Si trop rapide, on attends
|
|
|
|
if( SDL_GetTicks()-_lasttick < _fpstime )
|
|
|
|
SDL_Delay( _fpstime - (SDL_GetTicks()-_lasttick) );
|
|
|
|
|
|
|
|
// On enregistre le temps actuel
|
|
|
|
_lasttick = SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
/* [UPDATE] Mise a jour du rendu
|
|
|
|
=========================================================*/
|
|
|
|
void xManager::update(){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// cout << "Update MAIN SPRITE +" << _sprites.size() << " added sprites.." << endl;
|
2016-03-13 13:53:39 +00:00
|
|
|
// On bloque l'acces inter-thread
|
2016-03-16 12:56:52 +00:00
|
|
|
_mutex_update.try_lock();
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
/* (1) On efface le rendu */
|
|
|
|
SDL_RenderClear(_renderer);
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On applique la couleur de fond */
|
2016-03-13 13:53:39 +00:00
|
|
|
SDL_RenderDrawRect(_renderer, &_winrect);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (3) On ajoute le rendu principal (si existe) */
|
|
|
|
if( _texture != NULL)
|
|
|
|
SDL_RenderCopy(_renderer, _texture, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) On ajoute toutes les textures pushees */
|
|
|
|
for( int i = 0 ; i < _sprites.size() ; i++ )
|
2016-03-15 23:15:18 +00:00
|
|
|
SDL_RenderCopy(
|
|
|
|
_renderer,
|
|
|
|
_sprites[i]->texture(),
|
|
|
|
_sprites[i]->src(),
|
|
|
|
_sprites[i]->dst()
|
|
|
|
);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
// DEBUG
|
|
|
|
_debug = (SDL_Rect){_debug.x-1, _debug.y-1, _debug.w+2, _debug.h+2};
|
|
|
|
SDL_RenderDrawRect(_renderer, &_debug);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
/* (n) On affiche le resultat */
|
|
|
|
SDL_RenderPresent(_renderer);
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// On debloque l'acces
|
2016-03-13 23:06:33 +00:00
|
|
|
_mutex_update.unlock();
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* [ATTACHEVENT] Ajoute une fonction a un type d'evenement
|
2016-03-12 23:22:28 +00:00
|
|
|
=========================================================*/
|
2016-03-13 13:53:39 +00:00
|
|
|
void xManager::attachEvent(SDL_EventType t, void(*handler)(SDL_Event*)){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// On attache le type d'evenement a la fonction
|
|
|
|
_events.push_back( t );
|
|
|
|
_handlers.push_back( handler );
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* [MANAGEEVENTS] Gestion des evenements
|
|
|
|
=========================================================*/
|
|
|
|
void xManager::manageEvents(SDL_Event *event){
|
2016-03-15 22:54:12 +00:00
|
|
|
if( !this->status() ) return;
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// On lance les evenements en fonction de leur type
|
|
|
|
for( int i = 0 ; i < _events.size() ; i ++ )
|
|
|
|
if( event->type == _events[i] ) // si type ok
|
|
|
|
(*_handlers[i])(event); // on execute le handler
|
2016-03-15 21:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [DEBUG] Visualisation des donnees
|
|
|
|
=========================================================*/
|
|
|
|
void xManager::debug(){
|
|
|
|
for( int i = 0 ; i < _sprites.size() ; i++ ){
|
|
|
|
cerr << "INDEX: " << _indexes[i] << " AT " << i << endl;
|
2016-03-15 23:15:18 +00:00
|
|
|
cerr << " (" << (*_sprites[i]->dst()).x <<","<<(*_sprites[i]->dst()).y<<") -> (" << (*_sprites[i]->dst()).w << ", " << (*_sprites[i]->dst()).h << ")" << endl;
|
2016-03-15 21:56:39 +00:00
|
|
|
}
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|