- 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, 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,7 +142,12 @@ static void GameTicker()
switch (ga)
{
case ga_autoloadgame:
// todo: for now just handle the restart case
if (BackupSaveGame.IsNotEmpty() && cl_resumesavegame)
{
DoLoadGame(BackupSaveGame);
}
else
{
g_nextmap = currentLevel;
FX_StopAllSounds();
FX_SetReverb(0);
@ -145,6 +155,8 @@ static void GameTicker()
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;

View file

@ -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;
}
}
}