summaryrefslogtreecommitdiff
path: root/src/video/video_driver.hpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-16 16:43:11 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-22 22:16:07 +0100
commitd6b67758881ba24d532d42e211a5fddcc1cdd309 (patch)
tree7fe12be86517d23cd4dbc6d4f9def52186e30d0c /src/video/video_driver.hpp
parent73ed748deb65f14f280b8cefebb0a6beff16a4a5 (diff)
downloadopenttd-d6b67758881ba24d532d42e211a5fddcc1cdd309.tar.xz
Change: Lock the video buffer when drawing inside the game loop to properly account for threaded drawing.
Diffstat (limited to 'src/video/video_driver.hpp')
-rw-r--r--src/video/video_driver.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index c52b36029..cc74df202 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -127,6 +127,25 @@ public:
return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
}
+ /**
+ * Helper struct to ensure the video buffer is locked and ready for drawing. The destructor
+ * will make sure the buffer is unlocked no matter how the scope is exited.
+ */
+ struct VideoBufferLocker {
+ VideoBufferLocker()
+ {
+ this->unlock = VideoDriver::GetInstance()->LockVideoBuffer();
+ }
+
+ ~VideoBufferLocker()
+ {
+ if (this->unlock) VideoDriver::GetInstance()->UnlockVideoBuffer();
+ }
+
+ private:
+ bool unlock; ///< Stores if the lock did anything that has to be undone.
+ };
+
protected:
const uint ALLOWED_DRIFT = 5; ///< How many times videodriver can miss deadlines without it being overly compensated.