Skip to content
Snippets Groups Projects
Commit 4ccba2a9 authored by Sal's avatar Sal
Browse files

Merge branch 'fix-inaccurate-fps-counter' into 'next'

Fix inaccuracies in FPS counter

Closes #1047

See merge request STJr/SRB2!2047
parents 08c6e76d e3824b9f
No related branches found
No related tags found
No related merge requests found
...@@ -478,11 +478,11 @@ double averageFPS = 0.0f; ...@@ -478,11 +478,11 @@ double averageFPS = 0.0f;
#define USE_FPS_SAMPLES #define USE_FPS_SAMPLES
#ifdef USE_FPS_SAMPLES #ifdef USE_FPS_SAMPLES
#define FPS_SAMPLE_RATE (0.05) // How often to update FPS samples, in seconds #define MAX_FRAME_TIME 0.05
#define NUM_FPS_SAMPLES (16) // Number of samples to store #define NUM_FPS_SAMPLES (16) // Number of samples to store
static double fps_samples[NUM_FPS_SAMPLES]; static double total_frame_time = 0.0;
static double updateElapsed = 0.0; static int frame_index;
#endif #endif
static boolean fps_init = false; static boolean fps_init = false;
...@@ -505,34 +505,12 @@ void SCR_CalculateFPS(void) ...@@ -505,34 +505,12 @@ void SCR_CalculateFPS(void)
fps_enter = fps_finish; fps_enter = fps_finish;
#ifdef USE_FPS_SAMPLES #ifdef USE_FPS_SAMPLES
updateElapsed += frameElapsed; total_frame_time += frameElapsed;
if (frame_index++ >= NUM_FPS_SAMPLES || total_frame_time >= MAX_FRAME_TIME)
if (updateElapsed >= FPS_SAMPLE_RATE)
{
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 (updateElapsed >= FPS_SAMPLE_RATE)
{ {
updateElapsed -= FPS_SAMPLE_RATE; averageFPS = 1.0 / (total_frame_time / frame_index);
total_frame_time = 0.0;
frame_index = 0;
} }
#else #else
// Direct, unsampled counter. // Direct, unsampled counter.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment