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

4
data
View file

@ -117,3 +117,7 @@ details
:-6323 :f212
:!612 :f212 :+W1V :+21Q :+D13
#RLC4;00LC4;46e97a3d 0000974:0011:0119:0131:0173:0041:00a9:0031:0383:0021:00a9:0021:02c3:0021:0129:0041:0049:0031:0069:0031:0029:00d1:0073:0051:0103:0021:00d3:0011:0293:0021:0083:0031:0079:0041:0083:0031:01e9:0081:0083:0021:0049:00c1:0063:00e1:0043:0051:0049:00b1:0043:00a1:0049:0081:00a3:0031:0049:0031:0073:0041:0073:0031:0033:0031:0073:0031:0059:0041:00c9:0031:00e3:0051:0059:0041:0039:0031:0059:0041:0039:0021:0069:0031:0039:00a1:0043:0071:0049:0061:0010:00d4:0036:0054:005c:0044:00e0:0041:00b0:0054:0160:0031:0059:0091:00c0:0062:0091:00b3:0071:00c9:0041:0099:0041:0089:0041:0303:0041:0053:0031
#BLC4;
#RLCtiny1;00LCtiny1;7e39e006 0000387:0251:02b9:0031:0169:0031:0149:0061:0059:0051:0019:0031:0099:0021:00d3:0041:0073:0041:0073:00a1:0033:0027:0016:0042:0046:00a2:00a3:0082:0073:0032:0033:0052:0043:0021:00f9:0031:0109:0011:00b5:0021:0039:0041:0139:0021:0109:0031:00c9:0011:0053:0031
#BLCtiny1;

4
game.h
View file

@ -574,8 +574,8 @@ void _LCR_gamePrepareGhost(void)
while (1)
{
if (LCR_racing.tick % (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch)
== 0 || LCR_replayHasFinished())
if ((LCR_racing.tick % (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch)
== 0) || LCR_replayHasFinished())
{
LCR_racingGetCarTransform(carTransform,carTransform + 3,
LCR_GAME_UNIT / 2);

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