Continue ghost

This commit is contained in:
Miloslav Ciz 2025-01-22 00:18:28 +01:00
parent 0b16d64eef
commit 1753e3237b

52
game.h
View file

@ -276,14 +276,13 @@ struct
#if LCR_SETTING_GHOST_MAX_SAMPLES != 0 #if LCR_SETTING_GHOST_MAX_SAMPLES != 0
struct struct
{ {
uint8_t active;
uint8_t samples[LCR_SETTING_GHOST_MAX_SAMPLES * LCR_GHOST_SAMPLE_SIZE]; uint8_t samples[LCR_SETTING_GHOST_MAX_SAMPLES * LCR_GHOST_SAMPLE_SIZE];
/**< Samples, each 5 bytes: 9 bits for X and Z, 10 for Z, /**< Samples, each 5 bytes: 9 bits for X and Z, 10 for Z,
4 for each rotation component. */ 4 for each rotation component. */
uint8_t stretch; /**< Stretch of the base sample step, as a bit shift uint8_t stretch; /**< Stretch of the base sample step, as a bit shift
(i.e. 1 means the step will be 2x as long etc.). This (i.e. 1 means the step will be 2x as long etc.). This
is to allow ghosts for even long replays. */ is to allow ghosts for even long replays. */
uint8_t *currentSample;
uint16_t nextSampleIn;
} ghost; } ghost;
#endif #endif
@ -335,7 +334,7 @@ void LCR_gameSetState(uint8_t state)
LCR_game.stateStartTime = LCR_game.time; LCR_game.stateStartTime = LCR_game.time;
} }
void LCR_gameResetRun(uint8_t replay) void LCR_gameResetRun(uint8_t replay, uint8_t ghost)
{ {
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
@ -346,14 +345,17 @@ void LCR_gameResetRun(uint8_t replay)
LCR_racingGetCarTransform(carTransform,carTransform + 3,0); LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
LCR_rendererSetCarTransform(carTransform,carTransform + 3); LCR_rendererSetCarTransform(carTransform,carTransform + 3);
LCR_rendererCameraReset(); LCR_rendererCameraReset();
LCR_game.ghost.active = ghost;
LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING); LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING);
LCR_game.runTimeMS = 0; LCR_game.runTimeMS = 0;
} }
void LCR_gameGhostReset(void) void LCR_gameGhostGetTransform(uint32_t frame,
LCR_GameUnit position[3], LCR_GameUnit rotation[3])
{ {
LCR_game.ghost.currentSample = LCR_game.ghost.samples;
LCR_game.ghost.nextSampleIn = 0; LCR_racingGetCarTransform(position,rotation,0);
} }
void _LCR_gamePrepareGhost(void) void _LCR_gamePrepareGhost(void)
@ -361,10 +363,11 @@ void _LCR_gamePrepareGhost(void)
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
LCR_LOG1("preparing ghost"); LCR_LOG1("preparing ghost");
LCR_gameResetRun(1); LCR_gameResetRun(1,0);
uint8_t *currentSample = LCR_game.ghost.samples;
LCR_game.ghost.stretch = 0; LCR_game.ghost.stretch = 0;
LCR_game.ghost.currentSample = LCR_game.ghost.samples;
while (((int) LCR_replay.achievedTime) > while (((int) LCR_replay.achievedTime) >
(LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch) * (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch) *
@ -381,27 +384,25 @@ void _LCR_gamePrepareGhost(void)
{ {
LCR_racingGetCarTransform(carTransform,carTransform + 3,0); LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
LCR_game.ghost.currentSample[0] = carTransform[0]; currentSample[0] = carTransform[0];
LCR_game.ghost.currentSample[1] = currentSample[1] =
((carTransform[0] >> 8) & 0x01) | ((carTransform[0] >> 8) & 0x01) |
(carTransform[1] << 1); (carTransform[1] << 1);
LCR_game.ghost.currentSample[2] = currentSample[2] =
((carTransform[1] >> 7) & 0x03) | ((carTransform[1] >> 7) & 0x03) |
(carTransform[2] << 2); (carTransform[2] << 2);
LCR_game.ghost.currentSample[3] = currentSample[3] =
((carTransform[2] >> 6) & 0x0f) | ((carTransform[2] >> 6) & 0x0f) |
(carTransform[3] << 4); (carTransform[3] << 4);
LCR_game.ghost.currentSample[4] = currentSample[4] =
(carTransform[4] >> 4) | (carTransform[4] >> 4) |
(carTransform[5] << 4); (carTransform[5] << 4);
LCR_game.ghost.currentSample += LCR_GHOST_SAMPLE_SIZE; currentSample += LCR_GHOST_SAMPLE_SIZE;
} }
LCR_racingStep(0); LCR_racingStep(0);
} }
LCR_gameGhostReset();
} }
LCR_GameUnit LCR_carSpeedKMH(void) LCR_GameUnit LCR_carSpeedKMH(void)
@ -778,6 +779,15 @@ void LCR_gameDraw3DView(void)
LCR_rendererSetCarTransform(carTransform,carTransform + 3); LCR_rendererSetCarTransform(carTransform,carTransform + 3);
if (LCR_game.ghost.active)
{
LCR_rendererSetGhostVisibility(1);
LCR_gameGhostGetTransform(LCR_racing.tick,carTransform,carTransform + 3);
LCR_rendererSetGhostTransform(carTransform,carTransform + 3);
}
else
LCR_rendererSetGhostVisibility(0);
if (LCR_game.cameraMode != LCR_CAMERA_MODE_FREE && if (LCR_game.cameraMode != LCR_CAMERA_MODE_FREE &&
LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
LCR_rendererCameraFollow( LCR_rendererCameraFollow(
@ -997,7 +1007,7 @@ void LCR_gameHandleInput(void)
case LCR_GAME_STATE_RUN_FINISHED: case LCR_GAME_STATE_RUN_FINISHED:
if (LCR_game.keyStates[LCR_KEY_A] == 1) if (LCR_game.keyStates[LCR_KEY_A] == 1)
LCR_gameResetRun(LCR_racing.playingReplay); LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active);
break; break;
@ -1049,7 +1059,7 @@ void LCR_gameHandleInput(void)
LCR_rendererMoveCamera(offsets,offsets + 3); LCR_rendererMoveCamera(offsets,offsets + 3);
} }
else if (LCR_game.keyStates[LCR_KEY_A] == 1) else if (LCR_game.keyStates[LCR_KEY_A] == 1)
LCR_gameResetRun(LCR_racing.playingReplay); LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active);
break; break;
} }
@ -1082,11 +1092,11 @@ uint8_t LCR_gameStep(uint32_t time)
LCR_rendererLoadMap(); LCR_rendererLoadMap();
if (LCR_game.menu.selectedTab == 3) if (LCR_game.menu.selectedTab == 3)
{
_LCR_gamePrepareGhost(); _LCR_gamePrepareGhost();
}
LCR_gameResetRun(LCR_game.menu.selectedTab == 2); LCR_gameResetRun(
LCR_game.menu.selectedTab == 2,
LCR_game.menu.selectedTab == 3);
} }
LCR_gameHandleInput(); LCR_gameHandleInput();