From 6e060c2e836694f178e04521e971715cf3ad50c9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 14 May 2023 09:39:13 +0200 Subject: [PATCH] Revert "- Tidy up autosaving for all the games." This reverts commit 10445635cfba78e5ae86a5c063f680d250296601. Contrary to what the reverted commit states, it is absolutely essential to have this delay. Duke and Blood initialize a lot of things in their first tick that are necessary before the world is stable to save. --- source/core/mainloop.cpp | 8 +++++++- source/games/blood/src/blood.cpp | 1 + source/games/duke/src/gameloop.cpp | 1 + source/games/exhumed/src/exhumed.cpp | 3 ++- source/games/sw/src/d_menu.cpp | 2 +- source/games/sw/src/player.cpp | 2 ++ 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 6302cbb87..880a30de8 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -146,9 +146,11 @@ void G_BuildTiccmd(ticcmd_t* cmd) // // //========================================================================== +bool newGameStarted; void NewGame(MapRecord* map, int skill, bool ns = false) { + newGameStarted = true; ShowIntermission(nullptr, map, nullptr, [=](bool) { gi->NewGame(map, skill, ns); gameaction = ga_level; @@ -203,7 +205,6 @@ static void GameTicker() gameaction = ga_level; gi->NextLevel(g_nextmap, g_nextskill); ResetStatusBar(); - M_Autosave(); break; case ga_newgame: @@ -258,6 +259,11 @@ static void GameTicker() G_DoLoadGame(); break; + case ga_autosave: + if (gamestate == GS_LEVEL && !newGameStarted) M_Autosave(); + newGameStarted = false; + break; + case ga_level: Net_ClearFifo(); inputState.ClearAllInput(); diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index ab327f99a..f2145c8a9 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -469,6 +469,7 @@ void GameInterface::Ticker() gFrameCount++; PlayClock += kTicsPerFrame; + if (PlayClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. for (int i = 0; i < 8; i++) { diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 8147380ff..4dc73dd31 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -105,6 +105,7 @@ void GameInterface::Ticker() r_NoInterpolate = false; PlayClock+= 4; // This must be at the end of this block so that the first tic receives a value of 0! + if (PlayClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. } else r_NoInterpolate = true; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 21fc2ca43..b68a57bce 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -334,6 +334,7 @@ void GameInterface::Ticker() GameMove(); PlayClock += 4; + if (PlayClock == 8) gameaction = ga_autosave; // let the game run for 1 frame before saving. r_NoInterpolate = false; } else @@ -514,7 +515,7 @@ void EraseScreen(int nVal) bool GameInterface::CanSave() { - return !bRecord && !bPlayback && !bInDemo && nTotalPlayers == 1 && nFreeze == 0; + return gamestate == GS_LEVEL && !bRecord && !bPlayback && !bInDemo && nTotalPlayers == 1 && nFreeze == 0; } ::GameStats GameInterface::getStats() diff --git a/source/games/sw/src/d_menu.cpp b/source/games/sw/src/d_menu.cpp index 7db930af6..3b0df124e 100644 --- a/source/games/sw/src/d_menu.cpp +++ b/source/games/sw/src/d_menu.cpp @@ -86,7 +86,7 @@ void GameInterface::MenuSound(EMenuSounds snd) bool GameInterface::CanSave() { - return (!CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !(Player[myconnectindex].Flags & PF_DEAD)); + return (gamestate == GS_LEVEL && !CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !(Player[myconnectindex].Flags & PF_DEAD)); } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 074be9be5..d936ebe53 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6892,6 +6892,8 @@ void domovethings(void) return; } + if (PlayClock == synctics) gameaction = ga_autosave; // let the game run for 1 frame before saving. + thinktime.Reset(); thinktime.Clock();