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 "StdInc.h"
|
||||||
#include "FramerateManager.h"
|
#include "FramerateManager.h"
|
||||||
|
|
||||||
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
|
||||||
FramerateManager::FramerateManager(int targetFrameRate)
|
FramerateManager::FramerateManager(int targetFrameRate)
|
||||||
: targetFrameTime(Duration(boost::chrono::seconds(1)) / targetFrameRate)
|
: targetFrameTime(Duration(boost::chrono::seconds(1)) / targetFrameRate)
|
||||||
, lastFrameIndex(0)
|
, lastFrameIndex(0)
|
||||||
, lastFrameTimes({})
|
, lastFrameTimes({})
|
||||||
, lastTimePoint (Clock::now())
|
, lastTimePoint(Clock::now())
|
||||||
|
, vsyncEnabled(settings["video"]["vsync"].Bool())
|
||||||
{
|
{
|
||||||
boost::range::fill(lastFrameTimes, targetFrameTime);
|
boost::range::fill(lastFrameTimes, targetFrameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramerateManager::framerateDelay()
|
void FramerateManager::framerateDelay()
|
||||||
{
|
{
|
||||||
Duration timeSpentBusy = Clock::now() - lastTimePoint;
|
if(!vsyncEnabled)
|
||||||
|
{
|
||||||
|
Duration timeSpentBusy = Clock::now() - lastTimePoint;
|
||||||
|
|
||||||
// FPS is higher than it should be, then wait some time
|
// FPS is higher than it should be, then wait some time
|
||||||
if(timeSpentBusy < targetFrameTime)
|
if(timeSpentBusy < targetFrameTime)
|
||||||
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
|
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
|
||||||
|
}
|
||||||
|
|
||||||
// compute actual timeElapsed taking into account actual sleep interval
|
// 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)
|
// 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
|
/// index of last measured frome in lastFrameTimes array
|
||||||
ui32 lastFrameIndex;
|
ui32 lastFrameIndex;
|
||||||
|
|
||||||
|
bool vsyncEnabled;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FramerateManager(int targetFramerate);
|
FramerateManager(int targetFramerate);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user