Add replay validation

This commit is contained in:
Miloslav Ciz 2025-06-11 22:25:29 +02:00
parent f0d8521e90
commit 57097c57bb
3 changed files with 78 additions and 20 deletions

18
game.h
View file

@ -853,8 +853,8 @@ uint8_t LCR_gameLoadMap(unsigned int mapIndex)
/**
Loads replay by its index, returns index of a map for the replay (and the map
will be loaded as with LCR_mapLoadFromStr) or -1 if the map wasn't found or -2
if the replay couldn't be loaded. This function potentially reloads current
map!
if the replay couldn't be loaded or -3 if the replay is invalid. This function
potentially reloads current map!
*/
unsigned int LCR_gameLoadReplay(unsigned int replayIndex)
{
@ -900,7 +900,7 @@ unsigned int LCR_gameLoadReplay(unsigned int replayIndex)
LCR_LOG2("map name hash matches");
if (LCR_gameLoadMap(mapIndex) && mapHash == LCR_currentMap.hash)
return mapIndex;
return LCR_replayValidate() ? mapIndex : -3;
else
{
LCR_LOG2("bad map");
@ -1243,7 +1243,7 @@ void LCR_gameDraw3DView(void)
LCR_GameUnit carTransform[6];
LCR_GameUnit physicsInterpolationParam =
!(LCR_racing.playingReplay && LCR_replayHasFinished()) ?
!(LCR_racing.replay.on && LCR_replayHasFinished()) ?
LCR_GAME_UNIT -
((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT)
/ LCR_RACING_TICK_MS
@ -1388,7 +1388,7 @@ void LCR_gameHandleInput(void)
LCR_currentMap.targetTime = LCR_game.runTime;
}
LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active);
LCR_gameResetRun(LCR_racing.replay.on,LCR_game.ghost.active);
}
}
else if (LCR_game.state == LCR_GAME_STATE_RUN_STARTING)
@ -1448,7 +1448,7 @@ void LCR_gameHandleInput(void)
LCR_rendererMoveCamera(offsets,offsets + 3);
}
else if (LCR_game.keyStates[LCR_KEY_A] == 1)
LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active);
LCR_gameResetRun(LCR_racing.replay.on,LCR_game.ghost.active);
}
else // LCR_GAME_STATE_MENU
{
@ -1549,7 +1549,7 @@ void LCR_gameHandleInput(void)
case 3:
if (LCR_game.statePrev == LCR_GAME_STATE_RUN_FINISHED &&
!LCR_racing.playingReplay)
!LCR_racing.replay.on)
LCR_gameSaveReplay();
else
LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_FAIL]);
@ -1719,12 +1719,12 @@ uint8_t LCR_gameStep(uint32_t time)
LCR_LOG1_NUM(LCR_game.runTime);
if (LCR_game.runTime <= LCR_currentMap.targetTime &&
!LCR_racing.playingReplay)
!LCR_racing.replay.on)
{
LCR_gameSaveReplay();
if (!LCR_game.mapBeaten && !LCR_game.ghost.active &&
!LCR_racing.playingReplay)
!LCR_racing.replay.on)
{
LCR_LOG1("map beaten");
LCR_game.mapBeaten = 1;