fix up old fps counter

This commit is contained in:
Alug committed 2024-10-02 12:14:31 +02:00
1 parent b87074c5f6
commit b775095b67
1 file changed
+30 -12
+30 -12
View File
@@ -369,15 +369,13 @@ double averageFPS = 0.0f;
#define USE_FPS_SAMPLES
#ifdef USE_FPS_SAMPLES
#define MAX_FRAME_TIME 0.05
#define MAX_FRAME_TIME (0.05)
#define NUM_FPS_SAMPLES (16) // Number of samples to store
#define NUM_FPS_SAMPLES2 (32) // Number of samples to store for inaccurate counter
static double total_frame_time = 0.0;
static int frame_index;
static double fps_samples[NUM_FPS_SAMPLES2];
static int fps_index;
static double fps_samples[NUM_FPS_SAMPLES];
#endif
static boolean fps_init = false;
@@ -386,7 +384,6 @@ static precise_t fps_enter = 0;
void SCR_CalculateFPS(void)
{
precise_t fps_finish = 0;
int i;
double frameElapsed = 0.0;
@@ -401,7 +398,6 @@ void SCR_CalculateFPS(void)
fps_enter = fps_finish;
#ifdef USE_FPS_SAMPLES
if (cv_accuratefps.value)
{
total_frame_time += frameElapsed;
@@ -414,13 +410,35 @@ void SCR_CalculateFPS(void)
}
else
{
fps_samples[fps_index] = frameElapsed / NUM_FPS_SAMPLES2;
fps_index = (fps_index + 1) % NUM_FPS_SAMPLES2;
total_frame_time += frameElapsed;
averageFPS = 0.0;
for (i = 0; i < NUM_FPS_SAMPLES2; i++)
averageFPS += fps_samples[i];
averageFPS = 1.0 / averageFPS;
if (total_frame_time >= MAX_FRAME_TIME)
{
static int sampleIndex = 0;
int i;
fps_samples[sampleIndex] = frameElapsed;
sampleIndex++;
if (sampleIndex >= NUM_FPS_SAMPLES)
sampleIndex = 0;
averageFPS = 0.0;
for (i = 0; i < NUM_FPS_SAMPLES; i++)
{
averageFPS += fps_samples[i];
}
if (averageFPS > 0.0)
{
averageFPS = 1.0 / (averageFPS / NUM_FPS_SAMPLES);
}
}
while (total_frame_time >= MAX_FRAME_TIME)
{
total_frame_time -= MAX_FRAME_TIME;
}
}
#else
// Direct, unsampled counter.