Add physics version
This commit is contained in:
parent
ad8baef113
commit
5c8e4c4c2b
3 changed files with 44 additions and 8 deletions
40
racing.h
40
racing.h
|
@ -17,9 +17,17 @@
|
|||
because the offset is too big (input didn't change for more than 2^12
|
||||
frames), there must simply be inserted an extra word that just copies the
|
||||
current input state.
|
||||
- Replay text format: first there is the name of the map terminated by ';',
|
||||
then hexadecimal hash of the map follows (exactly 8 characters), then
|
||||
blank character follows, then achieved time as a series of decimal digits
|
||||
- Physics engine version: LCR_RACING_VERSION1 and LCR_RACING_VERSION2 define
|
||||
a two-character version string of this module that determines compatibility
|
||||
of replays. Whenever a change is made to this module that changes the
|
||||
behavior of physics, the version string must be changed because replays
|
||||
will stop being compatible. It's still possible to make other changes to
|
||||
this module (such as optimizations or comments) without having to change
|
||||
physics version.
|
||||
- Replay text format: first there are two characters saying the physics
|
||||
engine version, then immediately the name of the map terminated by ';', then
|
||||
hexadecimal hash of the map follows (exactly 8 characters), then blank
|
||||
character follows, then achieved time as a series of decimal digits
|
||||
expressing the physics frame at which the run finished, then the replay
|
||||
data, i.e. the series of 16 bit words in hexadecimal, each preceded by ':'.
|
||||
The events (but nothing else) may otherwise be preceeded or followed by
|
||||
|
@ -30,6 +38,9 @@
|
|||
|
||||
typedef int32_t LCR_GameUnit; ///< abstract game unit
|
||||
|
||||
#define LCR_RACING_VERSION1 '0' ///< first part of physics eng. version
|
||||
#define LCR_RACING_VERSION2 '0' ///< second part of physics eng. version
|
||||
|
||||
#define LCR_GAME_UNIT 2048 ///< length of map square in LCR_GameUnits
|
||||
|
||||
#define LCR_RACING_INPUT_FORW 0x01
|
||||
|
@ -174,6 +185,9 @@ void LCR_replayOutputStr(void (*printChar)(char))
|
|||
|
||||
const char *s = LCR_currentMap.name;
|
||||
|
||||
printChar(LCR_RACING_VERSION1);
|
||||
printChar(LCR_RACING_VERSION2);
|
||||
|
||||
while (*s)
|
||||
{
|
||||
printChar(*s);
|
||||
|
@ -225,11 +239,23 @@ void LCR_replayOutputStr(void (*printChar)(char))
|
|||
int LCR_replayLoadFromStr(char (*nextChar)(void),
|
||||
uint32_t *mapHash, uint16_t *nameHash)
|
||||
{
|
||||
char c = ' ';
|
||||
char c;
|
||||
|
||||
LCR_racing.replay.eventCount = 0;
|
||||
LCR_racing.replay.achievedTime = 0;
|
||||
|
||||
// has to be like this to force correct evaluation order:
|
||||
c = nextChar() == LCR_RACING_VERSION1;
|
||||
c |= (nextChar() == LCR_RACING_VERSION2) << 1;
|
||||
|
||||
if (c != 3)
|
||||
{
|
||||
LCR_LOG1("wrong physics version");
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = ' ';
|
||||
|
||||
if (nameHash)
|
||||
*nameHash = _LCR_simpleStrHash(nextChar,';');
|
||||
else
|
||||
|
@ -243,7 +269,10 @@ int LCR_replayLoadFromStr(char (*nextChar)(void),
|
|||
c = nextChar();
|
||||
|
||||
if (_LCR_hexDigitVal(c) < 0)
|
||||
{
|
||||
LCR_LOG1("wrong hash");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mapHash)
|
||||
*mapHash = ((*mapHash) << 4) | _LCR_hexDigitVal(c);
|
||||
|
@ -275,7 +304,10 @@ int LCR_replayLoadFromStr(char (*nextChar)(void),
|
|||
break;
|
||||
|
||||
if (LCR_racing.replay.eventCount >= LCR_SETTING_REPLAY_MAX_SIZE)
|
||||
{
|
||||
LCR_LOG1("replay too big");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LCR_racing.replay.events[LCR_racing.replay.eventCount] = e;
|
||||
LCR_racing.replay.eventCount++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue