diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index ffdb67a28e..059676227c 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -259,7 +259,7 @@ static void input_scroll_right(int32_t x, int32_t y, int32_t state) switch (state) { case MOUSE_STATE_RELEASED: - _ticksSinceDragStart += gTicksSinceLastUpdate; + _ticksSinceDragStart += gCurrentDeltaTime; if (x != 0 || y != 0) { _ticksSinceDragStart = 1000; @@ -552,7 +552,7 @@ static void input_viewport_drag_continue() } viewport = w->viewport; - _ticksSinceDragStart += gTicksSinceLastUpdate; + _ticksSinceDragStart += gCurrentDeltaTime; if (viewport == nullptr) { context_show_cursor(); @@ -1479,7 +1479,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, int window_tooltip_close(); } - gTooltipTimeout += gTicksSinceLastUpdate; + gTooltipTimeout += gCurrentDeltaTime; if (gTooltipTimeout >= 8000) { window_close_by_class(WC_TOOLTIP); diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 7f4078ca06..d866972646 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -110,7 +110,7 @@ namespace OpenRCT2 bool _isWindowMinimised = false; uint32_t _lastTick = 0; uint32_t _accumulator = 0; - uint32_t _lastUpdateTick = 0; + uint32_t _lastUpdateTime = 0; bool _variableFrame = false; // If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to @@ -914,13 +914,14 @@ namespace OpenRCT2 void Update() { - uint32_t currentUpdateTick = platform_get_ticks(); - gTicksSinceLastUpdate = std::min(currentUpdateTick - _lastUpdateTick, 500); - _lastUpdateTick = currentUpdateTick; + uint32_t currentUpdateTime = platform_get_ticks(); + + gCurrentDeltaTime = std::min(currentUpdateTime - _lastUpdateTime, 500); + _lastUpdateTime = currentUpdateTime; if (game_is_not_paused()) { - gPaletteEffectFrame += gTicksSinceLastUpdate; + gPaletteEffectFrame += gCurrentDeltaTime; } date_update_real_time_of_day(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 3b1a082237..507088ce6d 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -65,7 +65,7 @@ #define NUMBER_OF_AUTOSAVES_TO_KEEP 9 -uint16_t gTicksSinceLastUpdate; +uint16_t gCurrentDeltaTime; uint8_t gGamePaused = 0; int32_t gGameSpeed = 1; bool gDoSingleUpdate = false; @@ -82,6 +82,7 @@ uint8_t gUnk13CA740; uint8_t gUnk141F568; uint32_t gCurrentTicks; +uint32_t gCurrentRealTimeTicks; // clang-format off GAME_COMMAND_CALLBACK_POINTER * game_command_callback = nullptr; diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index c26b00aefe..c0dea522e4 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -137,8 +137,9 @@ extern rct_string_id gErrorStringId; extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT]; extern uint32_t gCurrentTicks; +extern uint32_t gCurrentRealTimeTicks; -extern uint16_t gTicksSinceLastUpdate; +extern uint16_t gCurrentDeltaTime; extern uint8_t gGamePaused; extern int32_t gGameSpeed; extern bool gDoSingleUpdate; diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index b48026b6b0..f88f790794 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -91,6 +91,12 @@ void GameState::Update() } } + uint32_t realtimeTicksElapsed = gCurrentDeltaTime / GAME_UPDATE_TIME_MS; + realtimeTicksElapsed = std::clamp(realtimeTicksElapsed, 1, GAME_MAX_UPDATES); + + // We use this variable to always advance ticks in normal speed. + gCurrentRealTimeTicks += realtimeTicksElapsed; + // Determine how many times we need to update the game if (gGameSpeed > 1) { @@ -98,8 +104,7 @@ void GameState::Update() } else { - numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS; - numUpdates = std::clamp(numUpdates, 1, GAME_MAX_UPDATES); + numUpdates = realtimeTicksElapsed; } if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 9a93a7577c..659418aecb 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -133,7 +133,7 @@ void window_update_all() // gfx_draw_all_dirty_blocks(); // 1000 tick update - gWindowUpdateTicks += gTicksSinceLastUpdate; + gWindowUpdateTicks += gCurrentDeltaTime; if (gWindowUpdateTicks >= 1000) { gWindowUpdateTicks = 0; diff --git a/src/openrct2/localisation/Localisation.Date.cpp b/src/openrct2/localisation/Localisation.Date.cpp index 8f7e5320a6..8d4b8fbec5 100644 --- a/src/openrct2/localisation/Localisation.Date.cpp +++ b/src/openrct2/localisation/Localisation.Date.cpp @@ -62,6 +62,7 @@ void date_reset() gDateMonthsElapsed = 0; gDateMonthTicks = 0; gCurrentTicks = 0; + gCurrentRealTimeTicks = 0; } void date_set(int32_t year, int32_t month, int32_t day) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index acfda40e1c..a407f1c81d 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -381,6 +381,7 @@ public: user_string_clear_all(); memcpy(gUserStrings, _s6.custom_strings, sizeof(_s6.custom_strings)); gCurrentTicks = _s6.game_ticks_1; + gCurrentRealTimeTicks = 0; ImportRides();