From ca10495d7cf8643998c5686d23f56e5ea418dc16 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 7 Dec 2021 00:12:04 +0100 Subject: [PATCH] - Blood: back up player state before ending the level, not just before loading the new one. The latter is too late, the player's actor data may already be stale and invalid here. --- source/core/mainloop.cpp | 16 ++-------------- source/core/screenjob.cpp | 6 ++++++ source/games/blood/src/blood.cpp | 9 --------- source/games/blood/src/blood.h | 2 +- source/games/blood/src/endgame.cpp | 10 ++++++++++ 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 8e3da4832..0e9f3a651 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -194,20 +194,8 @@ static void GameTicker() case ga_completed: FX_StopAllSounds(); FX_SetReverb(0); - if (g_nextmap == currentLevel) - { - // if the same level is restarted, skip any progression stuff like summary screens or cutscenes. - gi->FreeLevelData(); - gameaction = ga_level; - gi->NextLevel(g_nextmap, g_nextskill); - ResetStatusBar(); - Net_ClearFifo(); - } - else - { - gi->LevelCompleted(g_nextmap, g_nextskill); - assert(gameaction != ga_nothing); - } + gi->LevelCompleted(g_nextmap, g_nextskill); + assert(gameaction != ga_nothing); break; case ga_nextlevel: diff --git a/source/core/screenjob.cpp b/source/core/screenjob.cpp index 0225552b6..60357b366 100644 --- a/source/core/screenjob.cpp +++ b/source/core/screenjob.cpp @@ -188,6 +188,12 @@ void ShowScoreboard(int numplayers, const CompletionFunc& completion_) void ShowIntermission(MapRecord* fromMap, MapRecord* toMap, SummaryInfo* info, CompletionFunc completion_) { + if (fromMap == toMap) + { + // don't show intermission when restarting the same level. + completion_(false); + return; + } bool bossexit = g_bossexit; g_bossexit = false; diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 714bf3cfb..ad55edae7 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -154,7 +154,6 @@ void StartLevel(MapRecord* level, bool newgame) if (!level) return; gFrameCount = 0; PlayClock = 0; - EndLevel(); inputState.ClearAllInput(); currentLevel = level; @@ -172,14 +171,6 @@ void StartLevel(MapRecord* level, bool newgame) gRedFlagDropped = false; } #endif - if (!newgame) - { - for (int i = connecthead; i >= 0; i = connectpoint2[i]) - { - memcpy(&gPlayerTemp[i], &gPlayer[i], sizeof(PLAYER)); - gHealthTemp[i] = gPlayer[i].actor->x().health; - } - } //drawLoadingScreen(); BloodSpawnSpriteDef sprites; dbLoadMap(currentLevel->fileName, (int*)&startpos.x, (int*)&startpos.y, (int*)&startpos.z, &startang, &startsector, nullptr, sprites); diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 63fad4aac..d83ab7f82 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -80,7 +80,7 @@ void QuitGame(void); void PreloadCache(void); void ProcessFrame(void); void ScanINIFiles(void); -void EndLevel(); +void EndLevel(bool); struct MIRROR { diff --git a/source/games/blood/src/endgame.cpp b/source/games/blood/src/endgame.cpp index 193b78e8f..01b0ea57b 100644 --- a/source/games/blood/src/endgame.cpp +++ b/source/games/blood/src/endgame.cpp @@ -38,6 +38,16 @@ BEGIN_BLD_NS void GameInterface::LevelCompleted(MapRecord *map, int skill) { + // Save the player state before taking down anything. + for (int i = connecthead; i >= 0; i = connectpoint2[i]) + { + if (gPlayer[i].actor) + { + memcpy(&gPlayerTemp[i], &gPlayer[i], sizeof(PLAYER)); + gHealthTemp[i] = gPlayer[i].actor->x().health; + } + } + EndLevel(); Mus_Stop();