diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 3b691bd6a..8b855b711 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -90,6 +90,7 @@ CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, cl_capfps, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, cl_resumesavegame, true, CVAR_ARCHIVE) ticcmd_t playercmds[MAXPLAYERS]; @@ -102,6 +103,10 @@ int entertic; int oldentertics; int gametic; +extern FString BackupSaveGame; + +void DoLoadGame(const char* name); + //========================================================================== // @@ -137,14 +142,21 @@ static void GameTicker() switch (ga) { case ga_autoloadgame: - // todo: for now just handle the restart case - g_nextmap = currentLevel; - FX_StopAllSounds(); - FX_SetReverb(0); - gi->FreeLevelData(); - C_ClearMessages(); - gameaction = ga_level; - gi->NewGame(g_nextmap, -1); + if (BackupSaveGame.IsNotEmpty() && cl_resumesavegame) + { + DoLoadGame(BackupSaveGame); + } + else + { + g_nextmap = currentLevel; + FX_StopAllSounds(); + FX_SetReverb(0); + gi->FreeLevelData(); + C_ClearMessages(); + gameaction = ga_level; + gi->NewGame(g_nextmap, -1); + BackupSaveGame = ""; + } break; case ga_completed: @@ -178,6 +190,7 @@ static void GameTicker() gi->FreeLevelData(); C_ClearMessages(); gameaction = ga_level; + BackupSaveGame = ""; gi->NewGame(g_nextmap, g_nextskill); break; diff --git a/source/core/menu/savegamemanager.cpp b/source/core/menu/savegamemanager.cpp index 396102c15..a62be3068 100644 --- a/source/core/menu/savegamemanager.cpp +++ b/source/core/menu/savegamemanager.cpp @@ -57,28 +57,35 @@ FSavegameManager savegameManager; +FString BackupSaveGame; -void FSavegameManager::LoadGame(FSaveGameNode* node) +void DoLoadGame(const char* name) { - inputState.ClearAllInput(); - gi->FreeLevelData(); - if (OpenSaveGameForRead(node->Filename)) + if (OpenSaveGameForRead(name)) { - if (gi->LoadGame(node)) + if (gi->LoadGame(nullptr)) { gameaction = ga_level; } else { - I_Error("%s: Failed to load savegame", node->Filename.GetChars()); + I_Error("%s: Failed to load savegame", name); } } else { - I_Error("%s: Failed to open savegame", node->Filename.GetChars()); + I_Error("%s: Failed to open savegame", name); } } +void FSavegameManager::LoadGame(FSaveGameNode* node) +{ + inputState.ClearAllInput(); + gi->FreeLevelData(); + DoLoadGame(node->Filename); + BackupSaveGame = node->Filename; +} + void FSavegameManager::SaveGame(FSaveGameNode* node, bool ok4q, bool forceq) { if (OpenSaveGameForWrite(node->Filename, node->SaveTitle)) @@ -89,6 +96,7 @@ void FSavegameManager::SaveGame(FSaveGameNode* node, bool ok4q, bool forceq) FString desc = node->SaveTitle; NotifyNewSave(fn, desc, ok4q, forceq); Printf(PRINT_NOTIFY, "%s\n", GStrings("GAME SAVED")); + BackupSaveGame = node->Filename; } } }