mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-07-05 20:09:38 +01:00
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.
This commit is contained in:
parent
b45c006ab9
commit
cf865597f8
@ -116,10 +116,21 @@ void VideoDriver::Tick()
|
|||||||
/* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
|
/* 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;
|
if (this->next_draw_tick < now - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = now;
|
||||||
|
|
||||||
|
/* Locking video buffer can block (especially with vsync enabled), do it before taking game state lock. */
|
||||||
|
this->LockVideoBuffer();
|
||||||
|
|
||||||
|
{
|
||||||
|
/* Tell the game-thread to stop so we can have a go. */
|
||||||
|
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
|
/* Keep the interactive randomizer a bit more random by requesting
|
||||||
* new values when-ever we can. */
|
* new values when-ever we can. */
|
||||||
InteractiveRandom();
|
InteractiveRandom();
|
||||||
|
|
||||||
|
this->DrainCommandQueue();
|
||||||
|
|
||||||
|
while (this->PollEvent()) {}
|
||||||
this->InputLoop();
|
this->InputLoop();
|
||||||
|
|
||||||
/* Check if the fast-forward button is still pressed. */
|
/* Check if the fast-forward button is still pressed. */
|
||||||
@ -131,17 +142,6 @@ void VideoDriver::Tick()
|
|||||||
this->fast_forward_via_key = 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();
|
|
||||||
|
|
||||||
{
|
|
||||||
/* Tell the game-thread to stop so we can have a go. */
|
|
||||||
std::lock_guard<std::mutex> lock_wait(this->game_thread_wait_mutex);
|
|
||||||
std::lock_guard<std::mutex> lock_state(this->game_state_mutex);
|
|
||||||
|
|
||||||
this->DrainCommandQueue();
|
|
||||||
|
|
||||||
while (this->PollEvent()) {}
|
|
||||||
::InputLoop();
|
::InputLoop();
|
||||||
|
|
||||||
/* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
|
/* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
|
||||||
|
Loading…
Reference in New Issue
Block a user