always cap FPS to 1000

This commit is contained in:
RSDuck 2020-12-04 00:00:35 +01:00
parent 906521e7e9
commit 42e083960e
1 changed files with 15 additions and 15 deletions

View File

@ -495,24 +495,24 @@ void EmuThread::run()
double frametimeStep = nlines / (60.0 * 263.0); double frametimeStep = nlines / (60.0 * 263.0);
{ {
bool limitfps = Config::LimitFPS && !fastforward;
double practicalFramelimit = limitfps ? frametimeStep : 1.0 / 1000.0;
double curtime = SDL_GetPerformanceCounter() * perfCountsSec; double curtime = SDL_GetPerformanceCounter() * perfCountsSec;
bool limitfps = Config::LimitFPS && !fastforward; frameLimitError += practicalFramelimit - (curtime - lastTime);
if (limitfps) if (frameLimitError < -practicalFramelimit)
frameLimitError = -practicalFramelimit;
if (frameLimitError > practicalFramelimit)
frameLimitError = practicalFramelimit;
if (round(frameLimitError * 1000.0) > 0.0)
{ {
frameLimitError += frametimeStep - (curtime - lastTime); SDL_Delay(round(frameLimitError * 1000.0));
if (frameLimitError < -frametimeStep) double timeBeforeSleep = curtime;
frameLimitError = -frametimeStep; curtime = SDL_GetPerformanceCounter() * perfCountsSec;
if (frameLimitError > frametimeStep) frameLimitError -= curtime - timeBeforeSleep;
frameLimitError = frametimeStep;
if (round(frameLimitError * 1000.0) > 0.0)
{
SDL_Delay(round(frameLimitError * 1000.0));
double timeBeforeSleep = curtime;
curtime = SDL_GetPerformanceCounter() * perfCountsSec;
frameLimitError -= curtime - timeBeforeSleep;
}
} }
lastTime = curtime; lastTime = curtime;