Fix replay bug

This commit is contained in:
Miloslav Ciz 2025-03-31 20:10:15 +02:00
parent 1454ae446e
commit 50c03623a4
3 changed files with 22 additions and 18 deletions

View file

@ -317,13 +317,28 @@ int LCR_replayLoadFromStr(char (*nextChar)(void),
return 1;
}
int LCR_replayHasFinished(void)
{
if (LCR_racing.replay.currentEvent == LCR_racing.replay.eventCount)
{
uint32_t totalTime = LCR_racing.replay.currentFrame;
for (int i = 0; i < LCR_racing.replay.eventCount; ++i)
totalTime += LCR_racing.replay.events[i] >> 4;
return totalTime >= LCR_racing.replay.achievedTime;
}
return LCR_racing.replay.currentEvent > LCR_racing.replay.eventCount;
}
/**
When playing back a replay this function returns the next recorded input and
shifts to the next frame.
*/
uint8_t LCR_replayGetNextInput(void)
{
if (LCR_racing.replay.currentEvent >= LCR_racing.replay.eventCount)
if (LCR_replayHasFinished())
{
LCR_racing.replay.currentFrame++; // has to be here
return 0;
@ -342,21 +357,6 @@ uint8_t LCR_replayGetNextInput(void)
(LCR_racing.replay.events[LCR_racing.replay.currentEvent - 1] & 0x0f) : 0;
}
int LCR_replayHasFinished(void)
{
if (LCR_racing.replay.currentEvent == LCR_racing.replay.eventCount)
{
uint32_t totalTime = LCR_racing.replay.currentFrame;
for (int i = 0; i < LCR_racing.replay.eventCount; ++i)
totalTime += LCR_racing.replay.events[i] >> 4;
return totalTime >= LCR_racing.replay.achievedTime;
}
return LCR_racing.replay.currentEvent > LCR_racing.replay.eventCount;
}
/**
Records another input event into a replay. Returns 1 on success, or 0 if the
event couldn't be recorded. The event is only added if necessary, i.e. this