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:
@@ -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())
|
||||
, 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)
|
||||
|
@@ -25,6 +25,8 @@ class FramerateManager
|
||||
/// index of last measured frome in lastFrameTimes array
|
||||
ui32 lastFrameIndex;
|
||||
|
||||
bool vsyncEnabled;
|
||||
|
||||
public:
|
||||
FramerateManager(int targetFramerate);
|
||||
|
||||
|
Reference in New Issue
Block a user