From c2e54de4abfa9f586f5940571ade537c8f6adfa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Fri, 29 Mar 2024 21:52:02 +0100 Subject: [PATCH] Minor cleanup in the game state code --- src/smw/GameState.h | 63 +++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/smw/GameState.h b/src/smw/GameState.h index 6ca115055..afd93f4df 100644 --- a/src/smw/GameState.h +++ b/src/smw/GameState.h @@ -1,43 +1,40 @@ -#ifndef GAMESTATE_H -#define GAMESTATE_H +#pragma once -class GameState -{ - public: - virtual bool init() { return true; } - virtual void update() = 0; - virtual void cleanup() {} +#include - protected: - virtual void onEnterState() {} - virtual void onLeaveState() {} - friend class GameStateManager; -}; +class GameState { +public: + virtual bool init() { return true; } + virtual void update() = 0; + virtual void cleanup() {} + +protected: + virtual void onEnterState() {} + virtual void onLeaveState() {} -class GameStateManager -{ - public: - GameState* currentState; +friend class GameStateManager; +}; - void changeStateTo(GameState* newState) { - //assert(newState != 0); - currentState->onLeaveState(); - currentState = newState; - currentState->onEnterState(); - } - static GameStateManager& instance() { - static GameStateManager gsm; - return gsm; - } +class GameStateManager { +public: + GameState* currentState = nullptr; - private: + void changeStateTo(GameState* newState) { + assert(newState); + currentState->onLeaveState(); + currentState = newState; + currentState->onEnterState(); + } - GameStateManager() {} - GameStateManager(GameStateManager const&); - void operator=(GameStateManager const&); + static GameStateManager& instance() { + static GameStateManager gsm; + return gsm; + } +private: + GameStateManager() {} + GameStateManager(GameStateManager const&); + void operator=(GameStateManager const&); }; - -#endif // GAMESTATE_H