Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Generals/Code/GameEngine/Include/GameLogic/GameLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ class GameLogic : public SubsystemInterface, public Snapshot
ObjectID allocateObjectID(); ///< Returns a new unique object id

// super hack
void startNewGame( Bool saveGame );
void startNewGame( Bool loadSaveGame );
void loadMapINI( AsciiString mapName );

void updateLoadProgress( Int progress );
void deleteLoadScreen();

void setGameLoading( Bool loading );
//Kris: Cut setGameLoading() and replaced with setLoadingMap() and setLoadingSave() -- reason: nomenclature
//void setGameLoading( Bool loading ) { m_loadingScene = loading; }
void setLoadingMap( Bool loading ) { m_loadingMap = loading; }
void setLoadingSave( Bool loading ) { m_loadingSave = loading; }
void setClearingGameData( Bool clearing ) { m_clearingGameData = clearing; }

void setGameMode( GameMode mode );
GameMode getGameMode();

Expand All @@ -174,7 +179,12 @@ class GameLogic : public SubsystemInterface, public Snapshot

static Bool isInInteractiveGame(GameMode mode) { return mode != GAME_NONE && mode != GAME_SHELL; }

Bool isLoadingGame();
//Kris: Cut isLoadingGame() and replaced with isLoadingMap() and isLoadingSave() -- reason: nomenclature
//Bool isLoadingGame() const { return m_loadingScene; } // This is the old function that isn't very clear on it's definition.
Bool isLoadingMap() const { return m_loadingMap; } // Whenever a map is in the process of loading.
Bool isLoadingSave() const { return m_loadingSave; } // Whenever a saved game is in the process of loading.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoadingSave() always returns FALSE in Generals

setLoadingSave() is never called anywhere in the Generals/ codebase, so isLoadingSave() will always return FALSE here — making this API misleading and effectively a dead getter.

The GeneralsMD counterpart correctly calls the setter in GameStateMap::xfer():

// GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp : 247
if( xfer->getXferMode() == XFER_LOAD )
{
    TheGameLogic->setLoadingSave( TRUE );
}
// ... later at line 441:
TheGameLogic->setLoadingSave( FALSE );

The equivalent Generals/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp::xfer() has no such calls. Since startNewGame(TRUE) is called from that same function, the save-game load path exists and setLoadingSave() should be called there too — otherwise any future caller of isLoadingSave() in Generals will silently get FALSE even during an active save-game load.

Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Include/GameLogic/GameLogic.h
Line: 185

Comment:
**`isLoadingSave()` always returns FALSE in Generals**

`setLoadingSave()` is never called anywhere in the `Generals/` codebase, so `isLoadingSave()` will always return `FALSE` here — making this API misleading and effectively a dead getter.

The GeneralsMD counterpart correctly calls the setter in `GameStateMap::xfer()`:
```cpp
// GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp : 247
if( xfer->getXferMode() == XFER_LOAD )
{
    TheGameLogic->setLoadingSave( TRUE );
}
// ... later at line 441:
TheGameLogic->setLoadingSave( FALSE );
```

The equivalent `Generals/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp::xfer()` has no such calls. Since `startNewGame(TRUE)` is called from that same function, the save-game load path exists and `setLoadingSave()` should be called there too — otherwise any future caller of `isLoadingSave()` in Generals will silently get `FALSE` even during an active save-game load.

How can I resolve this? If you propose a fix, please make it concise.

Bool isClearingGameData() const { return m_clearingGameData; }

void enableScoring(Bool score) { m_isScoringEnabled = score; }
Bool isScoringEnabled() const { return m_isScoringEnabled; }

Expand Down Expand Up @@ -292,7 +302,10 @@ class GameLogic : public SubsystemInterface, public Snapshot
std::map<Int, UnsignedInt> m_cachedCRCs; ///< CRCs we've seen this frame
Bool m_shouldValidateCRCs; ///< Should we validate CRCs this frame?
//-----------------------------------------------------------------------------------------------
Bool m_loadingScene;
//Bool m_loadingScene;
Bool m_loadingMap;
Bool m_loadingSave;
Bool m_clearingGameData;

