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:
|
||||
sf::RenderWindow window;
|
||||
sf::Time previous_time;
|
||||
|
||||
sfg::SFGUI sfgui;
|
||||
sfg::Desktop desktop;
|
||||
std::vector<sfg::Widget::Ptr> widgets;
|
||||
|
||||
unsigned int framerate;
|
||||
ResourceManager resource_manager;
|
||||
|
@ -53,6 +55,7 @@ public:
|
|||
static const float GRID;
|
||||
|
||||
Manager();
|
||||
~Manager();
|
||||
|
||||
/**
|
||||
* Démarre la boucle principale du jeu
|
||||
|
@ -102,9 +105,14 @@ public:
|
|||
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
|
||||
|
|
|
@ -34,9 +34,13 @@ inline sf::Vector2f roundVectorToGrid(sf::Vector2f input) {
|
|||
Editor::Editor(Manager& manager) : Level(manager),
|
||||
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE),
|
||||
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() {
|
||||
Level::enable();
|
||||
|
@ -48,8 +52,8 @@ void Editor::enable() {
|
|||
// joue la musique de l'éditeur
|
||||
getResourceManager().playMusic("editor.ogg");
|
||||
|
||||
// ajout de la toolbar à la liste des widgets
|
||||
getManager().getDesktop().Add(toolbar.getWindow());
|
||||
// on affiche la toolbar de l'éditeur
|
||||
toolbar.getWindow()->Show(true);
|
||||
}
|
||||
|
||||
void Editor::processEvent(const sf::Event& event) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "state.hpp"
|
||||
#include "manager.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
const unsigned int Manager::FPS = 60;
|
||||
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();
|
||||
}
|
||||
|
||||
Manager::~Manager() {
|
||||
widgets.clear();
|
||||
desktop.RemoveAll();
|
||||
}
|
||||
|
||||
void Manager::start() {
|
||||
while (!states.empty()) {
|
||||
sf::Event event;
|
||||
|
@ -64,8 +70,10 @@ void Manager::start() {
|
|||
if (previous_state != states.top().get()) {
|
||||
previous_state = states.top().get();
|
||||
|
||||
// on vide l'interface de l'état précédent
|
||||
desktop.RemoveAll();
|
||||
// on masque tous les widgets de l'interface
|
||||
for (const auto &widget : widgets) {
|
||||
widget->Show(false);
|
||||
}
|
||||
|
||||
// on initialise le nouvel état
|
||||
previous_state->enable();
|
||||
|
@ -124,8 +132,16 @@ void Manager::useGUIView() {
|
|||
window.setView(gui_view);
|
||||
}
|
||||
|
||||
sfg::Desktop& Manager::getDesktop() {
|
||||
return desktop;
|
||||
void Manager::addWidget(sfg::Widget::Ptr widget) {
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue