Commit 10d62e08 authored by Elias Leinenweber's avatar Elias Leinenweber
Browse files

Condition d'arrêt plus propre

parent 6fcec69c
......@@ -13,7 +13,6 @@ class Game
{
private:
static GameWindow *mainWindow;
static bool running;
static std::vector<Component *> components;
public:
......
......@@ -24,12 +24,8 @@ class GameWindow : public sf::RenderWindow
*/
GameWindow();
/**
* Gestion des évènements.
*
* @param running
*/
void handleEvents(bool &running);
/** @brief Gestion des évènements. */
void handleEvents();
/**
* Dessin et rendu.
......
......@@ -15,7 +15,6 @@
#include "view/MainView.h"
GameWindow *Game::mainWindow = nullptr;
bool Game::running = true;
std::vector<Component *> Game::components = std::vector<Component *>();
void
......@@ -30,8 +29,8 @@ Game::start()
void
Game::loop(sf::Clock &clock)
{
while (running) {
mainWindow->handleEvents(running);
while (mainWindow->isOpen()) {
mainWindow->handleEvents();
ImGui::SFML::Update(*mainWindow, clock.restart());
for (const Component *component : components)
component->render();
......@@ -69,7 +68,7 @@ Game::getMainWindow()
void
Game::stop()
{
running = false;
mainWindow->close();
}
void
......
......@@ -23,7 +23,7 @@ GameWindow::GameWindow()
}
void
GameWindow::handleEvents(bool &running)
GameWindow::handleEvents()
{
sf::Event event;
......@@ -31,7 +31,7 @@ GameWindow::handleEvents(bool &running)
ImGui::SFML::ProcessEvent(event);
if (event.type == sf::Event::Closed) {
/* Stoppe le programme. */
running = false;
close();
} else if (event.type == sf::Event::Resized) {
/* Ajuste le viewport lorsque la fenêtre est redimensionnée. */
glViewport(0, 0, event.size.width, event.size.height);
......
......@@ -24,7 +24,7 @@ MainMenu::render() const
if (ImGui::Button("Nouvelle partie"))
Game::newGame();
if (ImGui::Button("Quitter"))
Game::end();
Game::stop();
}
ImGui::End();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment