diff options
author | glx <glx@openttd.org> | 2020-03-07 19:34:50 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-01-10 14:07:17 +0100 |
commit | c0d7949d7c798285cc289bb9c76b4b155256456c (patch) | |
tree | 254d70ce418761c5b86f3844180c049a83daffa1 | |
parent | 97d554feb175179c7af70f7d61cf56886b3090bd (diff) | |
download | openttd-c0d7949d7c798285cc289bb9c76b4b155256456c.tar.xz |
Fix: Don't use a timer for hundredth tick determination
-rw-r--r-- | src/window.cpp | 27 | ||||
-rw-r--r-- | src/window_gui.h | 4 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/window.cpp b/src/window.cpp index f67cda90f..aea7bf341 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1944,10 +1944,15 @@ void ResetWindowSystem() static void DecreaseWindowCounters() { + static byte hundredth_tick_timeout = 100; + if (_scroller_click_timeout != 0) _scroller_click_timeout--; + if (hundredth_tick_timeout != 0) hundredth_tick_timeout--; Window *w; FOR_ALL_WINDOWS_FROM_FRONT(w) { + if (!_network_dedicated && hundredth_tick_timeout == 0) w->OnHundredthTick(); + if (_scroller_click_timeout == 0) { /* Unclick scrollbar buttons if they are pressed. */ for (uint i = 0; i < w->nested_array_size; i++) { @@ -1979,6 +1984,8 @@ static void DecreaseWindowCounters() w->RaiseButtons(true); } } + + if (hundredth_tick_timeout == 0) hundredth_tick_timeout = 100; } static void HandlePlacePresize() @@ -3150,6 +3157,12 @@ void UpdateWindows() Window *w; + /* Process invalidations before anything else. */ + FOR_ALL_WINDOWS_FROM_FRONT(w) { + w->ProcessScheduledInvalidations(); + w->ProcessHighlightedInvalidations(); + } + static GUITimer window_timer = GUITimer(1); if (window_timer.Elapsed(delta_ms)) { if (_network_dedicated) window_timer.SetInterval(MILLISECONDS_PER_TICK); @@ -3171,24 +3184,10 @@ void UpdateWindows() if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects(delta_ms); - FOR_ALL_WINDOWS_FROM_FRONT(w) { - w->ProcessScheduledInvalidations(); - w->ProcessHighlightedInvalidations(); - } - /* Skip the actual drawing on dedicated servers without screen. * But still empty the invalidation queues above. */ if (_network_dedicated) return; - static GUITimer hundredth_timer = GUITimer(1); - if (hundredth_timer.Elapsed(delta_ms)) { - hundredth_timer.SetInterval(3000); // Historical reason: 100 * MILLISECONDS_PER_TICK - - FOR_ALL_WINDOWS_FROM_FRONT(w) { - w->OnHundredthTick(); - } - } - if (window_timer.HasElapsed()) { window_timer.SetInterval(MILLISECONDS_PER_TICK); diff --git a/src/window_gui.h b/src/window_gui.h index b03f5bbca..c792a6b28 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -691,7 +691,9 @@ public: virtual void OnGameTick() {} /** - * Called once every 100 (game) ticks. + * Called once every 100 (game) ticks, or once every 3s, whichever comes last. + * In normal game speed the frequency is 1 call every 100 ticks (can be more than 3s). + * In fast-forward the frequency is 1 call every ~3s (can be more than 100 ticks). */ virtual void OnHundredthTick() {} |