Simplify push/pull by reference, no more string identifier
This commit is contained in:
parent
0997541fc7
commit
2cbf3bc91b
|
@ -244,33 +244,17 @@ bool xApplication::setImage(const char *url){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** adds new sprite to draw (with its identifier) */
|
/** adds new sprite to draw */
|
||||||
void xApplication::push(string id, xElement* sprite){
|
void xApplication::push(xElement* sprite){
|
||||||
_mutex_draw.try_lock();
|
_mutex_draw.try_lock();
|
||||||
_sprites[id] = sprite;
|
_sprites.insert(sprite);
|
||||||
_mutex_draw.unlock();
|
_mutex_draw.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** removes a sprite to draw (from its identifier) */
|
|
||||||
void xApplication::pull(string id){
|
|
||||||
_mutex_draw.try_lock();
|
|
||||||
_sprites.erase(id);
|
|
||||||
_mutex_draw.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** removes a sprite to draw (from its address) */
|
/** removes a sprite to draw (from its address) */
|
||||||
void xApplication::pull(xElement* sprite){
|
void xApplication::pull(xElement* sprite){
|
||||||
_mutex_draw.try_lock();
|
_mutex_draw.try_lock();
|
||||||
|
_sprites.erase(sprite);
|
||||||
map<string, xElement*>::iterator it;
|
|
||||||
for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){
|
|
||||||
if( sprite == it->second ){
|
|
||||||
_sprites.erase(it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_mutex_draw.unlock();
|
_mutex_draw.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,9 +281,9 @@ void xApplication::render(){
|
||||||
|
|
||||||
|
|
||||||
/* 4. draw every sprite */
|
/* 4. draw every sprite */
|
||||||
map<string, xElement*>::iterator it = _sprites.begin();
|
set<xElement*>::iterator it;
|
||||||
for( ; it != _sprites.end() ; it++ ){
|
for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){
|
||||||
xElement* sprite = it->second;
|
xElement* sprite = *it;
|
||||||
sprite->draw(_renderer);
|
sprite->draw(_renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,7 @@
|
||||||
// bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
|
// bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
|
||||||
|
|
||||||
/** scene */
|
/** scene */
|
||||||
void push(string id, xElement* sprite);
|
void push(xElement* sprite);
|
||||||
void pull(string id);
|
|
||||||
void pull(xElement *sprite);
|
void pull(xElement *sprite);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
@ -68,6 +67,9 @@
|
||||||
// event management
|
// event management
|
||||||
xController _controller;
|
xController _controller;
|
||||||
|
|
||||||
|
// sprites
|
||||||
|
set<xElement*> _sprites;
|
||||||
|
|
||||||
// sdl objects
|
// sdl objects
|
||||||
SDL_Window *_window;
|
SDL_Window *_window;
|
||||||
SDL_Rect _winrect;
|
SDL_Rect _winrect;
|
||||||
|
@ -75,12 +77,6 @@
|
||||||
SDL_Renderer *_renderer;
|
SDL_Renderer *_renderer;
|
||||||
SDL_Texture *_texture;
|
SDL_Texture *_texture;
|
||||||
|
|
||||||
// sprites
|
|
||||||
map<string, xElement*> _sprites;
|
|
||||||
|
|
||||||
// shared threads
|
|
||||||
map<string, thread*> _pool;
|
|
||||||
|
|
||||||
// thread safety
|
// thread safety
|
||||||
mutex _mutex_draw;
|
mutex _mutex_draw;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue