parent
44de8cb3ea
commit
ab2f170def
|
@ -4,7 +4,7 @@
|
|||
#include "../xSDL/xOrchestrable.h"
|
||||
#include "../xSDL/xApplication.h"
|
||||
#include "../xSDL/xController.h"
|
||||
#include "../xSDL/xElement.h"
|
||||
#include "../xSDL/xDrawable.h"
|
||||
#include "../xSDL/xSprite.h"
|
||||
|
||||
#endif
|
|
@ -139,7 +139,7 @@ bool xApplication::setImage(const char *url){
|
|||
|
||||
|
||||
// // Anti conflit inter-thread
|
||||
// _mutex_hit.try_lock();
|
||||
// _mutex_hit.lock();
|
||||
|
||||
// /* (1) On recupere le SDL_Rect destination du sprite courant */
|
||||
// int xIndex = -1;
|
||||
|
@ -224,7 +224,7 @@ bool xApplication::setImage(const char *url){
|
|||
// bool xApplication::hit(string current, int movex, int movey){
|
||||
// if( !this->status() ) return true;
|
||||
|
||||
// _mutex_hit.try_lock();
|
||||
// _mutex_hit.lock();
|
||||
|
||||
// /* (1) On recupere le SDL_Rect destination du sprite courant */
|
||||
// xSprite *sprite = NULL;
|
||||
|
@ -245,29 +245,29 @@ bool xApplication::setImage(const char *url){
|
|||
|
||||
|
||||
/** adds new sprite to draw */
|
||||
void xApplication::push(xElement* sprite){
|
||||
_mutex_draw.try_lock();
|
||||
void xApplication::push(xDrawable* sprite){
|
||||
_mutex_draw.lock();
|
||||
_sprites.insert(sprite);
|
||||
_mutex_draw.unlock();
|
||||
}
|
||||
|
||||
/** removes a sprite to draw (from its address) */
|
||||
void xApplication::pull(xElement* sprite){
|
||||
_mutex_draw.try_lock();
|
||||
void xApplication::pull(xDrawable* sprite){
|
||||
_mutex_draw.lock();
|
||||
_sprites.erase(sprite);
|
||||
_mutex_draw.unlock();
|
||||
}
|
||||
|
||||
/** clears the scene */
|
||||
void xApplication::clear(){
|
||||
_mutex_draw.try_lock();
|
||||
_mutex_draw.lock();
|
||||
_sprites.clear();
|
||||
_mutex_draw.unlock();
|
||||
}
|
||||
|
||||
/** Update the scene */
|
||||
void xApplication::render(){
|
||||
_mutex_draw.try_lock();
|
||||
_mutex_draw.lock();
|
||||
|
||||
/* 1. clear scene */
|
||||
SDL_RenderClear(_renderer);
|
||||
|
@ -281,9 +281,9 @@ void xApplication::render(){
|
|||
|
||||
|
||||
/* 4. draw every sprite */
|
||||
set<xElement*>::iterator it;
|
||||
set<xDrawable*>::iterator it;
|
||||
for( it = _sprites.begin() ; it != _sprites.end() ; it++ ){
|
||||
xElement* sprite = *it;
|
||||
xDrawable* sprite = *it;
|
||||
sprite->draw(_renderer);
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ void xApplication::schedule(){
|
|||
const uint32_t ticks = SDL_GetTicks();
|
||||
|
||||
// trigger tick() on registered orchestrables
|
||||
_mutex_orchestrate.try_lock();
|
||||
_mutex_orchestrate.lock();
|
||||
set<xOrchestrable*>::iterator it;
|
||||
for( it = _orchestrables.begin() ; it != _orchestrables.end() ; it++ ){
|
||||
xOrchestrable* orchestrable = *it;
|
||||
|
@ -324,13 +324,13 @@ void xApplication::schedule(){
|
|||
}
|
||||
|
||||
void xApplication::addOrchestrable(xOrchestrable* o){
|
||||
_mutex_orchestrate.try_lock();
|
||||
_mutex_orchestrate.lock();
|
||||
_orchestrables.insert(o);
|
||||
_mutex_orchestrate.unlock();
|
||||
}
|
||||
|
||||
void xApplication::removeOrchestrable(xOrchestrable* o){
|
||||
_mutex_orchestrate.try_lock();
|
||||
_mutex_orchestrate.lock();
|
||||
_orchestrables.erase(o);
|
||||
_mutex_orchestrate.unlock();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <stdexcept>
|
||||
#include "xElement.h"
|
||||
#include "xDrawable.h"
|
||||
#include "xController.h"
|
||||
#include "xOrchestrable.h"
|
||||
using namespace std;
|
||||
|
@ -41,8 +41,8 @@
|
|||
// bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
|
||||
|
||||
/** scene */
|
||||
void push(xElement* sprite);
|
||||
void pull(xElement *sprite);
|
||||
void push(xDrawable* sprite);
|
||||
void pull(xDrawable *sprite);
|
||||
void clear();
|
||||
|
||||
void render();
|
||||
|
@ -71,7 +71,7 @@
|
|||
xController _controller;
|
||||
|
||||
// sprites
|
||||
set<xElement*> _sprites;
|
||||
set<xDrawable*> _sprites;
|
||||
|
||||
// execution pool
|
||||
set<xOrchestrable*> _orchestrables;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include "xDrawable.h"
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
struct xElement {
|
||||
struct xDrawable {
|
||||
virtual void draw(SDL_Renderer* renderer) = 0;
|
||||
};
|
||||
|
|
@ -1 +0,0 @@
|
|||
#include "xElement.h"
|
Loading…
Reference in New Issue