Skip to content

Commit 5856a3c

Browse files
committed
refactor(gamelogic): Use GameMode enum instead of integer (#1369)
1 parent 0d850ca commit 5856a3c

File tree

8 files changed

+42
-28
lines changed

8 files changed

+42
-28
lines changed

Generals/Code/GameEngine/Include/GameLogic/GameLogic.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ enum BuildableStatus CPP_11(: Int);
7171
typedef const CommandButton* ConstCommandButtonPtr;
7272

7373
// What kind of game we're in.
74-
enum
74+
enum GameMode CPP_11(: Int)
7575
{
7676
GAME_SINGLE_PLAYER,
7777
GAME_LAN,
@@ -116,7 +116,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
116116

117117
void processCommandList( CommandList *list ); ///< process the command list
118118

119-
void prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints ); ///< prepare for new game
119+
void prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints ); ///< prepare for new game
120120

121121
void logicMessageDispatcher( GameMessage *msg,
122122
void *userData ); ///< Logic command list processing
@@ -162,9 +162,10 @@ class GameLogic : public SubsystemInterface, public Snapshot
162162
void deleteLoadScreen( void );
163163

164164
void setGameLoading( Bool loading );
165-
void setGameMode( Int mode );
166-
Int getGameMode( void );
167-
Bool isInGame( void );
165+
void setGameMode( GameMode mode );
166+
GameMode getGameMode( void );
167+
168+
Bool isInGame( void ); // Includes Shell Game
168169
Bool isInLanGame( void );
169170
Bool isInSinglePlayerGame( void );
170171
Bool isInSkirmishGame( void );
@@ -335,7 +336,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
335336
virtual TerrainLogic *createTerrainLogic( void );
336337
virtual GhostObjectManager *createGhostObjectManager(void);
337338

338-
Int m_gameMode;
339+
GameMode m_gameMode;
339340
Int m_rankLevelLimit;
340341

341342
LoadScreen *getLoadScreen( Bool saveGame );
@@ -386,12 +387,11 @@ inline void GameLogic::setHeight( Real height ) { m_height = height; }
386387
inline Real GameLogic::getHeight( void ) { return m_height; }
387388
inline UnsignedInt GameLogic::getFrame( void ) { return m_frame; }
388389

389-
inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }
390-
inline void GameLogic::setGameMode( Int mode ) { m_gameMode = mode; }
391-
inline Int GameLogic::getGameMode( void ) { return m_gameMode; }
390+
inline Bool GameLogic::isInGame( void ) { return m_gameMode != GAME_NONE; }
391+
inline GameMode GameLogic::getGameMode( void ) { return m_gameMode; }
392392
inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }
393393
inline Bool GameLogic::isInSkirmishGame( void ) { return (m_gameMode == GAME_SKIRMISH); }
394-
inline Bool GameLogic::isInMultiplayerGame( void ) { return ((m_gameMode == GAME_LAN) || (m_gameMode == GAME_INTERNET)) ; }
394+
inline Bool GameLogic::isInMultiplayerGame( void ) { return (m_gameMode == GAME_LAN) || (m_gameMode == GAME_INTERNET) ; }
395395
inline Bool GameLogic::isInReplayGame( void ) { return (m_gameMode == GAME_REPLAY); }
396396
inline Bool GameLogic::isInInternetGame( void ) { return (m_gameMode == GAME_INTERNET); }
397397
inline Bool GameLogic::isInShellGame( void ) { return (m_gameMode == GAME_SHELL); }

Generals/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void GameStateMap::xfer( Xfer *xfer )
305305
if (currentVersion >= 2)
306306
{
307307
// save the game mode.
308-
Int gameMode = TheGameLogic->getGameMode();
308+
Int gameMode = (Int)TheGameLogic->getGameMode();
309309
xfer->xferInt( &gameMode);
310310
}
311311

@@ -338,7 +338,7 @@ void GameStateMap::xfer( Xfer *xfer )
338338
// get the game mode.
339339
Int gameMode;
340340
xfer->xferInt(&gameMode);
341-
TheGameLogic->setGameMode(gameMode);
341+
TheGameLogic->setGameMode((GameMode)gameMode);
342342
}
343343

344344
} // end else, load

Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,13 @@ void GameLogic::setGameLoading( Bool loading )
984984
m_loadingScene = loading;
985985
}
986986

