diff options
author | Patric Stout <truebrain@openttd.org> | 2021-02-20 10:49:27 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-02-20 17:08:44 +0100 |
commit | 761efbb4571397fe9e5f19049ca64663e12cbc1e (patch) | |
tree | 4eaa9b3380305f16999d7cd0c13b506d621a3c45 /src/video/sdl2_v.cpp | |
parent | 661eb39ecc3a128c24dbbc4f53d1c075fe89bc93 (diff) | |
download | openttd-761efbb4571397fe9e5f19049ca64663e12cbc1e.tar.xz |
Codechange: use (Un)LockVideoBuffer() to manage video buffer
Diffstat (limited to 'src/video/sdl2_v.cpp')
-rw-r--r-- | src/video/sdl2_v.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index b02beacef..8bee575e2 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -801,9 +801,9 @@ void VideoDriver_SDL::LoopOnce() /* The gameloop is the part that can run asynchronously. The rest * except sleeping can't. */ - if (_draw_mutex != nullptr) draw_lock.unlock(); + this->UnlockVideoBuffer(); GameLoop(); - if (_draw_mutex != nullptr) draw_lock.lock(); + this->LockVideoBuffer(); } /* Prevent drawing when switching mode, as windows can be removed when they should still appear. */ @@ -834,9 +834,9 @@ void VideoDriver_SDL::LoopOnce() auto now = std::chrono::steady_clock::now(); if (next_tick > now) { - if (_draw_mutex != nullptr) draw_lock.unlock(); + this->UnlockVideoBuffer(); std::this_thread::sleep_for(next_tick - now); - if (_draw_mutex != nullptr) draw_lock.lock(); + this->LockVideoBuffer(); } } #endif @@ -986,3 +986,14 @@ Dimension VideoDriver_SDL::GetScreenSize() const return { static_cast<uint>(mode.w), static_cast<uint>(mode.h) }; } + +bool VideoDriver_SDL::LockVideoBuffer() +{ + if (_draw_threaded) this->draw_lock.lock(); + return true; +} + +void VideoDriver_SDL::UnlockVideoBuffer() +{ + if (_draw_threaded) this->draw_lock.unlock(); +} |