Update readme

This commit is contained in:
Miloslav Ciz 2025-06-18 02:02:30 +02:00
parent aab53fc11a
commit 822375ff7d
6 changed files with 178 additions and 36 deletions

100
game.h
View file

@ -365,6 +365,7 @@ struct
unsigned int itemsTotal;
} dataFile;
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
#define LCR_GHOST_SAMPLE_SIZE 5
struct
{
@ -377,6 +378,7 @@ struct
allow ghosts for even long replays. */
int16_t offset[3]; ///< Small correcting position offset.
} ghost;
#endif
#ifdef LCR_FPS_GET_MS
uint16_t renderFrameMS;
@ -498,7 +500,10 @@ void LCR_gameResetRun(uint8_t replay, uint8_t ghost)
LCR_rendererLoadMapChunks();
}
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
LCR_game.ghost.active = ghost;
#endif
LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING);
LCR_game.runTime = 0;
}
@ -506,6 +511,7 @@ void LCR_gameResetRun(uint8_t replay, uint8_t ghost)
void LCR_gameGetNthGhostSample(unsigned int n,
LCR_GameUnit position[3], LCR_GameUnit rotation[3])
{
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
n *= LCR_GHOST_SAMPLE_SIZE;
position[0] = LCR_game.ghost.samples[n];
@ -538,11 +544,20 @@ void LCR_gameGetNthGhostSample(unsigned int n,
rotation[i] = (rotation[i] * LCR_GAME_UNIT) / 16;
}
#else
for (int i = 0; i < 3; ++i)
{
position[i] = 0;
rotation[i] = 0;
}
#endif
}
void LCR_gameGhostGetTransform(uint32_t frame,
LCR_GameUnit position[3], LCR_GameUnit rotation[3])
{
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
int n = ((frame >> LCR_game.ghost.stretch) / LCR_SETTING_GHOST_STEP);
LCR_gameGetNthGhostSample(n,position,rotation);
@ -575,6 +590,13 @@ void LCR_gameGhostGetTransform(uint32_t frame,
/ LCR_SETTING_GHOST_STEP)) % LCR_GAME_UNIT;
}
}
#else
for (int i = 0; i < 3; ++i)
{
position[i] = 0;
rotation[i] = 0;
}
#endif
}
/**
@ -583,6 +605,7 @@ void LCR_gameGhostGetTransform(uint32_t frame,
*/
void _LCR_gamePrepareGhost(void)
{
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0 && LCR_SETTING_REPLAY_MAX_SIZE != 0
LCR_GameUnit carTransform[6];
LCR_LOG1("preparing ghost");
@ -658,6 +681,7 @@ void _LCR_gamePrepareGhost(void)
LCR_game.ghost.offset[i] = (((((int) LCR_currentMap.startPos[i]) -
LCR_MAP_SIZE_BLOCKS / 2) * LCR_GAME_UNIT + LCR_GAME_UNIT / 2)
/ (i == 1 ? 2 : 1)) - carTransform[i];
#endif
}
LCR_GameUnit LCR_carSpeedKMH(void)
@ -853,8 +877,9 @@ uint8_t LCR_gameLoadMap(unsigned int mapIndex)
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)
int LCR_gameLoadReplay(unsigned int replayIndex)
{
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
uint32_t mapHash;
uint16_t nameHash;
char c;
@ -921,6 +946,9 @@ unsigned int LCR_gameLoadReplay(unsigned int replayIndex)
}
return 0;
#else
return -2;
#endif
}
void LCR_gameEraseMenuItemNames(void)
@ -1240,8 +1268,12 @@ void LCR_gameDraw3DView(void)
LCR_GameUnit carTransform[6];
LCR_GameUnit physicsInterpolationParam =
!(LCR_racing.replay.on && LCR_replayHasFinished()) ?
LCR_GAME_UNIT -
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
!(LCR_racing.replay.on && LCR_replayHasFinished())
#else
1
#endif
? LCR_GAME_UNIT -
((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT)
/ LCR_RACING_TICK_MS_RT
: LCR_GAME_UNIT / 2;
@ -1251,6 +1283,7 @@ void LCR_gameDraw3DView(void)
LCR_rendererSetCarTransform(carTransform,carTransform + 3);
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
if (LCR_game.ghost.active && LCR_game.state != LCR_GAME_STATE_RUN_STARTING)
{
LCR_GameUnit carTransform2[3];
@ -1269,6 +1302,7 @@ void LCR_gameDraw3DView(void)
}
else
LCR_rendererSetGhostVisibility(0);
#endif
if (LCR_game.cameraMode != LCR_CAMERA_MODE_FREE &&
LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
@ -1347,6 +1381,8 @@ void LCR_gameSaveReplay(void)
char str[10];
LCR_LOG0("saving replay");
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
_LCR_gameDataCharWrite(LCR_DATA_FILE_SEPARATOR);
_LCR_gameDataCharWrite('R');
@ -1371,6 +1407,7 @@ void LCR_gameSaveReplay(void)
LCR_replayOutputStr(_LCR_gameDataCharWrite);
LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_SAVED]);
#endif
}
/**
@ -1400,13 +1437,28 @@ void LCR_gameHandleInput(void)
if (LCR_game.keyStates[LCR_KEY_A] == 1)
{
if (LCR_game.runTime <= LCR_currentMap.targetTime
&& !LCR_game.ghost.active)
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
&& !LCR_game.ghost.active
#endif
)
{
LCR_LOG1("setting new target time");
LCR_currentMap.targetTime = LCR_game.runTime;
}
LCR_gameResetRun(LCR_racing.replay.on,LCR_game.ghost.active);
LCR_gameResetRun(
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
LCR_racing.replay.on,
#else
0,
#endif
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
LCR_game.ghost.active
#else
0
#endif
);
}
}
else if (LCR_game.state == LCR_GAME_STATE_RUN_STARTING)
@ -1466,7 +1518,19 @@ void LCR_gameHandleInput(void)
LCR_rendererMoveCamera(offsets,offsets + 3);
}
else if (LCR_game.keyStates[LCR_KEY_A] == 1)
LCR_gameResetRun(LCR_racing.replay.on,LCR_game.ghost.active);
LCR_gameResetRun(
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
LCR_racing.replay.on,
#else
0,
#endif
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
LCR_game.ghost.active
#else
0
#endif
);
}
else // LCR_GAME_STATE_MENU
{
@ -1566,10 +1630,12 @@ void LCR_gameHandleInput(void)
break;
case 3:
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
if (LCR_game.statePrev == LCR_GAME_STATE_RUN_FINISHED &&
!LCR_racing.replay.on)
LCR_gameSaveReplay();
else
#endif
LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_FAIL]);
break;
@ -1661,7 +1727,9 @@ uint8_t LCR_gameStep(uint32_t time)
if (LCR_game.menu.selectedTab == 3)
{
_LCR_gamePrepareGhost();
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
LCR_currentMap.targetTime = LCR_racing.replay.achievedTime;
#endif
}
LCR_gameSetState(LCR_GAME_STATE_LOADED);
@ -1736,13 +1804,25 @@ uint8_t LCR_gameStep(uint32_t time)
LCR_LOG1("finished, time:");
LCR_LOG1_NUM(LCR_game.runTime);
if (LCR_game.runTime <= LCR_currentMap.targetTime &&
!LCR_racing.replay.on)
if (LCR_game.runTime <= LCR_currentMap.targetTime
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
&& !LCR_racing.replay.on
#endif
)
{
LCR_gameSaveReplay();
if (!LCR_game.mapBeaten && !LCR_game.ghost.active &&
!LCR_racing.replay.on)
if (!LCR_game.mapBeaten &&
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0
!LCR_game.ghost.active &&
#endif
#if LCR_SETTING_REPLAY_MAX_SIZE != 0
!LCR_racing.replay.on
#else
1
#endif
)
{
LCR_LOG1("map beaten");
LCR_game.mapBeaten = 1;