1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-04 18:29:41 +01:00

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.)
This commit is contained in:
Misa 2021-12-17 23:57:55 -08:00
parent b67386894c
commit 119e25d0bb
3 changed files with 12 additions and 5 deletions

View file

@ -1,7 +1,7 @@
#ifndef ENUMGAME_H #ifndef ENUMGAME_H
#define ENUMGAME_H #define ENUMGAME_H
enum enum GameGamestate
{ {
GAMEMODE, TITLEMODE, CLICKTOSTART, FOCUSMODE, MAPMODE, TELEPORTERMODE, GAMECOMPLETE, GAMECOMPLETE2, EDITORMODE, PRELOADER GAMEMODE, TITLEMODE, CLICKTOSTART, FOCUSMODE, MAPMODE, TELEPORTERMODE, GAMECOMPLETE, GAMECOMPLETE2, EDITORMODE, PRELOADER

View file

@ -6877,7 +6877,7 @@ void Game::unlockAchievement(const char *name) {
#endif #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) if (user_initiated && graphics.resumegamemode)
{ {

View file

@ -7,6 +7,13 @@
#include "ScreenSettings.h" #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 <tinyxml2.h> // Forward decl without including all of <tinyxml2.h>
namespace tinyxml2 namespace tinyxml2
{ {
@ -227,8 +234,8 @@ public:
bool glitchrunkludge; bool glitchrunkludge;
int gamestate; enum GameGamestate gamestate;
int prevgamestate; //only used sometimes enum GameGamestate prevgamestate; //only used sometimes
bool hascontrol, jumpheld; bool hascontrol, jumpheld;
int jumppressed; int jumppressed;
int gravitycontrol; int gravitycontrol;
@ -242,7 +249,7 @@ public:
int tapleft, tapright; int tapleft, tapright;
//Menu interaction stuff //Menu interaction stuff
void mapmenuchange(const int newgamestate, const bool user_initiated); void mapmenuchange(const enum GameGamestate newgamestate, const bool user_initiated);
bool mapheld; bool mapheld;
int menupage; int menupage;
int lastsaved; int lastsaved;