mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Draw framerate counter properly in uncapped
This commit is contained in:
parent
3e227654c7
commit
225590b7ba
4 changed files with 82 additions and 14 deletions
|
|
@ -56,7 +56,7 @@ precise_t I_GetPreciseTime(void);
|
|||
|
||||
/** \brief Returns the difference between precise times as microseconds.
|
||||
*/
|
||||
int I_PreciseToMicros(precise_t);
|
||||
int I_PreciseToMicros(precise_t d);
|
||||
|
||||
/** \brief The I_Sleep function
|
||||
|
||||
|
|
|
|||
77
src/screen.c
77
src/screen.c
|
|
@ -453,9 +453,46 @@ boolean SCR_IsAspectCorrect(INT32 width, INT32 height)
|
|||
|
||||
// XMOD FPS display
|
||||
// moved out of os-specific code for consistency
|
||||
static boolean fpsgraph[TICRATE];
|
||||
static boolean ticsgraph[TICRATE];
|
||||
static tic_t lasttic;
|
||||
|
||||
static UINT32 fpstime = 0;
|
||||
static UINT32 lastupdatetime = 0;
|
||||
|
||||
#define FPSUPDATERATE 1/20 // What fraction of a second to update at. The fraction will not simplify to 0, trust me.
|
||||
#define FPSMAXSAMPLES 16
|
||||
|
||||
static UINT32 fpssamples[FPSMAXSAMPLES];
|
||||
static UINT32 fpssampleslen = 0;
|
||||
static UINT32 fpssum = 0;
|
||||
double aproxfps = 0.0f;
|
||||
|
||||
void SCR_CalcAproxFps(void)
|
||||
{
|
||||
tic_t i = 0;
|
||||
if (I_PreciseToMicros(fpstime - lastupdatetime) > 1000000 * FPSUPDATERATE)
|
||||
{
|
||||
if (fpssampleslen == FPSMAXSAMPLES)
|
||||
{
|
||||
fpssum -= fpssamples[0];
|
||||
|
||||
for (i = 1; i < fpssampleslen; i++)
|
||||
fpssamples[i-1] = fpssamples[i];
|
||||
}
|
||||
else
|
||||
fpssampleslen++;
|
||||
|
||||
fpssamples[fpssampleslen-1] = I_GetPreciseTime() - fpstime;
|
||||
fpssum += fpssamples[fpssampleslen-1];
|
||||
|
||||
aproxfps = 1000000 / (I_PreciseToMicros(fpssum) / (double)fpssampleslen);
|
||||
|
||||
lastupdatetime = I_GetPreciseTime();
|
||||
}
|
||||
|
||||
fpstime = I_GetPreciseTime();
|
||||
}
|
||||
|
||||
void SCR_DisplayTicRate(void)
|
||||
{
|
||||
tic_t i;
|
||||
|
|
@ -464,25 +501,51 @@ void SCR_DisplayTicRate(void)
|
|||
const UINT8 *ticcntcolor = NULL;
|
||||
|
||||
for (i = lasttic + 1; i < TICRATE+lasttic && i < ontic; ++i)
|
||||
fpsgraph[i % TICRATE] = false;
|
||||
ticsgraph[i % TICRATE] = false;
|
||||
|
||||
fpsgraph[ontic % TICRATE] = true;
|
||||
ticsgraph[ontic % TICRATE] = true;
|
||||
|
||||
for (i = 0;i < TICRATE;++i)
|
||||
if (fpsgraph[i])
|
||||
if (ticsgraph[i])
|
||||
++totaltics;
|
||||
|
||||
if (totaltics <= TICRATE/2) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE);
|
||||
else if (totaltics == TICRATE) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE);
|
||||
|
||||
// draw "FPS"
|
||||
V_DrawFixedPatch(306<<FRACBITS, 183<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, framecounter, R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_YELLOW, GTC_CACHE));
|
||||
|
||||
if (cv_frameinterpolation.value == 1)
|
||||
{
|
||||
if (aproxfps <= 15.0f) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE);
|
||||
else if (aproxfps >= 60.0f) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE);
|
||||
|
||||
/*
|
||||
if (cv_fpscap.value != 0)
|
||||
{
|
||||
// draw total frame:
|
||||
//V_DrawPingNum(318, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, cv_fpscap.value, ticcntcolor);
|
||||
// draw "/"
|
||||
//V_DrawFixedPatch(306<<FRACBITS, 190<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, frameslash, ticcntcolor);
|
||||
// draw our actual framerate
|
||||
V_DrawPingNum(306, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, aproxfps, ticcntcolor);
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
// draw our actual framerate
|
||||
V_DrawPingNum(318, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, aproxfps, ticcntcolor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (totaltics <= 15) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE);
|
||||
else if (totaltics >= TICRATE) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE);
|
||||
|
||||
// draw total frame:
|
||||
V_DrawPingNum(318, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, TICRATE, ticcntcolor);
|
||||
// draw "/"
|
||||
V_DrawFixedPatch(306<<FRACBITS, 190<<FRACBITS, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, frameslash, ticcntcolor);
|
||||
// draw our actual framerate
|
||||
V_DrawPingNum(306, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS, totaltics, ticcntcolor);
|
||||
}
|
||||
|
||||
|
||||
lasttic = ontic;
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ extern boolean R_SSE2;
|
|||
extern viddef_t vid;
|
||||
extern INT32 setmodeneeded; // mode number to set if needed, or 0
|
||||
extern UINT8 setrenderneeded;
|
||||
extern double aproxfps;
|
||||
|
||||
void SCR_ChangeRenderer(void);
|
||||
|
||||
|
|
@ -213,6 +214,8 @@ void SCR_CheckDefaultMode(void);
|
|||
// Set the mode number which is saved in the config
|
||||
void SCR_SetDefaultMode(void);
|
||||
|
||||
void SCR_CalcAproxFps(void);
|
||||
|
||||
FUNCMATH boolean SCR_IsAspectCorrect(INT32 width, INT32 height);
|
||||
|
||||
// move out to main code for consistency
|
||||
|
|
|
|||
|
|
@ -1292,6 +1292,8 @@ void I_FinishUpdate(void)
|
|||
if (I_SkipFrame())
|
||||
return;
|
||||
|
||||
SCR_CalcAproxFps();
|
||||
|
||||
if (st_overlay)
|
||||
{
|
||||
if (cv_ticrate.value)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue