- implemented reloading from the last saved game, like in GZDoom.

Fixes #352
This commit is contained in:
Christoph Oelckers 2020-09-10 22:45:42 +02:00
parent f829bc96c8
commit 52cbb5c9dc
2 changed files with 36 additions and 15 deletions

View file

@ -90,6 +90,7 @@
CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, r_ticstability, true, 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_capfps, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, cl_resumesavegame, true, CVAR_ARCHIVE)
ticcmd_t playercmds[MAXPLAYERS]; ticcmd_t playercmds[MAXPLAYERS];
@ -102,6 +103,10 @@ int entertic;
int oldentertics; int oldentertics;
int gametic; int gametic;
extern FString BackupSaveGame;
void DoLoadGame(const char* name);
//========================================================================== //==========================================================================
// //
@ -137,14 +142,21 @@ static void GameTicker()
switch (ga) switch (ga)
{ {
case ga_autoloadgame: case ga_autoloadgame:
// todo: for now just handle the restart case if (BackupSaveGame.IsNotEmpty() && cl_resumesavegame)
g_nextmap = currentLevel; {
FX_StopAllSounds(); DoLoadGame(BackupSaveGame);
FX_SetReverb(0); }
gi->FreeLevelData(); else
C_ClearMessages(); {
gameaction = ga_level; g_nextmap = currentLevel;
gi->NewGame(g_nextmap, -1); FX_StopAllSounds();
FX_SetReverb(0);
gi->FreeLevelData();
C_ClearMessages();
gameaction = ga_level;
gi->NewGame(g_nextmap, -1);
BackupSaveGame = "";
}
break; break;
case ga_completed: case ga_completed:
@ -178,6 +190,7 @@ static void GameTicker()
gi->FreeLevelData(); gi->FreeLevelData();
C_ClearMessages(); C_ClearMessages();
gameaction = ga_level; gameaction = ga_level;
BackupSaveGame = "";
gi->NewGame(g_nextmap, g_nextskill); gi->NewGame(g_nextmap, g_nextskill);
break; break;

View file

@ -57,28 +57,35 @@
FSavegameManager savegameManager; FSavegameManager savegameManager;
FString BackupSaveGame;
void FSavegameManager::LoadGame(FSaveGameNode* node) void DoLoadGame(const char* name)
{ {
inputState.ClearAllInput(); if (OpenSaveGameForRead(name))
gi->FreeLevelData();
if (OpenSaveGameForRead(node->Filename))
{ {
if (gi->LoadGame(node)) if (gi->LoadGame(nullptr))
{ {
gameaction = ga_level; gameaction = ga_level;
} }
else else
{ {
I_Error("%s: Failed to load savegame", node->Filename.GetChars()); I_Error("%s: Failed to load savegame", name);
} }
} }
else 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) void FSavegameManager::SaveGame(FSaveGameNode* node, bool ok4q, bool forceq)
{ {
if (OpenSaveGameForWrite(node->Filename, node->SaveTitle)) if (OpenSaveGameForWrite(node->Filename, node->SaveTitle))
@ -89,6 +96,7 @@ void FSavegameManager::SaveGame(FSaveGameNode* node, bool ok4q, bool forceq)
FString desc = node->SaveTitle; FString desc = node->SaveTitle;
NotifyNewSave(fn, desc, ok4q, forceq); NotifyNewSave(fn, desc, ok4q, forceq);
Printf(PRINT_NOTIFY, "%s\n", GStrings("GAME SAVED")); Printf(PRINT_NOTIFY, "%s\n", GStrings("GAME SAVED"));
BackupSaveGame = node->Filename;
} }
} }
} }