mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 04:11:18 +00:00
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:
parent
507211b94e
commit
a4090db7b9
1 changed files with 41 additions and 27 deletions
68
src/screen.c
68
src/screen.c
|
@ -402,55 +402,69 @@ boolean SCR_IsAspectCorrect(INT32 width, INT32 height)
|
|||
|
||||
double averageFPS = 0.0f;
|
||||
|
||||
#define FPS_SAMPLE_RATE (50000) // How often to update FPS samples, in microseconds
|
||||
#define NUM_FPS_SAMPLES 16 // Number of samples to store
|
||||
#define USE_FPS_SAMPLES
|
||||
|
||||
#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 updateElapsed = 0.0;
|
||||
#endif
|
||||
|
||||
static boolean fps_init = false;
|
||||
static precise_t fps_enter = 0;
|
||||
|
||||
void SCR_CalculateFPS(void)
|
||||
{
|
||||
static boolean init = false;
|
||||
precise_t fps_finish = 0;
|
||||
|
||||
static precise_t startTime = 0;
|
||||
precise_t endTime = 0;
|
||||
double frameElapsed = 0.0;
|
||||
|
||||
static precise_t updateTime = 0;
|
||||
int updateElapsed = 0;
|
||||
int i;
|
||||
|
||||
endTime = I_GetPreciseTime();
|
||||
|
||||
if (init == false)
|
||||
if (fps_init == false)
|
||||
{
|
||||
startTime = updateTime = endTime;
|
||||
init = true;
|
||||
return;
|
||||
fps_enter = I_GetPreciseTime();
|
||||
fps_init = true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
static int sampleIndex = 0;
|
||||
int frameElapsed = (endTime - startTime) / (I_GetPrecisePrecision() / 1000000);
|
||||
int i;
|
||||
|
||||
fps_samples[sampleIndex] = frameElapsed / 1000.0f;
|
||||
fps_samples[sampleIndex] = frameElapsed;
|
||||
|
||||
sampleIndex++;
|
||||
if (sampleIndex >= NUM_FPS_SAMPLES)
|
||||
sampleIndex = 0;
|
||||
|
||||
averageFPS = 0.0f;
|
||||
averageFPS = 0.0;
|
||||
for (i = 0; i < NUM_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)
|
||||
|
@ -459,10 +473,10 @@ void SCR_DisplayTicRate(void)
|
|||
UINT32 cap = R_GetFramerateCap();
|
||||
UINT32 benchmark = (cap == 0) ? I_GetRefreshRate() : cap;
|
||||
INT32 x = 318;
|
||||
double fps = ceil(averageFPS);
|
||||
double fps = round(averageFPS);
|
||||
|
||||
// draw "FPS"
|
||||
V_DrawFixedPatch(306<<FRACBITS, 183<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, framecounter, R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_YELLOW, GTC_CACHE));
|
||||
V_DrawFixedPatch(306<<FRACBITS, 183<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT, framecounter, R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_YELLOW, GTC_CACHE));
|
||||
|
||||
if (fps > (benchmark - 5))
|
||||
ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE);
|
||||
|
@ -481,15 +495,15 @@ void SCR_DisplayTicRate(void)
|
|||
}
|
||||
|
||||
// draw total frame:
|
||||
V_DrawPingNum(x, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, cap, ticcntcolor);
|
||||
V_DrawPingNum(x, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT, cap, ticcntcolor);
|
||||
x -= digits * 4;
|
||||
|
||||
// draw "/"
|
||||
V_DrawFixedPatch(x<<FRACBITS, 190<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, frameslash, ticcntcolor);
|
||||
V_DrawFixedPatch(x<<FRACBITS, 190<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT, frameslash, ticcntcolor);
|
||||
}
|
||||
|
||||
// draw our actual framerate
|
||||
V_DrawPingNum(x, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, fps, ticcntcolor);
|
||||
V_DrawPingNum(x, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT, fps, ticcntcolor);
|
||||
}
|
||||
|
||||
// SCR_DisplayLocalPing
|
||||
|
|
Loading…
Reference in a new issue