From 74013219e57628af0de8912a5a2998e42b242216 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Thu, 12 Jun 2025 16:54:56 +0200 Subject: [PATCH] Fix time multiplier --- game.h | 20 +++++++++++--------- racing.h | 10 +++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/game.h b/game.h index 461bdae..2336b1a 100644 --- a/game.h +++ b/game.h @@ -1246,7 +1246,7 @@ void LCR_gameDraw3DView(void) !(LCR_racing.replay.on && LCR_replayHasFinished()) ? LCR_GAME_UNIT - ((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT) - / LCR_RACING_TICK_MS + / LCR_RACING_TICK_MS_RT : LCR_GAME_UNIT / 2; LCR_racingGetCarTransform(carTransform,carTransform + 3, @@ -1782,11 +1782,9 @@ uint8_t LCR_gameStep(uint32_t time) if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) LCR_game.runTime = LCR_racing.tick; - LCR_game.nextRacingTickTime += LCR_RACING_TICK_MS; + LCR_game.nextRacingTickTime += LCR_RACING_TICK_MS_RT; } - sleep = (3 * (LCR_game.nextRacingTickTime - time)) / 4; - // handle rendering: if (time >= LCR_game.nextRenderFrameTime || LCR_game.state == LCR_GAME_STATE_LOADING) @@ -1822,11 +1820,6 @@ uint8_t LCR_gameStep(uint32_t time) LCR_game.renderFramesMeasured++; #endif } - else - { - uint32_t tmp = (3 * (LCR_game.nextRenderFrameTime - time)) / 4; - sleep = tmp < sleep ? tmp : sleep; - } if (LCR_game.state == LCR_GAME_STATE_LOADING) { @@ -1837,6 +1830,15 @@ uint8_t LCR_gameStep(uint32_t time) LCR_gameDrawPopupMessage(); } + if (LCR_game.nextRacingTickTime > time) + sleep = LCR_game.nextRenderFrameTime - time; + + if (LCR_game.nextRenderFrameTime > time && + LCR_game.nextRenderFrameTime - time < sleep) + sleep = LCR_game.nextRenderFrameTime - time; + + sleep = (sleep * 3) / 4; + if (sleep) LCR_sleep(sleep); else diff --git a/racing.h b/racing.h index 375e1df..c9e6202 100644 --- a/racing.h +++ b/racing.h @@ -56,7 +56,10 @@ typedef int32_t LCR_GameUnit; ///< Abstract game unit. #define LCR_RACING_FPS 30 /**< Physics FPS, i.e. the number of physics ticks per second. */ -#define LCR_RACING_TICK_MS \ + +#define LCR_RACING_TICK_MS (1000 / LCR_RACING_FPS) + +#define LCR_RACING_TICK_MS_RT \ (100000 / (LCR_RACING_FPS * LCR_SETTING_TIME_MULTIPLIER)) #define LCR_RACING_VERSION1 '0' ///< First part of physics eng. version. @@ -1202,8 +1205,9 @@ int _LCR_racingCarShapeOK(void) } /** - Updates the racing physics world, call every LCR_RACING_TICK_MS milliseconds. - Returns a set of events (logically ORed) that occured during this step. + Updates the racing physics world, call every LCR_RACING_TICK_MS_RT + milliseconds. Returns a set of events (logically ORed) that occured during + this step. */ uint32_t LCR_racingStep(unsigned int input) {