Use double instead of precise_t for FPS counter

Makes the displayed FPS more accurate to what it's actually displaying.

Also removed HUDTRANS from it -- stop it fading out during level transitions, it's annoying when I actually want to see the FPS during those bits.
This commit is contained in:
Sally Coolatta 2022-05-19 16:37:33 -04:00 committed by Eidolon
parent 169f33a101
commit 79f736b75f

View file

@ -454,55 +454,69 @@ boolean SCR_IsAspectCorrect(INT32 width, INT32 height)
double averageFPS = 0.0f; double averageFPS = 0.0f;
#define FPS_SAMPLE_RATE (50000) // How often to update FPS samples, in microseconds #define USE_FPS_SAMPLES
#define NUM_FPS_SAMPLES 16 // Number of samples to store
#ifdef USE_FPS_SAMPLES
#define FPS_SAMPLE_RATE (0.05) // How often to update FPS samples, in seconds
#define NUM_FPS_SAMPLES (16) // Number of samples to store
static double fps_samples[NUM_FPS_SAMPLES]; static double fps_samples[NUM_FPS_SAMPLES];
static double updateElapsed = 0.0;
#endif
static boolean fps_init = false;
static precise_t fps_enter = 0;
void SCR_CalculateFPS(void) void SCR_CalculateFPS(void)
{ {
static boolean init = false; precise_t fps_finish = 0;
static precise_t startTime = 0; double frameElapsed = 0.0;
precise_t endTime = 0;
static precise_t updateTime = 0; if (fps_init == false)
int updateElapsed = 0;
int i;
endTime = I_GetPreciseTime();
if (init == false)
{ {
startTime = updateTime = endTime; fps_enter = I_GetPreciseTime();
init = true; fps_init = true;
return;
} }
updateElapsed = (endTime - updateTime) / (I_GetPrecisePrecision() / 1000000); fps_finish = I_GetPreciseTime();
frameElapsed = (double)((INT64)(fps_finish - fps_enter)) / I_GetPrecisePrecision();
fps_enter = fps_finish;
#ifdef USE_FPS_SAMPLES
updateElapsed += frameElapsed;
if (updateElapsed >= FPS_SAMPLE_RATE) if (updateElapsed >= FPS_SAMPLE_RATE)
{ {
static int sampleIndex = 0; static int sampleIndex = 0;
int frameElapsed = (endTime - startTime) / (I_GetPrecisePrecision() / 1000000); int i;
fps_samples[sampleIndex] = frameElapsed / 1000.0f; fps_samples[sampleIndex] = frameElapsed;
sampleIndex++; sampleIndex++;
if (sampleIndex >= NUM_FPS_SAMPLES) if (sampleIndex >= NUM_FPS_SAMPLES)
sampleIndex = 0; sampleIndex = 0;
averageFPS = 0.0f; averageFPS = 0.0;
for (i = 0; i < NUM_FPS_SAMPLES; i++) for (i = 0; i < NUM_FPS_SAMPLES; i++)
{ {
averageFPS += fps_samples[i]; averageFPS += fps_samples[i];
} }
averageFPS = 1000.0f / (averageFPS / NUM_FPS_SAMPLES);
updateTime = endTime; if (averageFPS > 0.0)
{
averageFPS = 1.0 / (averageFPS / NUM_FPS_SAMPLES);
}
} }
startTime = endTime; while (updateElapsed >= FPS_SAMPLE_RATE)
{
updateElapsed -= FPS_SAMPLE_RATE;
}
#else
// Direct, unsampled counter.
averageFPS = 1.0 / frameElapsed;
#endif
} }
void SCR_DisplayTicRate(void) void SCR_DisplayTicRate(void)