From 119e25d0bbd0db360410410367d58ffcf9711ef4 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 17 Dec 2021 23:57:55 -0800 Subject: [PATCH] Change all game-gamestates to use an enum type Currently, all game-gamestate variables are just ints. This is not particularly type-safe, in case the number of enums changes. To verify that all current uses of the game-gamestate variables actually use the enums, change them to be typed with the enum instead. (As an aside, we should probably rename this so that it can't be confused with Terry's state machine that has several different ways to exploit to warp you to the credits, but that's something to do later.) --- desktop_version/src/Enums.h | 2 +- desktop_version/src/Game.cpp | 2 +- desktop_version/src/Game.h | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/desktop_version/src/Enums.h b/desktop_version/src/Enums.h index 4b7c852b..fc4bedd6 100644 --- a/desktop_version/src/Enums.h +++ b/desktop_version/src/Enums.h @@ -1,7 +1,7 @@ #ifndef ENUMGAME_H #define ENUMGAME_H -enum +enum GameGamestate { GAMEMODE, TITLEMODE, CLICKTOSTART, FOCUSMODE, MAPMODE, TELEPORTERMODE, GAMECOMPLETE, GAMECOMPLETE2, EDITORMODE, PRELOADER diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 9e2e8765..49e29968 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6877,7 +6877,7 @@ void Game::unlockAchievement(const char *name) { #endif } -void Game::mapmenuchange(const int newgamestate, const bool user_initiated) +void Game::mapmenuchange(const enum GameGamestate newgamestate, const bool user_initiated) { if (user_initiated && graphics.resumegamemode) { diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index e78b6384..de7f12ba 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -7,6 +7,13 @@ #include "ScreenSettings.h" +/* FIXME: Can't forward declare this enum in C++, unfortunately. + * In C, enum sizes are always the same, so you can forward declare them. + * In C++ instead, enum sizes are based on how many enums there are. + * You cannot specify the underlying type until C++11. + * But bumping the standard opens up a can of worms. I'd rather just move to C. -Misa */ +#include "Enums.h" + // Forward decl without including all of namespace tinyxml2 { @@ -227,8 +234,8 @@ public: bool glitchrunkludge; - int gamestate; - int prevgamestate; //only used sometimes + enum GameGamestate gamestate; + enum GameGamestate prevgamestate; //only used sometimes bool hascontrol, jumpheld; int jumppressed; int gravitycontrol; @@ -242,7 +249,7 @@ public: int tapleft, tapright; //Menu interaction stuff - void mapmenuchange(const int newgamestate, const bool user_initiated); + void mapmenuchange(const enum GameGamestate newgamestate, const bool user_initiated); bool mapheld; int menupage; int lastsaved;