summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-17 20:22:57 +0200
committerGitHub <noreply@github.com>2021-06-17 20:22:57 +0200
commitcf865597f8f14c56e96b22b9a7fef1b693fbcb08 (patch)
treef9792d33d19984f67c8514e9223a06a8ee4c08ee
parentb45c006ab9bdfb92fa6be66dcfa00099adbb85a8 (diff)
downloadopenttd-cf865597f8f14c56e96b22b9a7fef1b693fbcb08.tar.xz
Fix: don't propagate shift/ctrl state till next game-tick (#9381)
When the game-loop is very slow, it was easily possible to start the loop with _shift_pressed being false, but end with _shift_pressed being true. This doesn't hurt the game as such, but for the user this can be very weird: I pressed "Buy Vehicle", pressed shift a bit later, and I still get a cost indication.
-rw-r--r--src/video/video_driver.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp
index 27824674a..8fe582760 100644
--- a/src/video/video_driver.cpp
+++ b/src/video/video_driver.cpp
@@ -116,21 +116,6 @@ void VideoDriver::Tick()
/* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
if (this->next_draw_tick < now - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = now;
- /* Keep the interactive randomizer a bit more random by requesting
- * new values when-ever we can. */
- InteractiveRandom();
-
- this->InputLoop();
-
- /* Check if the fast-forward button is still pressed. */
- if (fast_forward_key_pressed && !_networking && _game_mode != GM_MENU) {
- ChangeGameSpeed(true);
- this->fast_forward_via_key = true;
- } else if (this->fast_forward_via_key) {
- ChangeGameSpeed(false);
- this->fast_forward_via_key = false;
- }
-
/* Locking video buffer can block (especially with vsync enabled), do it before taking game state lock. */
this->LockVideoBuffer();
@@ -139,9 +124,24 @@ void VideoDriver::Tick()
std::lock_guard<std::mutex> lock_wait(this->game_thread_wait_mutex);
std::lock_guard<std::mutex> lock_state(this->game_state_mutex);
+ /* Keep the interactive randomizer a bit more random by requesting
+ * new values when-ever we can. */
+ InteractiveRandom();
+
this->DrainCommandQueue();
while (this->PollEvent()) {}
+ this->InputLoop();
+
+ /* Check if the fast-forward button is still pressed. */
+ if (fast_forward_key_pressed && !_networking && _game_mode != GM_MENU) {
+ ChangeGameSpeed(true);
+ this->fast_forward_via_key = true;
+ } else if (this->fast_forward_via_key) {
+ ChangeGameSpeed(false);
+ this->fast_forward_via_key = false;
+ }
+
::InputLoop();
/* Prevent drawing when switching mode, as windows can be removed when they should still appear. */