summaryrefslogtreecommitdiff
path: root/src/video/win32_v.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video/win32_v.cpp')
-rw-r--r--src/video/win32_v.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 2fe5f67f0..42fcf3f4b 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -1258,13 +1258,20 @@ void VideoDriver_Win32::MainLoop()
CheckPaletteAnim();
}
+ /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
if (!_fast_forward || _pause_mode) {
- /* Flush GDI buffer to ensure we don't conflict with the drawing thread. */
- GdiFlush();
+ /* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
+ auto next_tick = std::min(next_draw_tick, next_game_tick);
+ auto now = std::chrono::steady_clock::now();
- if (_draw_mutex != nullptr) draw_lock.unlock();
- CSleep(1);
- if (_draw_mutex != nullptr) draw_lock.lock();
+ if (next_tick > now) {
+ /* Flush GDI buffer to ensure we don't conflict with the drawing thread. */
+ GdiFlush();
+
+ if (_draw_mutex != nullptr) draw_lock.unlock();
+ std::this_thread::sleep_for(next_tick - now);
+ if (_draw_mutex != nullptr) draw_lock.lock();
+ }
}
}