mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Fix freezing of hero and long enemy turns without sleeping in FramerateManager::framerateDelay()
This commit is contained in:
parent
0d11c5197d
commit
f52562eeb7
@ -129,11 +129,10 @@ void CGuiHandler::renderFrame()
|
|||||||
|
|
||||||
CCS->curh->render();
|
CCS->curh->render();
|
||||||
|
|
||||||
SDL_RenderPresent(mainRenderer);
|
|
||||||
|
|
||||||
windows().onFrameRendered();
|
windows().onFrameRendered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_RenderPresent(mainRenderer);
|
||||||
framerate().framerateDelay(); // holds a constant FPS
|
framerate().framerateDelay(); // holds a constant FPS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,22 +15,12 @@
|
|||||||
#include <SDL_video.h>
|
#include <SDL_video.h>
|
||||||
|
|
||||||
FramerateManager::FramerateManager(int targetFrameRate)
|
FramerateManager::FramerateManager(int targetFrameRate)
|
||||||
: lastFrameIndex(0)
|
: targetFrameTime(Duration(boost::chrono::seconds(1)) / targetFrameRate)
|
||||||
|
, lastFrameIndex(0)
|
||||||
, lastFrameTimes({})
|
, lastFrameTimes({})
|
||||||
, lastTimePoint(Clock::now())
|
, 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);
|
boost::range::fill(lastFrameTimes, targetFrameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +28,14 @@ void FramerateManager::framerateDelay()
|
|||||||
{
|
{
|
||||||
Duration timeSpentBusy = Clock::now() - lastTimePoint;
|
Duration timeSpentBusy = Clock::now() - lastTimePoint;
|
||||||
|
|
||||||
// FPS is higher than it should be, then wait some time
|
if(!vsyncEnabled)
|
||||||
if(timeSpentBusy < targetFrameTime)
|
{
|
||||||
boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
|
// 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
|
// 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);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user