Utilisation de pointeurs natifs plutôt qu'intelligents
This commit is contained in:
parent
773a703c76
commit
0dc46b5e7c
|
@ -69,7 +69,7 @@ Engine::Engine() {
|
||||||
void Engine::update(State state) {
|
void Engine::update(State state) {
|
||||||
// demande la mise à jour de tous les objets du jeu
|
// demande la mise à jour de tous les objets du jeu
|
||||||
for (int i = 0; i < objects.size(); i++) {
|
for (int i = 0; i < objects.size(); i++) {
|
||||||
objects[i]->update(state, delta);
|
objects[i]->update(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,7 @@ void Engine::draw() {
|
||||||
window.clear(sf::Color(66, 165, 245));
|
window.clear(sf::Color(66, 165, 245));
|
||||||
|
|
||||||
// chargement de la file d'affichage des objets
|
// chargement de la file d'affichage des objets
|
||||||
typedef std::unique_ptr<Object> ObjectPtr;
|
std::priority_queue<Object*, std::vector<Object*>, CompareObjectLayer> display_queue;
|
||||||
std::priority_queue<ObjectPtr, std::vector<ObjectPtr>, CompareObjectLayer> display_queue;
|
|
||||||
|
|
||||||
for (int i = 0; i < objects.size(); i++) {
|
for (int i = 0; i < objects.size(); i++) {
|
||||||
display_queue.push(objects[i]);
|
display_queue.push(objects[i]);
|
||||||
|
@ -89,6 +88,7 @@ void Engine::draw() {
|
||||||
unsigned int layer = 0;
|
unsigned int layer = 0;
|
||||||
|
|
||||||
while (!display_queue.empty()) {
|
while (!display_queue.empty()) {
|
||||||
display_queue.pop()->draw(window);
|
display_queue.top()->draw(window);
|
||||||
|
display_queue.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define PTF_ENGINE_HPP
|
#define PTF_ENGINE_HPP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
|
@ -19,7 +18,7 @@ private:
|
||||||
bool goLeftKey;
|
bool goLeftKey;
|
||||||
bool goRightKey;
|
bool goRightKey;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Object>> objects;
|
std::vector<Object*> objects;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Engine();
|
Engine();
|
||||||
|
|
|
@ -44,8 +44,8 @@ public:
|
||||||
* qui doit être dessinée avant celle du second
|
* qui doit être dessinée avant celle du second
|
||||||
*/
|
*/
|
||||||
struct CompareObjectLayer {
|
struct CompareObjectLayer {
|
||||||
bool operator()(Object const &obj1, Object const &obj2) {
|
bool operator()(Object* const &obj1, Object* const &obj2) {
|
||||||
return obj1.getLayer() < obj2.getLayer();
|
return obj1->getLayer() < obj2->getLayer();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue