summaryrefslogtreecommitdiff
path: root/src/video/cocoa
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-02-17 15:04:46 +0100
committerPatric Stout <github@truebrain.nl>2021-02-19 10:43:15 +0100
commitc81c6e5eb7a0e991039b7662868e87a8d2fe3415 (patch)
tree99be2e476e68136db5f64fe34e606f9a7a418211 /src/video/cocoa
parent5bfa0145057f2b67ed05d491abea82df4cc10d6b (diff)
downloadopenttd-c81c6e5eb7a0e991039b7662868e87a8d2fe3415.tar.xz
Add: draw the screen at a steady pace, also during fast-forward
During fast-forward, the game was drawing as fast as it could. This means that the fast-forward was limited also by how fast we could draw, something that people in general don't expect. To give an extreme case, if you are fully zoomed out on a busy map, fast-forward would be mostly limited because of the time it takes to draw the screen. By decoupling the draw-tick and game-tick, we can keep the pace of the draw-tick the same while speeding up the game-tick. To use the extreme case as example again, if you are fully zoomed out now, the screen only redraws 33.33 times per second, fast-forwarding or not. This means fast-forward is much more likely to go at the same speed, no matter what you are looking at.
Diffstat (limited to 'src/video/cocoa')
-rw-r--r--src/video/cocoa/cocoa_v.mm24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index c9e6768a8..d065630b7 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -636,7 +636,8 @@ void VideoDriver_Cocoa::GameLoop()
{
auto cur_ticks = std::chrono::steady_clock::now();
auto last_realtime_tick = cur_ticks;
- auto next_tick = cur_ticks;
+ auto next_game_tick = cur_ticks;
+ auto next_draw_tick = cur_ticks;
for (;;) {
@autoreleasepool {
@@ -672,8 +673,14 @@ void VideoDriver_Cocoa::GameLoop()
last_realtime_tick += delta;
}
- if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode)) {
- next_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
+ if (cur_ticks >= next_game_tick || (_fast_forward && !_pause_mode)) {
+ next_game_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
+
+ ::GameLoop();
+ }
+
+ if (cur_ticks >= next_draw_tick) {
+ next_draw_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
bool old_ctrl_pressed = _ctrl_pressed;
@@ -682,16 +689,15 @@ void VideoDriver_Cocoa::GameLoop()
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
- ::GameLoop();
-
+ InputLoop();
UpdateWindows();
this->CheckPaletteAnim();
+
this->Draw();
- } else {
+ }
+
+ if (!_fast_forward || _pause_mode) {
CSleep(1);
- NetworkDrawChatMessage();
- DrawMouseCursor();
- this->Draw();
}
}
}