Amélioration de l'utilisation de la mémoire
This commit is contained in:
parent
dca255f7bd
commit
837621d18b
|
@ -18,8 +18,10 @@ class Manager {
|
||||||
private:
|
private:
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
sf::Time previous_time;
|
sf::Time previous_time;
|
||||||
|
|
||||||
sfg::SFGUI sfgui;
|
sfg::SFGUI sfgui;
|
||||||
sfg::Desktop desktop;
|
sfg::Desktop desktop;
|
||||||
|
std::vector<sfg::Widget::Ptr> widgets;
|
||||||
|
|
||||||
unsigned int framerate;
|
unsigned int framerate;
|
||||||
ResourceManager resource_manager;
|
ResourceManager resource_manager;
|
||||||
|
@ -53,6 +55,7 @@ public:
|
||||||
static const float GRID;
|
static const float GRID;
|
||||||
|
|
||||||
Manager();
|
Manager();
|
||||||
|
~Manager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Démarre la boucle principale du jeu
|
* Démarre la boucle principale du jeu
|
||||||
|
@ -102,9 +105,14 @@ public:
|
||||||
void useGUIView();
|
void useGUIView();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le bureau pour l'affichage de l'interface
|
* Ajoute un nouveau widget à l'interface
|
||||||
*/
|
*/
|
||||||
sfg::Desktop& getDesktop();
|
void addWidget(sfg::Widget::Ptr widget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime un widget de l'interface
|
||||||
|
*/
|
||||||
|
void removeWidget(sfg::Widget::Ptr widget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le titre actuel de la fenêtre
|
* Renvoie le titre actuel de la fenêtre
|
||||||
|
|
|
@ -34,9 +34,13 @@ inline sf::Vector2f roundVectorToGrid(sf::Vector2f input) {
|
||||||
Editor::Editor(Manager& manager) : Level(manager),
|
Editor::Editor(Manager& manager) : Level(manager),
|
||||||
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE),
|
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE),
|
||||||
widget_timer(manager, true, std::bind(&Editor::setTotalTime, this, std::placeholders::_1)),
|
widget_timer(manager, true, std::bind(&Editor::setTotalTime, this, std::placeholders::_1)),
|
||||||
toolbar(*this) {}
|
toolbar(*this) {
|
||||||
|
getManager().addWidget(toolbar.getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
Editor::~Editor() {}
|
Editor::~Editor() {
|
||||||
|
getManager().removeWidget(toolbar.getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::enable() {
|
void Editor::enable() {
|
||||||
Level::enable();
|
Level::enable();
|
||||||
|
@ -48,8 +52,8 @@ void Editor::enable() {
|
||||||
// joue la musique de l'éditeur
|
// joue la musique de l'éditeur
|
||||||
getResourceManager().playMusic("editor.ogg");
|
getResourceManager().playMusic("editor.ogg");
|
||||||
|
|
||||||
// ajout de la toolbar à la liste des widgets
|
// on affiche la toolbar de l'éditeur
|
||||||
getManager().getDesktop().Add(toolbar.getWindow());
|
toolbar.getWindow()->Show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::processEvent(const sf::Event& event) {
|
void Editor::processEvent(const sf::Event& event) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "manager.hpp"
|
#include "manager.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
const unsigned int Manager::FPS = 60;
|
const unsigned int Manager::FPS = 60;
|
||||||
const sf::Time Manager::FRAME_TIME = sf::seconds(1.f / Manager::FPS);
|
const sf::Time Manager::FRAME_TIME = sf::seconds(1.f / Manager::FPS);
|
||||||
|
@ -22,6 +23,11 @@ Manager::Manager() : previous_time(sf::seconds(0)), title(sf::String(L"")),
|
||||||
gui_view = window.getDefaultView();
|
gui_view = window.getDefaultView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Manager::~Manager() {
|
||||||
|
widgets.clear();
|
||||||
|
desktop.RemoveAll();
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::start() {
|
void Manager::start() {
|
||||||
while (!states.empty()) {
|
while (!states.empty()) {
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
@ -64,8 +70,10 @@ void Manager::start() {
|
||||||
if (previous_state != states.top().get()) {
|
if (previous_state != states.top().get()) {
|
||||||
previous_state = states.top().get();
|
previous_state = states.top().get();
|
||||||
|
|
||||||
// on vide l'interface de l'état précédent
|
// on masque tous les widgets de l'interface
|
||||||
desktop.RemoveAll();
|
for (const auto &widget : widgets) {
|
||||||
|
widget->Show(false);
|
||||||
|
}
|
||||||
|
|
||||||
// on initialise le nouvel état
|
// on initialise le nouvel état
|
||||||
previous_state->enable();
|
previous_state->enable();
|
||||||
|
@ -124,8 +132,16 @@ void Manager::useGUIView() {
|
||||||
window.setView(gui_view);
|
window.setView(gui_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
sfg::Desktop& Manager::getDesktop() {
|
void Manager::addWidget(sfg::Widget::Ptr widget) {
|
||||||
return desktop;
|
widgets.push_back(widget);
|
||||||
|
desktop.Add(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::removeWidget(sfg::Widget::Ptr widget) {
|
||||||
|
desktop.Remove(widget);
|
||||||
|
widgets.erase(std::remove(
|
||||||
|
widgets.begin(), widgets.end(), widget
|
||||||
|
), widgets.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::String Manager::getTitle() {
|
sf::String Manager::getTitle() {
|
||||||
|
|
Loading…
Reference in New Issue