1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Introduce gCurrentRealTimeTicks and refactor some variable names.

This commit is contained in:
Matt
2018-12-01 16:36:00 +01:00
parent ebd4e8f5d6
commit 4bc69a0111
8 changed files with 23 additions and 13 deletions

View File

@@ -259,7 +259,7 @@ static void input_scroll_right(int32_t x, int32_t y, int32_t state)
switch (state) switch (state)
{ {
case MOUSE_STATE_RELEASED: case MOUSE_STATE_RELEASED:
_ticksSinceDragStart += gTicksSinceLastUpdate; _ticksSinceDragStart += gCurrentDeltaTime;
if (x != 0 || y != 0) if (x != 0 || y != 0)
{ {
_ticksSinceDragStart = 1000; _ticksSinceDragStart = 1000;
@@ -552,7 +552,7 @@ static void input_viewport_drag_continue()
} }
viewport = w->viewport; viewport = w->viewport;
_ticksSinceDragStart += gTicksSinceLastUpdate; _ticksSinceDragStart += gCurrentDeltaTime;
if (viewport == nullptr) if (viewport == nullptr)
{ {
context_show_cursor(); context_show_cursor();
@@ -1479,7 +1479,7 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, int
window_tooltip_close(); window_tooltip_close();
} }
gTooltipTimeout += gTicksSinceLastUpdate; gTooltipTimeout += gCurrentDeltaTime;
if (gTooltipTimeout >= 8000) if (gTooltipTimeout >= 8000)
{ {
window_close_by_class(WC_TOOLTIP); window_close_by_class(WC_TOOLTIP);

View File

@@ -110,7 +110,7 @@ namespace OpenRCT2
bool _isWindowMinimised = false; bool _isWindowMinimised = false;
uint32_t _lastTick = 0; uint32_t _lastTick = 0;
uint32_t _accumulator = 0; uint32_t _accumulator = 0;
uint32_t _lastUpdateTick = 0; uint32_t _lastUpdateTime = 0;
bool _variableFrame = false; 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 // 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() void Update()
{ {
uint32_t currentUpdateTick = platform_get_ticks(); uint32_t currentUpdateTime = platform_get_ticks();
gTicksSinceLastUpdate = std::min<uint32_t>(currentUpdateTick - _lastUpdateTick, 500);
_lastUpdateTick = currentUpdateTick; gCurrentDeltaTime = std::min<uint32_t>(currentUpdateTime - _lastUpdateTime, 500);
_lastUpdateTime = currentUpdateTime;
if (game_is_not_paused()) if (game_is_not_paused())
{ {
gPaletteEffectFrame += gTicksSinceLastUpdate; gPaletteEffectFrame += gCurrentDeltaTime;
} }
date_update_real_time_of_day(); date_update_real_time_of_day();

View File

@@ -65,7 +65,7 @@
#define NUMBER_OF_AUTOSAVES_TO_KEEP 9 #define NUMBER_OF_AUTOSAVES_TO_KEEP 9
uint16_t gTicksSinceLastUpdate; uint16_t gCurrentDeltaTime;
uint8_t gGamePaused = 0; uint8_t gGamePaused = 0;
int32_t gGameSpeed = 1; int32_t gGameSpeed = 1;
bool gDoSingleUpdate = false; bool gDoSingleUpdate = false;
@@ -82,6 +82,7 @@ uint8_t gUnk13CA740;
uint8_t gUnk141F568; uint8_t gUnk141F568;
uint32_t gCurrentTicks; uint32_t gCurrentTicks;
uint32_t gCurrentRealTimeTicks;
// clang-format off // clang-format off
GAME_COMMAND_CALLBACK_POINTER * game_command_callback = nullptr; GAME_COMMAND_CALLBACK_POINTER * game_command_callback = nullptr;

View File

@@ -137,8 +137,9 @@ extern rct_string_id gErrorStringId;
extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT]; extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT];
extern uint32_t gCurrentTicks; extern uint32_t gCurrentTicks;
extern uint32_t gCurrentRealTimeTicks;
extern uint16_t gTicksSinceLastUpdate; extern uint16_t gCurrentDeltaTime;
extern uint8_t gGamePaused; extern uint8_t gGamePaused;
extern int32_t gGameSpeed; extern int32_t gGameSpeed;
extern bool gDoSingleUpdate; extern bool gDoSingleUpdate;

View File

@@ -91,6 +91,12 @@ void GameState::Update()
} }
} }
uint32_t realtimeTicksElapsed = gCurrentDeltaTime / GAME_UPDATE_TIME_MS;
realtimeTicksElapsed = std::clamp<uint32_t>(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 // Determine how many times we need to update the game
if (gGameSpeed > 1) if (gGameSpeed > 1)
{ {
@@ -98,8 +104,7 @@ void GameState::Update()
} }
else else
{ {
numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS; numUpdates = realtimeTicksElapsed;
numUpdates = std::clamp<uint32_t>(numUpdates, 1, GAME_MAX_UPDATES);
} }
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED

View File

@@ -133,7 +133,7 @@ void window_update_all()
// gfx_draw_all_dirty_blocks(); // gfx_draw_all_dirty_blocks();
// 1000 tick update // 1000 tick update
gWindowUpdateTicks += gTicksSinceLastUpdate; gWindowUpdateTicks += gCurrentDeltaTime;
if (gWindowUpdateTicks >= 1000) if (gWindowUpdateTicks >= 1000)
{ {
gWindowUpdateTicks = 0; gWindowUpdateTicks = 0;

View File

@@ -62,6 +62,7 @@ void date_reset()
gDateMonthsElapsed = 0; gDateMonthsElapsed = 0;
gDateMonthTicks = 0; gDateMonthTicks = 0;
gCurrentTicks = 0; gCurrentTicks = 0;
gCurrentRealTimeTicks = 0;
} }
void date_set(int32_t year, int32_t month, int32_t day) void date_set(int32_t year, int32_t month, int32_t day)

View File

@@ -381,6 +381,7 @@ public:
user_string_clear_all(); user_string_clear_all();
memcpy(gUserStrings, _s6.custom_strings, sizeof(_s6.custom_strings)); memcpy(gUserStrings, _s6.custom_strings, sizeof(_s6.custom_strings));
gCurrentTicks = _s6.game_ticks_1; gCurrentTicks = _s6.game_ticks_1;
gCurrentRealTimeTicks = 0;
ImportRides(); ImportRides();