mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +00:00
game.cpp: improve G_FPSLimit() to be more stable with regard to floating point precision.
Additionally, prefer rendering early and compensating with a late frame due to clock precision rather than the other way around so that we are more consistently within a target vblank period. git-svn-id: https://svn.eduke32.com/eduke32@7731 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
19c2c690d3
commit
b014ae4d54
1 changed files with 15 additions and 6 deletions
|
@ -6137,17 +6137,26 @@ void G_MaybeAllocPlayer(int32_t pnum)
|
|||
|
||||
int G_FPSLimit(void)
|
||||
{
|
||||
static auto nextPageTicks = (double)timerGetTicksU64();
|
||||
static double nextPageDelay = g_frameDelay;
|
||||
static uint64_t lastFrameTicks = timerGetTicksU64() - (uint64_t) g_frameDelay;
|
||||
int frameWaiting = 0;
|
||||
|
||||
auto const frameTicks = (double)timerGetTicksU64();
|
||||
uint64_t const frameTicks = timerGetTicksU64();
|
||||
uint64_t elapsedTime = frameTicks-lastFrameTicks;
|
||||
|
||||
if (!r_maxfps || frameTicks >= nextPageTicks)
|
||||
if (!r_maxfps || elapsedTime >= (uint64_t) nextPageDelay)
|
||||
{
|
||||
if (frameTicks >= nextPageTicks + g_frameDelay)
|
||||
nextPageTicks = frameTicks;
|
||||
if (elapsedTime >= (uint64_t) (nextPageDelay + g_frameDelay))
|
||||
{
|
||||
//If we missed a frame, reset any cumulated remainder from rendering frames early
|
||||
nextPageDelay = g_frameDelay;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextPageDelay += g_frameDelay - elapsedTime;
|
||||
}
|
||||
|
||||
nextPageTicks += g_frameDelay;
|
||||
lastFrameTicks = frameTicks;
|
||||
++frameWaiting;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue