Backport new FPS limiter

# Conflicts:
#	source/rr/src/game.cpp
This commit is contained in:
nukeykt 2019-08-10 04:51:31 +09:00 committed by Christoph Oelckers
parent f87f38b8f0
commit fbd3bdb665

View file

@ -2918,24 +2918,27 @@ double g_frameDelay = 0.0;
int viewFPSLimit(void) int viewFPSLimit(void)
{ {
if (!r_maxfps)
return 1;
static double nextPageDelay = g_frameDelay; static double nextPageDelay = g_frameDelay;
static uint64_t lastFrameTicks = timerGetTicksU64() - (uint64_t) g_frameDelay; uint64_t const delay = llrint(nextPageDelay);
int frameWaiting = 0;
uint64_t const frameTicks = timerGetTicksU64(); uint64_t const frameTicks = timerGetTicksU64();
uint64_t const frameDelay = (uint64_t)llrint(g_frameDelay);
static uint64_t lastFrameTicks = frameTicks - frameDelay;
uint64_t elapsedTime = frameTicks-lastFrameTicks; uint64_t elapsedTime = frameTicks-lastFrameTicks;
if (!r_maxfps || elapsedTime >= (uint64_t) nextPageDelay) int frameWaiting = 0;
{
if (elapsedTime >= (uint64_t) (nextPageDelay + g_frameDelay)) if (elapsedTime >= delay)
{ {
//If we missed a frame, reset any cumulated remainder from rendering frames early //If we missed a frame, reset any cumulated remainder from rendering frames early
if (elapsedTime > frameDelay)
nextPageDelay = g_frameDelay; nextPageDelay = g_frameDelay;
}
else else
{ nextPageDelay += double(frameDelay-elapsedTime);
nextPageDelay += g_frameDelay - elapsedTime;
}
lastFrameTicks = frameTicks; lastFrameTicks = frameTicks;
++frameWaiting; ++frameWaiting;