|
@@ -15,22 +15,12 @@
|
|
|
#include <SDL_video.h>
|
|
|
|
|
|
FramerateManager::FramerateManager(int targetFrameRate)
|
|
|
- : lastFrameIndex(0)
|
|
|
+ : targetFrameTime(Duration(boost::chrono::seconds(1)) / targetFrameRate)
|
|
|
+ , lastFrameIndex(0)
|
|
|
, lastFrameTimes({})
|
|
|
, lastTimePoint(Clock::now())
|
|
|
+ , vsyncEnabled(settings["video"]["vsync"].Bool())
|
|
|
{
|
|
|
- if(settings["video"]["vsync"].Bool())
|
|
|
- {
|
|
|
- static int display_in_use = settings["video"]["displayIndex"].Integer();
|
|
|
- SDL_DisplayMode mode;
|
|
|
- SDL_GetCurrentDisplayMode(display_in_use, &mode);
|
|
|
- int displayRefreshRate = mode.refresh_rate;
|
|
|
- logGlobal->info("Display refresh rate is %d", displayRefreshRate);
|
|
|
- targetFrameTime = Duration(boost::chrono::seconds(1)) / displayRefreshRate;
|
|
|
- } else
|
|
|
- {
|
|
|
- targetFrameTime = Duration(boost::chrono::seconds(1)) / targetFrameRate;
|
|
|
- }
|
|
|
boost::range::fill(lastFrameTimes, targetFrameTime);
|
|
|
}
|
|
|
|
|
@@ -38,9 +28,14 @@ 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)
|
|
|
+ {
|
|
|
+ // if 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)
|