From 1753e3237bf0e40c8b943ab94cdb8a0f78d91ee7 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Wed, 22 Jan 2025 00:18:28 +0100 Subject: [PATCH] Continue ghost --- game.h | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/game.h b/game.h index 1acc502..ae3791f 100644 --- a/game.h +++ b/game.h @@ -276,14 +276,13 @@ struct #if LCR_SETTING_GHOST_MAX_SAMPLES != 0 struct { + uint8_t active; 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, 4 for each rotation component. */ 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 is to allow ghosts for even long replays. */ - uint8_t *currentSample; - uint16_t nextSampleIn; } ghost; #endif @@ -335,7 +334,7 @@ void LCR_gameSetState(uint8_t state) 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]; @@ -346,14 +345,17 @@ void LCR_gameResetRun(uint8_t replay) LCR_racingGetCarTransform(carTransform,carTransform + 3,0); LCR_rendererSetCarTransform(carTransform,carTransform + 3); LCR_rendererCameraReset(); + LCR_game.ghost.active = ghost; LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING); 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) @@ -361,10 +363,11 @@ void _LCR_gamePrepareGhost(void) LCR_GameUnit carTransform[6]; 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.currentSample = LCR_game.ghost.samples; while (((int) LCR_replay.achievedTime) > (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch) * @@ -381,27 +384,25 @@ void _LCR_gamePrepareGhost(void) { LCR_racingGetCarTransform(carTransform,carTransform + 3,0); - LCR_game.ghost.currentSample[0] = carTransform[0]; - LCR_game.ghost.currentSample[1] = + currentSample[0] = carTransform[0]; + currentSample[1] = ((carTransform[0] >> 8) & 0x01) | (carTransform[1] << 1); - LCR_game.ghost.currentSample[2] = + currentSample[2] = ((carTransform[1] >> 7) & 0x03) | (carTransform[2] << 2); - LCR_game.ghost.currentSample[3] = + currentSample[3] = ((carTransform[2] >> 6) & 0x0f) | (carTransform[3] << 4); - LCR_game.ghost.currentSample[4] = + currentSample[4] = (carTransform[4] >> 4) | (carTransform[5] << 4); - LCR_game.ghost.currentSample += LCR_GHOST_SAMPLE_SIZE; + currentSample += LCR_GHOST_SAMPLE_SIZE; } LCR_racingStep(0); } - - LCR_gameGhostReset(); } LCR_GameUnit LCR_carSpeedKMH(void) @@ -778,6 +779,15 @@ void LCR_gameDraw3DView(void) 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 && LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) LCR_rendererCameraFollow( @@ -997,7 +1007,7 @@ void LCR_gameHandleInput(void) case LCR_GAME_STATE_RUN_FINISHED: if (LCR_game.keyStates[LCR_KEY_A] == 1) - LCR_gameResetRun(LCR_racing.playingReplay); + LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active); break; @@ -1049,7 +1059,7 @@ void LCR_gameHandleInput(void) LCR_rendererMoveCamera(offsets,offsets + 3); } else if (LCR_game.keyStates[LCR_KEY_A] == 1) - LCR_gameResetRun(LCR_racing.playingReplay); + LCR_gameResetRun(LCR_racing.playingReplay,LCR_game.ghost.active); break; } @@ -1082,11 +1092,11 @@ uint8_t LCR_gameStep(uint32_t time) LCR_rendererLoadMap(); if (LCR_game.menu.selectedTab == 3) - { _LCR_gamePrepareGhost(); - } - LCR_gameResetRun(LCR_game.menu.selectedTab == 2); + LCR_gameResetRun( + LCR_game.menu.selectedTab == 2, + LCR_game.menu.selectedTab == 3); } LCR_gameHandleInput();