1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Don't sleep in FramerateManager::framerateDelay() if VSync is enabled

This commit is contained in:
Alexander Wilms
2023-09-26 17:28:44 +02:00
parent 23d1638d70
commit bfa5ef7990
2 changed files with 13 additions and 5 deletions

View File

@@ -11,22 +11,28 @@
#include "StdInc.h"
#include "FramerateManager.h"
#include "../../lib/CConfigHandler.h"
FramerateManager::FramerateManager(int targetFrameRate)
: targetFrameTime(Duration(boost::chrono::seconds(1)) / targetFrameRate)
, lastFrameIndex(0)
, lastFrameTimes({})
, lastTimePoint (Clock::now())
, lastTimePoint(Clock::now())
, vsyncEnabled(settings["video"]["vsync"].Bool())
{
boost::range::fill(lastFrameTimes, targetFrameTime);
}
void FramerateManager::framerateDelay()
{
if(!vsyncEnabled)
{
Duration timeSpentBusy = Clock::now() - lastTimePoint;
// FPS is higher than it should be, then wait some time
if(timeSpentBusy < targetFrameTime)
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
}
// compute actual timeElapsed taking into account actual sleep interval
// limit it to 100 ms to avoid breaking animation in case of huge lag (e.g. triggered breakpoint)

View File

@@ -25,6 +25,8 @@ class FramerateManager
/// index of last measured frome in lastFrameTimes array
ui32 lastFrameIndex;
bool vsyncEnabled;
public:
FramerateManager(int targetFramerate);