From 0bbbc26f2a6a8a4c3571a7a0623e2f32ef15e32f Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Wed, 28 May 2025 22:05:50 +0200 Subject: [PATCH] Fix bug, add input display --- TODO.txt | 3 ++- game.h | 31 +++++++++++++++++++++++++------ map.h | 4 ++-- racing.h | 8 ++++++-- settings.h | 6 ++++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/TODO.txt b/TODO.txt index 601be97..841a8a1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,7 +2,6 @@ fuck issue trackers :D =========== GENERAL ============== -- add display of inputs on the screen (option in setting? arg?) - frontends: - auto test frontend, with no I/O, that will just internally run a series of inputs and check if the output is as expected @@ -44,6 +43,8 @@ fuck issue trackers :D =========== HANDLED ============== - should drifting make a sound? NO NEED +- add display of inputs on the screen (option in setting? arg?) +- viewing replay during countdown bugs! - sometimes after restart the timer shows not 0:0:0, but something like 0:0:033 - doxygen documentation - immediately after starting the map countdown seems to be lower (seems to diff --git a/game.h b/game.h index ba4f436..75b8cdd 100644 --- a/game.h +++ b/game.h @@ -482,6 +482,7 @@ void LCR_gameResetRun(uint8_t replay, uint8_t ghost) LCR_LOG0("resetting run"); LCR_mapReset(); + LCR_racingRestart(replay); LCR_rendererUnmarkCPs(); LCR_racingGetCarTransform(carTransform,carTransform + 3,0); @@ -833,6 +834,7 @@ uint8_t LCR_gameLoadMap(unsigned int mapIndex) result = LCR_mapLoadFromStr(LCR_gameGetNextDataStrChar,name); LCR_game.mapBeaten = LCR_mapIsBeaten(LCR_currentMap.name); + return result; } @@ -1228,9 +1230,12 @@ void LCR_gameDraw3DView(void) { LCR_GameUnit carTransform[6]; - LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT - - ((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT) - / LCR_RACING_TICK_MS; + LCR_GameUnit physicsInterpolationParam = + !(LCR_racing.playingReplay && LCR_replayHasFinished()) ? + LCR_GAME_UNIT - + ((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT) + / LCR_RACING_TICK_MS + : LCR_GAME_UNIT / 2; LCR_racingGetCarTransform(carTransform,carTransform + 3, physicsInterpolationParam); @@ -1285,6 +1290,19 @@ void LCR_gameDraw3DView(void) LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(_FONT_SIZE) - LCR_GUI_GAP,0,_FONT_SIZE); +#if LCR_SETTING_DISPLAY_INPUTS + str[0] = (LCR_racing.currentInputs & LCR_RACING_INPUT_LEFT) ? 'L' : '.'; + str[1] = (LCR_racing.currentInputs & LCR_RACING_INPUT_BACK) ? 'D' : '.'; + str[2] = (LCR_racing.currentInputs & LCR_RACING_INPUT_FORW) ? 'U' : '.'; + str[3] = (LCR_racing.currentInputs & LCR_RACING_INPUT_RIGHT) ? 'R' : '.'; + str[4] = 0; + + LCR_rendererDrawText(str,LCR_EFFECTIVE_RESOLUTION_X - + LCR_rendererComputeTextWidth(str,_FONT_SIZE) - LCR_GUI_GAP, + LCR_EFFECTIVE_RESOLUTION_Y - 2 * + (LCR_rendererComputeTextHeight(_FONT_SIZE) + LCR_GUI_GAP),0,_FONT_SIZE); +#endif + LCR_gameTimeToStr(LCR_game.runTime,str); if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) @@ -1622,9 +1640,10 @@ uint8_t LCR_gameStep(uint32_t time) else { LCR_gameHandleInput(); - - int paused = LCR_game.state == LCR_GAME_STATE_MENU || - LCR_game.state == LCR_GAME_STATE_RUN_STARTING; + + int paused = + LCR_game.state != LCR_GAME_STATE_RUN && + LCR_game.state != LCR_GAME_STATE_RUN_FINISHED; // handle simulation: while (time >= LCR_game.nextRacingTickTime) diff --git a/map.h b/map.h index 5d791c9..a5ee022 100644 --- a/map.h +++ b/map.h @@ -392,10 +392,10 @@ void _LCR_mapComputeHash(void) LCR_currentMap.hash = 11 + LCR_currentMap.environment; - for (int i = 0; i < LCR_currentMap.blockCount * LCR_BLOCK_SIZE + 4; ++i) + for (int i = 0; i < 4 + LCR_currentMap.blockCount * LCR_BLOCK_SIZE; ++i) { LCR_currentMap.hash = LCR_currentMap.hash * 101 + *data; - data = i != 3 ? data + 1 : LCR_currentMap.blocks; + data = (i != 3) ? data + 1 : LCR_currentMap.blocks; } LCR_currentMap.hash *= 251; diff --git a/racing.h b/racing.h index 6b8f1a0..6851f42 100644 --- a/racing.h +++ b/racing.h @@ -134,6 +134,7 @@ struct LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative if backwards) and its previous value. */ + uint8_t currentInputs; ///< Current input state (from player or replay). uint8_t groundMaterial; ///< Material currently under car wheels. @@ -251,8 +252,8 @@ void LCR_replayOutputStr(void (*printChar)(char)) the memory they point to will be filled with the map hash and name hash. Returns 1 on success, else 0. */ -int LCR_replayLoadFromStr(char (*nextChar)(void), - uint32_t *mapHash, uint16_t *nameHash) +int LCR_replayLoadFromStr(char (*nextChar)(void), uint32_t *mapHash, + uint16_t *nameHash) { char c; @@ -964,6 +965,7 @@ void LCR_racingRestart(uint8_t replay) LCR_racing.carSpeeds[1] = 0; LCR_racing.carDrifting = 0; LCR_racing.crashState = 0; + LCR_racing.currentInputs = 0; // make the car body: TPE_makeCenterRectFull(LCR_racing.carJoints, @@ -1192,6 +1194,8 @@ uint32_t LCR_racingStep(unsigned int input) LCR_replayRecordEvent(LCR_racing.tick,input); } + LCR_racing.currentInputs = input; + carForw = TPE_vec3Normalized(TPE_vec3Plus( TPE_vec3Minus(LCR_racing.carBody.joints[0].position, LCR_racing.carBody.joints[2].position), diff --git a/settings.h b/settings.h index 63fc09c..3188724 100644 --- a/settings.h +++ b/settings.h @@ -92,9 +92,15 @@ #endif #ifndef LCR_SETTING_LOD_COLOR + /** RGB565 color of LOD blocks in the distance. */ #define LCR_SETTING_LOD_COLOR 0x4229 #endif +#ifndef LCR_SETTING_DISPLAY_INPUTS + /** Whether to display current inputs on the screen. */ + #define LCR_SETTING_DISPLAY_INPUTS 1 +#endif + #ifndef LCR_SETTING_CAR_ANIMATION_SUBDIVIDE /** How many frames will be used to complete whole animation of the car model. 0 turns off car animation completely (may be faster and smaller), 1 turns on