Output replays

This commit is contained in:
Miloslav Ciz 2025-01-14 13:40:22 +01:00
parent 17c182f474
commit 2dfad249ad
3 changed files with 100 additions and 18 deletions

View file

@ -145,6 +145,52 @@ void LCR_replayInitPlaying(void)
LCR_replay.currentFrame = 0;
}
char _LCR_hexDigit(int i)
{
return i < 10 ? '0' + i : ('a' - 10 + i);
}
/**
Outputs current replay using provided character printing function. The string
will be zero terminated.
*/
void LCR_replayOutputStr(void (*printChar)(char))
{
LCR_LOG1("outputting replay");
const char *s = LCR_currentMap.name;
while (*s)
{
printChar(*s);
s++;
}
printChar(';');
uint32_t hash = LCR_currentMap.hash;
for (int i = 0; i < 8; ++i)
{
printChar(_LCR_hexDigit(hash % 16));
hash /= 16;
}
for (int i = 0; i < LCR_replay.eventCount; ++i)
{
uint16_t e = LCR_replay.events[i];
printChar(' ');
for (int j = 0; j < 4; ++j)
{
printChar(_LCR_hexDigit(e % 16));
e /= 16;
}
}
printChar('\n');
}
/**
During playing of a replay returns the next input and shifts to next frame.
*/