summaryrefslogtreecommitdiff
path: root/src/video/sdl2_v.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video/sdl2_v.cpp')
-rw-r--r--src/video/sdl2_v.cpp54
1 files changed, 2 insertions, 52 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index 7c406b677..0ff0a4673 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -786,42 +786,7 @@ void VideoDriver_SDL::LoopOnce()
return;
}
- cur_ticks = std::chrono::steady_clock::now();
-
- /* If more than a millisecond has passed, increase the _realtime_tick. */
- if (cur_ticks - last_realtime_tick > std::chrono::milliseconds(1)) {
- auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(cur_ticks - last_realtime_tick);
- _realtime_tick += delta.count();
- last_realtime_tick += delta;
- }
-
- if (cur_ticks >= next_game_tick || (_fast_forward && !_pause_mode)) {
- if (_fast_forward && !_pause_mode) {
- next_game_tick = cur_ticks + this->GetGameInterval();
- } else {
- next_game_tick += this->GetGameInterval();
- /* Avoid next_game_tick getting behind more and more if it cannot keep up. */
- if (next_game_tick < cur_ticks - ALLOWED_DRIFT * this->GetGameInterval()) next_game_tick = cur_ticks;
- }
-
- /* The gameloop is the part that can run asynchronously. The rest
- * except sleeping can't. */
- this->UnlockVideoBuffer();
- GameLoop();
- this->LockVideoBuffer();
- }
-
- /* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
- if (cur_ticks >= next_draw_tick && (_switch_mode == SM_NONE || HasModalProgress())) {
- next_draw_tick += this->GetDrawInterval();
- /* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
- if (next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) next_draw_tick = cur_ticks;
-
- this->InputLoop();
- ::InputLoop();
- UpdateWindows();
- this->CheckPaletteAnim();
-
+ if (VideoDriver::Tick()) {
if (_draw_mutex != nullptr && !HasModalProgress()) {
_draw_signal->notify_one();
} else {
@@ -832,27 +797,12 @@ void VideoDriver_SDL::LoopOnce()
/* Emscripten is running an event-based mainloop; there is already some
* downtime between each iteration, so no need to sleep. */
#ifndef __EMSCRIPTEN__
- /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
- if (!_fast_forward || _pause_mode) {
- /* 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 (next_tick > now) {
- this->UnlockVideoBuffer();
- std::this_thread::sleep_for(next_tick - now);
- this->LockVideoBuffer();
- }
- }
+ this->SleepTillNextTick();
#endif
}
void VideoDriver_SDL::MainLoop()
{
- cur_ticks = std::chrono::steady_clock::now();
- last_realtime_tick = cur_ticks;
- next_game_tick = cur_ticks;
-
if (_draw_threaded) {
/* Initialise the mutex first, because that's the thing we *need*
* directly in the newly created thread. */