987+
// ------------------------------------------------------------------------------------------------
988+
// ------------------------------------------------------------------------------------------------
989+
void GameLogic::setGameMode( GameMode mode )
990+
{
991+
m_gameMode = mode;
992+
}
993+
987994
// ------------------------------------------------------------------------------------------------
988995
/** Entry point for starting a new game, the engine is already in clean state at this
989996
* point and ready to load up with all the data */

Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void GameLogic::clearGameData( Bool showScoreScreen )
296296
// ------------------------------------------------------------------------------------------------
297297
/** Prepare for a new game */
298298
// ------------------------------------------------------------------------------------------------
299-
void GameLogic::prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints )
299+
void GameLogic::prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints )
300300
{
301301
//Added By Sadullah Nader
302302
//Fix for loading game scene
@@ -413,7 +413,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
413413
case GameMessage::MSG_NEW_GAME:
414414
{
415415
//DEBUG_ASSERTCRASH(msg->getArgumentCount() == 1 || msg->getArgumentCount() == 2, ("%d arguments to MSG_NEW_GAME", msg->getArgumentCount()));
416-
Int gameMode = msg->getArgument( 0 )->integer;
416+
GameMode gameMode = (GameMode)msg->getArgument( 0 )->integer;
417417
Int rankPoints = 0;
418418
GameDifficulty diff = DIFFICULTY_NORMAL;
419419
if ( msg->getArgumentCount() >= 2 )

GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ enum BuildableStatus CPP_11(: Int);
7272
typedef const CommandButton* ConstCommandButtonPtr;
7373

7474
// What kind of game we're in.
75-
enum
75+
enum GameMode CPP_11(: Int)
7676
{
7777
GAME_SINGLE_PLAYER,
7878
GAME_LAN,
@@ -121,7 +121,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
121121
#endif
122122
void processCommandList( CommandList *list ); ///< process the command list
123123

124-
void prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints ); ///< prepare for new game
124+
void prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints ); ///< prepare for new game
125125

126126
void logicMessageDispatcher( GameMessage *msg,
127127
void *userData ); ///< Logic command list processing
@@ -172,9 +172,10 @@ class GameLogic : public SubsystemInterface, public Snapshot
172172
void setLoadingSave( Bool loading ) { m_loadingSave = loading; }
173173
void setClearingGameData( Bool clearing ) { m_clearingGameData = clearing; }
174174

175-
void setGameMode( Int mode );
176-
Int getGameMode( void );
177-
Bool isInGame( void );
175+
void setGameMode( GameMode mode );
176+
GameMode getGameMode( void );
177+
178+
Bool isInGame( void ); // Includes Shell Game
178179
Bool isInLanGame( void );
179180
Bool isInSinglePlayerGame( void );
180181
Bool isInSkirmishGame( void );
@@ -358,7 +359,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
358359
virtual TerrainLogic *createTerrainLogic( void );
359360
virtual GhostObjectManager *createGhostObjectManager(void);
360361

361-
Int m_gameMode;
362+
GameMode m_gameMode;
362363
Int m_rankLevelLimit;
363364
UnsignedShort m_superweaponRestriction;
364365

@@ -410,12 +411,11 @@ inline void GameLogic::setHeight( Real height ) { m_height = height; }
410411
inline Real GameLogic::getHeight( void ) { return m_height; }
411412
inline UnsignedInt GameLogic::getFrame( void ) { return m_frame; }
412413

413-
inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }
414-
inline void GameLogic::setGameMode( Int mode ) { m_gameMode = mode; }
415-
inline Int GameLogic::getGameMode( void ) { return m_gameMode; }
414+
inline Bool GameLogic::isInGame( void ) { return m_gameMode != GAME_NONE; }
415+
inline GameMode GameLogic::getGameMode( void ) { return m_gameMode; }
416416
inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }
417417
inline Bool GameLogic::isInSkirmishGame( void ) { return (m_gameMode == GAME_SKIRMISH); }
418-
inline Bool GameLogic::isInMultiplayerGame( void ) { return ((m_gameMode == GAME_LAN) || (m_gameMode == GAME_INTERNET)) ; }
418+
inline Bool GameLogic::isInMultiplayerGame( void ) { return (m_gameMode == GAME_LAN) || (m_gameMode == GAME_INTERNET) ; }
419419
inline Bool GameLogic::isInReplayGame( void ) { return (m_gameMode == GAME_REPLAY); }
420420
inline Bool GameLogic::isInInternetGame( void ) { return (m_gameMode == GAME_INTERNET); }
421421
inline Bool GameLogic::isInShellGame( void ) { return (m_gameMode == GAME_SHELL); }

GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void GameStateMap::xfer( Xfer *xfer )
312312
if (currentVersion >= 2)
313313
{
314314
// save the game mode.
315-
Int gameMode = TheGameLogic->getGameMode();
315+
Int gameMode = (Int)TheGameLogic->getGameMode();
316316
xfer->xferInt( &gameMode);
317317
}
318318

@@ -345,7 +345,7 @@ void GameStateMap::xfer( Xfer *xfer )
345345
// get the game mode.
346346
Int gameMode;
347347
xfer->xferInt(&gameMode);
348-
TheGameLogic->setGameMode(gameMode);
348+
TheGameLogic->setGameMode((GameMode)gameMode);
349349
}
350350

351351
} // end else, load

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,13 @@ void GameLogic::deleteLoadScreen( void )
11211121

11221122
} // end deleteLoadScreen
11231123

1124+
// ------------------------------------------------------------------------------------------------
1125+
// ------------------------------------------------------------------------------------------------
1126+
void GameLogic::setGameMode( GameMode mode )
1127+
{
1128+
m_gameMode = mode;
1129+
}
1130+
11241131
// ------------------------------------------------------------------------------------------------
11251132
/** Entry point for starting a new game, the engine is already in clean state at this
11261133
* point and ready to load up with all the data */

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void GameLogic::clearGameData( Bool showScoreScreen )
303303
// ------------------------------------------------------------------------------------------------
304304
/** Prepare for a new game */
305305
// ------------------------------------------------------------------------------------------------
306-
void GameLogic::prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints )
306+
void GameLogic::prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints )
307307
{
308308
//Added By Sadullah Nader
309309
//Fix for loading game scene
@@ -422,7 +422,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
422422
case GameMessage::MSG_NEW_GAME:
423423
{
424424
//DEBUG_ASSERTCRASH(msg->getArgumentCount() == 1 || msg->getArgumentCount() == 2, ("%d arguments to MSG_NEW_GAME", msg->getArgumentCount()));
425-
Int gameMode = msg->getArgument( 0 )->integer;
425+
GameMode gameMode = (GameMode)msg->getArgument( 0 )->integer;
426426
Int rankPoints = 0;
427427
GameDifficulty diff = DIFFICULTY_NORMAL;
428428
if ( msg->getArgumentCount() >= 2 )

0 commit comments

Comments
 (0)