- 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.
This commit is contained in:
Christoph Oelckers 2021-12-07 00:12:04 +01:00
parent 8a2385dd89
commit ca10495d7c
5 changed files with 19 additions and 24 deletions

View file

@ -194,20 +194,8 @@ static void GameTicker()
case ga_completed: case ga_completed:
FX_StopAllSounds(); FX_StopAllSounds();
FX_SetReverb(0); FX_SetReverb(0);
if (g_nextmap == currentLevel) gi->LevelCompleted(g_nextmap, g_nextskill);
{ assert(gameaction != ga_nothing);
// 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);
}
break; break;
case ga_nextlevel: case ga_nextlevel:

View file

@ -188,6 +188,12 @@ void ShowScoreboard(int numplayers, const CompletionFunc& completion_)
void ShowIntermission(MapRecord* fromMap, MapRecord* toMap, SummaryInfo* info, 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; bool bossexit = g_bossexit;
g_bossexit = false; g_bossexit = false;

View file

@ -154,7 +154,6 @@ void StartLevel(MapRecord* level, bool newgame)
if (!level) return; if (!level) return;
gFrameCount = 0; gFrameCount = 0;
PlayClock = 0; PlayClock = 0;
EndLevel();
inputState.ClearAllInput(); inputState.ClearAllInput();
currentLevel = level; currentLevel = level;
@ -172,14 +171,6 @@ void StartLevel(MapRecord* level, bool newgame)
gRedFlagDropped = false; gRedFlagDropped = false;
} }
#endif #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(); //drawLoadingScreen();
BloodSpawnSpriteDef sprites; BloodSpawnSpriteDef sprites;
dbLoadMap(currentLevel->fileName, (int*)&startpos.x, (int*)&startpos.y, (int*)&startpos.z, &startang, &startsector, nullptr, sprites); dbLoadMap(currentLevel->fileName, (int*)&startpos.x, (int*)&startpos.y, (int*)&startpos.z, &startang, &startsector, nullptr, sprites);

View file

@ -80,7 +80,7 @@ void QuitGame(void);
void PreloadCache(void); void PreloadCache(void);
void ProcessFrame(void); void ProcessFrame(void);
void ScanINIFiles(void); void ScanINIFiles(void);
void EndLevel(); void EndLevel(bool);
struct MIRROR struct MIRROR
{ {

View file

@ -38,6 +38,16 @@ BEGIN_BLD_NS
void GameInterface::LevelCompleted(MapRecord *map, int skill) 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(); EndLevel();
Mus_Stop(); Mus_Stop();