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) */
|
||||
void xApplication::push(string id, xElement* sprite){
|
||||
/** adds new sprite to draw */
|
||||
void xApplication::push(xElement* sprite){
|
||||
_mutex_draw.try_lock();
|
||||
_sprites[id] = sprite;
|
||||
_sprites.insert(sprite);
|
||||
_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) */
|
||||
void xApplication::pull(xElement* sprite){
|
||||
_mutex_draw.try_lock();
|
||||
|
||||
map<string, xElement*>::iterator it;
|
||||
for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){
|
||||
if( sprite == it->second ){
|
||||
_sprites.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_sprites.erase(sprite);
|
||||
_mutex_draw.unlock();
|
||||
}
|
||||
|
||||
|
@ -297,9 +281,9 @@ void xApplication::render(){
|
|||
|
||||
|
||||
/* 4. draw every sprite */
|
||||
map<string, xElement*>::iterator it = _sprites.begin();
|
||||
for( ; it != _sprites.end() ; it++ ){
|
||||
xElement* sprite = it->second;
|
||||
set<xElement*>::iterator it;
|
||||
for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){
|
||||
xElement* sprite = *it;
|
||||
sprite->draw(_renderer);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,7 @@
|
|||
// bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
|
||||
|
||||
/** scene */
|
||||
void push(string id, xElement* sprite);
|
||||
void pull(string id);
|
||||
void push(xElement* sprite);
|
||||
void pull(xElement *sprite);
|
||||
void clear();
|
||||
|
||||
|
@ -68,6 +67,9 @@
|
|||
// event management
|
||||
xController _controller;
|
||||
|
||||
// sprites
|
||||
set<xElement*> _sprites;
|
||||
|
||||
// sdl objects
|
||||
SDL_Window *_window;
|
||||
SDL_Rect _winrect;
|
||||
|
@ -75,12 +77,6 @@
|
|||
SDL_Renderer *_renderer;
|
||||
SDL_Texture *_texture;
|
||||
|
||||
// sprites
|
||||
map<string, xElement*> _sprites;
|
||||
|
||||
// shared threads
|
||||
map<string, thread*> _pool;
|
||||
|
||||
// thread safety
|
||||
mutex _mutex_draw;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue