fix up old fps counter
This commit is contained in:
1 parent
31516c7987
commit
dfb6006f9c
1 file changed
+30
-12
+30
-12
@@ -366,15 +366,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;
|
||||
@@ -383,7 +381,6 @@ static precise_t fps_enter = 0;
|
||||
void SCR_CalculateFPS(void)
|
||||
{
|
||||
precise_t fps_finish = 0;
|
||||
int i;
|
||||
|
||||
double frameElapsed = 0.0;
|
||||
|
||||
@@ -398,7 +395,6 @@ void SCR_CalculateFPS(void)
|
||||
fps_enter = fps_finish;
|
||||
|
||||
#ifdef USE_FPS_SAMPLES
|
||||
|
||||
if (cv_accuratefps.value)
|
||||
{
|
||||
total_frame_time += frameElapsed;
|
||||
@@ -411,13 +407,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.
|
||||
|
||||
Reference in new issue
Block a user