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