Change: Lock the video buffer when drawing inside the game loop to properly account for threaded drawing.

This commit is contained in:
Michael Lutz
2021-01-16 16:43:11 +01:00
parent 73ed748deb
commit d6b6775888
4 changed files with 75 additions and 50 deletions

View File

@@ -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.