Another attempt at improving/fixing the fps limiter

git-svn-id: https://svn.eduke32.com/eduke32@7954 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-08-12 03:15:29 +00:00 committed by Christoph Oelckers
parent 755de405c2
commit 620f0da65b
2 changed files with 11 additions and 18 deletions

View file

@ -6326,30 +6326,23 @@ int G_FPSLimit(void)
if (!r_maxfps)
return 1;
static double nextPageDelay = g_frameDelay;
uint64_t const delay = llrint(nextPageDelay);
static double nextPageDelay;
static uint64_t lastFrameTicks;
uint64_t const frameTicks = timerGetTicksU64();
uint64_t const frameDelay = (uint64_t)llrint(g_frameDelay);
uint64_t const frameTicks = timerGetTicksU64();
int64_t const elapsedTime = frameTicks - lastFrameTicks;
static uint64_t lastFrameTicks = frameTicks - frameDelay;
uint64_t elapsedTime = frameTicks-lastFrameTicks;
int frameWaiting = 0;
if (elapsedTime >= delay)
if (elapsedTime >= lrint(floor(nextPageDelay)))
{
//If we missed a frame, reset any cumulated remainder from rendering frames early
if (elapsedTime > frameDelay)
nextPageDelay = g_frameDelay;
else
nextPageDelay += double(frameDelay-elapsedTime);
if (elapsedTime <= lrint(floor(nextPageDelay + g_frameDelay)))
nextPageDelay = nearbyint(nextPageDelay + g_frameDelay - (double)elapsedTime);
lastFrameTicks = frameTicks;
++frameWaiting;
return 1;
}
return frameWaiting;
return 0;
}
// TODO: reorder (net)actor_t to eliminate slop and update assertion

View file

@ -349,7 +349,7 @@ extern palette_t CrosshairColors;
extern palette_t DefaultCrosshairColors;
extern double g_frameDelay;
static inline double calcFrameDelay(int maxFPS) { return maxFPS > 0 ? ((double)timerGetFreqU64() / (double)(maxFPS)) : 0.0; }
static inline double calcFrameDelay(int const maxFPS) { return maxFPS > 0 ? nearbyint((double)timerGetFreqU64()/maxFPS) : 0.0; }
int32_t A_CheckInventorySprite(spritetype *s);
int32_t A_InsertSprite(int16_t whatsect, int32_t s_x, int32_t s_y, int32_t s_z, int16_t s_pn, int8_t s_s, uint8_t s_xr,