Bool m_isInUpdate;
Bool m_hasUpdated;
Expand Down Expand Up @@ -398,8 +411,6 @@ inline Bool GameLogic::isInInteractiveGame() const { return isInInteractiveGame(
inline Bool GameLogic::isInReplayGame() { return (m_gameMode == GAME_REPLAY); }
inline Bool GameLogic::isInInternetGame() { return (m_gameMode == GAME_INTERNET); }
inline Bool GameLogic::isInShellGame() { return (m_gameMode == GAME_SHELL); }
//Check for loading scene
inline Bool GameLogic::isLoadingGame(){ return m_loadingScene;}

inline Object* GameLogic::findObjectByID( ObjectID id )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void UpdateDiplomacyBriefingText(AsciiString newText, Bool clear)
void ShowDiplomacy( Bool immediate )
{
if (!TheInGameUI->getInputEnabled() || TheGameLogic->isIntroMoviePlaying() ||
TheGameLogic->isLoadingGame())
TheGameLogic->isLoadingMap())
return;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void HideQuitMenu()
//-------------------------------------------------------------------------------------------------
void ToggleQuitMenu()
{
if (TheGameLogic->isIntroMoviePlaying() || TheGameLogic->isLoadingGame() ||TheScriptEngine->isGameEnding())
if (TheGameLogic->isIntroMoviePlaying() || TheGameLogic->isLoadingMap() ||TheScriptEngine->isGameEnding())
return;

// BGC- If we are currently in the disconnect screen, don't let the quit menu come up.
Expand Down
40 changes: 21 additions & 19 deletions Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ GameLogic::GameLogic()
#ifdef DUMP_PERF_STATS
m_overallFailedPathfinds = 0;
#endif

m_loadingMap = FALSE;
m_loadingSave = FALSE;
m_clearingGameData = FALSE;
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -933,11 +937,6 @@ void GameLogic::deleteLoadScreen()

}

void GameLogic::setGameLoading( Bool loading )
{
m_loadingScene = loading;
}

// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void GameLogic::updateDisplayBusyState()
Expand All @@ -964,7 +963,7 @@ void GameLogic::setGameMode( GameMode mode )
/** Entry point for starting a new game, the engine is already in clean state at this
* point and ready to load up with all the data */
// ------------------------------------------------------------------------------------------------
void GameLogic::startNewGame( Bool saveGame )
void GameLogic::startNewGame( Bool loadingSaveGame )
{

#ifdef DUMP_PERF_STATS
Expand All @@ -984,7 +983,9 @@ void GameLogic::startNewGame( Bool saveGame )
CRCDebugStartNewGame();
#endif

if( saveGame == FALSE )
setLoadingMap( TRUE );

if( loadingSaveGame == FALSE )
{

// record pristine map name when we're loading from the map (not a save game)
Expand Down Expand Up @@ -1015,7 +1016,7 @@ void GameLogic::startNewGame( Bool saveGame )
deleteInstance(m_background);
m_background = nullptr;
}
m_loadScreen = getLoadScreen( saveGame );
m_loadScreen = getLoadScreen( loadingSaveGame );
if(m_loadScreen)
{
TheWritableGlobalData->m_loadScreenRender = TRUE; ///< mark it so only a few select things are rendered during load
Expand All @@ -1038,7 +1039,7 @@ void GameLogic::startNewGame( Bool saveGame )
// for save games, we read this value out of the save game file and it is important
// that we preserve it as we load and execute the game
//
if( saveGame == FALSE )
if( loadingSaveGame == FALSE )
m_nextObjID = (ObjectID)1;

TheWritableGlobalData->m_loadScreenRender = TRUE; ///< mark it so only a few select things are rendered during load
Expand Down Expand Up @@ -1079,7 +1080,7 @@ void GameLogic::startNewGame( Bool saveGame )
for (Int i=0; i<MAX_SLOTS; ++i)
{
GameSlot *slot = TheGameInfo->getSlot(i);
if (!saveGame) {
if (!loadingSaveGame) {
slot->saveOffOriginalInfo();
}
if (slot->isAI())
Expand All @@ -1104,7 +1105,7 @@ void GameLogic::startNewGame( Bool saveGame )
// Get the m_loadScreen for this kind of game
if(!m_loadScreen && !(TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_SIMULATION_PLAYBACK))
{
m_loadScreen = getLoadScreen( saveGame );
m_loadScreen = getLoadScreen( loadingSaveGame );
if(m_loadScreen && !TheGlobalData->m_headless)
{
TheMouse->setVisibility(FALSE);
Expand Down Expand Up @@ -1510,7 +1511,7 @@ void GameLogic::startNewGame( Bool saveGame )
updateLoadProgress(LOAD_PROGRESS_POST_GHOST_OBJECT_MANAGER_RESET);

// update the terrain logic now that all is loaded
TheTerrainLogic->newMap( saveGame );
TheTerrainLogic->newMap( loadingSaveGame );

// update the loadscreen
updateLoadProgress(LOAD_PROGRESS_POST_TERRAIN_LOGIC_NEW_MAP);
Expand Down Expand Up @@ -1613,7 +1614,7 @@ void GameLogic::startNewGame( Bool saveGame )
DEBUG_LOG(("%s", Buf));
#endif

if( saveGame == FALSE )
if( loadingSaveGame == FALSE )
{
Int progressCount = LOAD_PROGRESS_LOOP_ALL_THE_FREAKN_OBJECTS;
Int timer = timeGetTime();
Expand Down Expand Up @@ -1716,7 +1717,7 @@ void GameLogic::startNewGame( Bool saveGame )
#endif

// place initial network buildings/units
if (TheGameInfo && !saveGame)
if (TheGameInfo && !loadingSaveGame)
{
Int progressCount = LOAD_PROGRESS_LOOP_INITIAL_NETWORK_BUILDINGS;
for (int i=0; i<MAX_SLOTS; ++i)
Expand Down Expand Up @@ -1852,11 +1853,11 @@ void GameLogic::startNewGame( Bool saveGame )


// final step, run newMap for all players
if( saveGame == FALSE )
if( loadingSaveGame == FALSE )
ThePlayerList->newMap();

// reset all the skill points in a single player game
if(saveGame == FALSE && isInSinglePlayerGame())
if(loadingSaveGame == FALSE && isInSinglePlayerGame())
{
for (Int i=0; i<MAX_PLAYER_COUNT; ++i)
{
Expand Down Expand Up @@ -1889,7 +1890,7 @@ void GameLogic::startNewGame( Bool saveGame )
}

// if we're in a load game, don't fade yet
if(saveGame == FALSE && TheTransitionHandler != nullptr && m_loadScreen)
if(loadingSaveGame == FALSE && TheTransitionHandler != nullptr && m_loadScreen)
{
TheTransitionHandler->setGroup("FadeWholeScreen");
while(!TheTransitionHandler->isFinished())
Expand All @@ -1915,7 +1916,7 @@ void GameLogic::startNewGame( Bool saveGame )
// have more work to do and the load screen will be deleted elsewhere after
// we're all done with the load game progress
//
if( saveGame == FALSE )
if( loadingSaveGame == FALSE )
*/
deleteLoadScreen();

Expand Down Expand Up @@ -2048,7 +2049,8 @@ void GameLogic::startNewGame( Bool saveGame )
}

//ReAllows quit menu to work during loading scene
setGameLoading(FALSE);
//setGameLoading(FALSE);
setLoadingMap( FALSE );

#ifdef DUMP_PERF_STATS
GetPrecisionTimer(&endTime64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ void GameLogic::clearGameData( Bool showScoreScreen )
return;
}

setClearingGameData( TRUE );

// m_background = TheWindowManager->winCreateLayout("Menus/BlankWindow.wnd");
// DEBUG_ASSERTCRASH(m_background,("We Couldn't Load Menus/BlankWindow.wnd"));
// m_background->hide(FALSE);
Expand Down Expand Up @@ -292,14 +294,18 @@ void GameLogic::clearGameData( Bool showScoreScreen )
m_background = nullptr;
}

setClearingGameData( FALSE );

}

// ------------------------------------------------------------------------------------------------
/** Prepare for a new game */
// ------------------------------------------------------------------------------------------------
void GameLogic::prepareNewGame( GameMode gameMode, GameDifficulty diff, Int rankPoints )
{
setGameLoading(TRUE);
//Kris: Commented this out, but leaving it around incase it bites us later. I cleaned up the
// nomenclature. Look for setLoadingMap() and setLoadingSave()
//setGameLoading(TRUE);

TheScriptEngine->setGlobalDifficulty(diff);

Expand Down
Loading