Check FPS cap further in the main loop

This allows map changes to properly run. (I also seem to be able to hit the framerate cap slightly more often ... maybe placebo lol)
This commit is contained in:
Sally Coolatta 2022-03-27 13:17:26 -04:00
parent 12353c2d6f
commit c0678e5016
4 changed files with 62 additions and 51 deletions

View file

@ -679,6 +679,29 @@ static void D_Display(void)
}
}
static boolean D_CheckFrameCap(void)
{
static boolean init = false;
static precise_t startCap = 0;
precise_t endCap = 0;
endCap = I_GetPreciseTime();
if (init == false)
{
startCap = endCap;
init = true;
}
else if (I_CheckFrameCap(startCap, endCap))
{
// Framerate should be capped.
return true;
}
startCap = endCap;
return false;
}
// =========================================================================
// D_SRB2Loop
// =========================================================================
@ -762,18 +785,11 @@ void D_SRB2Loop(void)
#endif
interp = R_UsingFrameInterpolation();
if (interp)
if (!realtics && !singletics && !interp)
{
if (I_CheckFrameCap())
continue;
}
else
{
if (!realtics && !singletics)
{
I_Sleep();
continue;
}
// Non-interp sleep
I_Sleep();
continue;
}
#ifdef HW3SOUND
@ -788,31 +804,43 @@ void D_SRB2Loop(void)
// process tics (but maybe not if realtic == 0)
ticked = TryRunTics(realtics);
if (interp && !(paused || P_AutoPause()))
if (interp)
{
static float tictime = 0.0f;
static float prevtime = 0.0f;
float entertime = I_GetTimeFrac();
fixed_t entertimefrac;
if (!(paused || P_AutoPause()))
{
static float tictime = 0.0f;
static float prevtime = 0.0f;
float entertime = I_GetTimeFrac();
fixed_t entertimefrac;
if (ticked)
tictime = entertime;
if (ticked)
tictime = entertime;
if (entertime - prevtime >= 1.0f) // Lagged for more frames than a gametic... shut off interpolation.
entertimefrac = FRACUNIT;
else
entertimefrac = min(FRACUNIT, FLOAT_TO_FIXED(entertime - tictime));
if (entertime - prevtime >= 1.0f) // Lagged for more frames than a gametic... shut off interpolation.
entertimefrac = FRACUNIT;
else
entertimefrac = min(FRACUNIT, FLOAT_TO_FIXED(entertime - tictime));
prevtime = entertime;
prevtime = entertime;
// renderdeltatics is a bit awkard to evaluate, since the system time interface is whole tic-based
renderdeltatics = realtics * FRACUNIT;
if (entertimefrac > rendertimefrac)
renderdeltatics += entertimefrac - rendertimefrac;
else
renderdeltatics -= rendertimefrac - entertimefrac;
// renderdeltatics is a bit awkard to evaluate, since the system time interface is whole tic-based
renderdeltatics = realtics * FRACUNIT;
if (entertimefrac > rendertimefrac)
renderdeltatics += entertimefrac - rendertimefrac;
else
renderdeltatics -= rendertimefrac - entertimefrac;
rendertimefrac = entertimefrac;
rendertimefrac = entertimefrac;
}
// Handle interp sleep / framerate cap here.
// TryRunTics needs ran if possible to prevent lagged map changes,
// (and if that runs, the code above needs to also run)
// so this is done here after TryRunTics.
if (D_CheckFrameCap())
{
continue;
}
}
else
{

View file

@ -237,7 +237,7 @@ static CV_PossibleValue_t teamscramble_cons_t[] = {{0, "Off"}, {1, "Random"}, {2
static CV_PossibleValue_t startingliveslimit_cons_t[] = {{1, "MIN"}, {99, "MAX"}, {0, NULL}};
static CV_PossibleValue_t sleeping_cons_t[] = {{-1, "MIN"}, {1000/TICRATE, "MAX"}, {0, NULL}};
static CV_PossibleValue_t sleeping_cons_t[] = {{0, "MIN"}, {1000/TICRATE, "MAX"}, {0, NULL}};
static CV_PossibleValue_t pause_cons_t[] = {{0, "Server"}, {1, "All"}, {0, NULL}};

View file

@ -64,7 +64,7 @@ int I_PreciseToMicros(precise_t d);
*/
void I_Sleep(void);
boolean I_CheckFrameCap(void);
boolean I_CheckFrameCap(precise_t start, precise_t end);
/** \brief Get events

View file

@ -1701,32 +1701,16 @@ void I_Sleep(void)
SDL_Delay(cv_sleep.value);
}
boolean I_CheckFrameCap(void)
boolean I_CheckFrameCap(precise_t start, precise_t end)
{
static boolean init = false;
static precise_t start = 0;
precise_t end;
int elapsed;
UINT32 capFrames = R_GetFramerateCap();
int capMicros = 0;
end = I_GetPreciseTime();
if (init == false)
{
// Just initialized.
start = end;
init = true;
return false;
}
int elapsed;
if (capFrames == 0)
{
// We don't want to cap.
start = end;
return false;
}
@ -1760,7 +1744,6 @@ boolean I_CheckFrameCap(void)
}
// Waited enough to draw again.
start = end;
return false;
}