mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-11 07:11:39 +00:00
Add FPS counter
This commit is contained in:
parent
19dfc45321
commit
337dea13e6
5 changed files with 59 additions and 3 deletions
|
@ -510,7 +510,7 @@ EXTERN char *palookup[MAXPALOOKUPS];
|
|||
extern uint8_t *basepaltable[MAXBASEPALS];
|
||||
EXTERN uint8_t paletteloaded;
|
||||
EXTERN char *blendtable[MAXBLENDTABS];
|
||||
EXTERN uint8_t whitecol, redcol;
|
||||
EXTERN uint8_t whitecol, redcol, blackcol;
|
||||
|
||||
EXTERN int32_t maxspritesonscreen;
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ palette_t curpalette[256]; // the current palette, unadjusted for brightness o
|
|||
palette_t curpalettefaded[256]; // the current palette, adjusted for brightness and tint (ie. what gets sent to the card)
|
||||
palette_t palfadergb = { 0, 0, 0, 0 };
|
||||
char palfadedelta = 0;
|
||||
uint8_t blackcol;
|
||||
|
||||
int32_t realmaxshade;
|
||||
float frealmaxshade;
|
||||
|
|
|
@ -2002,6 +2002,60 @@ static inline int32_t calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk
|
|||
return clamp(tabledivide64(65536*elapsedFrames*30, rfreq), 0, 65536);
|
||||
}
|
||||
|
||||
int r_showfps;
|
||||
|
||||
#define COLOR_RED redcol
|
||||
#define COLOR_WHITE whitecol
|
||||
|
||||
#define LOW_FPS ((videoGetRenderMode() == REND_CLASSIC) ? 35 : 50)
|
||||
#define SLOW_FRAME_TIME 20
|
||||
|
||||
#if defined GEKKO
|
||||
# define FPS_YOFFSET 16
|
||||
#else
|
||||
# define FPS_YOFFSET 0
|
||||
#endif
|
||||
|
||||
#define FPS_COLOR(x) ((x) ? COLOR_RED : COLOR_WHITE)
|
||||
|
||||
static void G_PrintFPS(void)
|
||||
{
|
||||
static char tempbuf[256];
|
||||
static int32_t frameCount;
|
||||
static double cumulativeFrameDelay;
|
||||
static double lastFrameTime;
|
||||
static float lastFPS, minFPS = std::numeric_limits<float>::max(), maxFPS;
|
||||
static double minGameUpdate = std::numeric_limits<double>::max(), maxGameUpdate;
|
||||
|
||||
double frameTime = timerGetHiTicks();
|
||||
double frameDelay = frameTime - lastFrameTime;
|
||||
cumulativeFrameDelay += frameDelay;
|
||||
|
||||
if (frameDelay >= 0)
|
||||
{
|
||||
int32_t x = (xdim <= 640);
|
||||
|
||||
if (r_showfps)
|
||||
{
|
||||
int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS);
|
||||
|
||||
printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, blackcol, -1, tempbuf, x);
|
||||
printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET,
|
||||
FPS_COLOR(lastFPS < LOW_FPS), -1, tempbuf, x);
|
||||
}
|
||||
|
||||
if (cumulativeFrameDelay >= 1000.0)
|
||||
{
|
||||
lastFPS = 1000.f * frameCount / cumulativeFrameDelay;
|
||||
// g_frameRate = Blrintf(lastFPS);
|
||||
frameCount = 0;
|
||||
cumulativeFrameDelay = 0.0;
|
||||
}
|
||||
frameCount++;
|
||||
}
|
||||
lastFrameTime = frameTime;
|
||||
}
|
||||
|
||||
static void GameDisplay(void)
|
||||
{
|
||||
// End Section B
|
||||
|
@ -2045,6 +2099,8 @@ static void GameDisplay(void)
|
|||
myprintext((320 - nLen) / 2, 100, "PAUSED", 0);
|
||||
}
|
||||
|
||||
G_PrintFPS();
|
||||
|
||||
videoNextPage();
|
||||
}
|
||||
|
||||
|
|
|
@ -210,6 +210,7 @@ enum {
|
|||
};
|
||||
|
||||
extern char g_modDir[BMAX_PATH];
|
||||
extern int r_showfps;
|
||||
|
||||
extern struct grpfile_t const* g_selectedGrp;
|
||||
|
||||
|
|
|
@ -615,7 +615,7 @@ int32_t registerosdcommands(void)
|
|||
|
||||
//{ "r_camrefreshdelay", "minimum delay between security camera sprite updates, 120 = 1 second", (void *)&ud.camera_time, CVAR_INT, 1, 240 },
|
||||
//{ "r_drawweapon", "enable/disable weapon drawing", (void *)&ud.drawweapon, CVAR_INT, 0, 2 },
|
||||
//{ "r_showfps", "show the frame rate counter", (void *)&ud.showfps, CVAR_INT, 0, 3 },
|
||||
{ "r_showfps", "show the frame rate counter", (void *)&r_showfps, CVAR_INT, 0, 3 },
|
||||
//{ "r_showfpsperiod", "time in seconds before averaging min and max stats for r_showfps 2+", (void *)&ud.frameperiod, CVAR_INT, 0, 5 },
|
||||
//{ "r_shadows", "enable/disable sprite and model shadows", (void *)&ud.shadows, CVAR_BOOL, 0, 1 },
|
||||
//{ "r_size", "change size of viewable area", (void *)&ud.screen_size, CVAR_INT|CVAR_FUNCPTR, 0, 64 },
|
||||
|
|
Loading…
Reference in a new issue