|
@@ -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()
|
|
|
{
|
|
|
- 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);
|
|
|
+ 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)
|