mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'hanicef-fps-counter' into 'master'
Fix inaccuracies in FPS counter See merge request KartKrew/Kart!1456
This commit is contained in:
commit
70207076c1
1 changed files with 8 additions and 30 deletions
38
src/screen.c
38
src/screen.c
|
|
@ -531,11 +531,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;
|
||||||
|
|
@ -558,34 +558,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;
|
averageFPS = 1.0 / (total_frame_time / frame_index);
|
||||||
int i;
|
total_frame_time = 0.0;
|
||||||
|
frame_index = 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Direct, unsampled counter.
|
// Direct, unsampled counter.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue