From 564a68f1a71e2c61097a71107b4da9827290e7c5 Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 9 Aug 2019 09:28:34 +0000 Subject: [PATCH] Improve frame limiter logic git-svn-id: https://svn.eduke32.com/eduke32@7935 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/game.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 6d8f6ec1c..968ebf094 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -6323,24 +6323,27 @@ void G_MaybeAllocPlayer(int32_t pnum) int G_FPSLimit(void) { + if (!r_maxfps) + return 1; + static double nextPageDelay = g_frameDelay; - static uint64_t lastFrameTicks = timerGetTicksU64() - (uint64_t) g_frameDelay; - int frameWaiting = 0; + uint64_t const delay = llrint(nextPageDelay); 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; - if (!r_maxfps || elapsedTime >= (uint64_t) nextPageDelay) + int frameWaiting = 0; + + if (elapsedTime >= delay) { - if (elapsedTime >= (uint64_t) (nextPageDelay + g_frameDelay)) - { - //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; - } else - { - nextPageDelay += g_frameDelay - elapsedTime; - } + nextPageDelay += double(frameDelay-elapsedTime); lastFrameTicks = frameTicks; ++frameWaiting;