scr_showfps implementation

This commit is contained in:
Ian 2022-06-19 14:00:57 -04:00
parent c04d0f0c9a
commit 3b7c00d0e9

View file

@ -80,6 +80,7 @@ float scr_con_current;
float scr_conlines; // lines of console to display float scr_conlines; // lines of console to display
float oldscreensize, oldfov; float oldscreensize, oldfov;
cvar_t scr_viewsize = {"viewsize","100", true}; cvar_t scr_viewsize = {"viewsize","100", true};
cvar_t scr_fov = {"fov","90"}; // 10 - 170 cvar_t scr_fov = {"fov","90"}; // 10 - 170
cvar_t scr_conspeed = {"scr_conspeed","300"}; cvar_t scr_conspeed = {"scr_conspeed","300"};
@ -88,6 +89,8 @@ cvar_t scr_showram = {"showram","1"};
cvar_t scr_showturtle = {"showturtle","0"}; cvar_t scr_showturtle = {"showturtle","0"};
cvar_t scr_showpause = {"showpause","1"}; cvar_t scr_showpause = {"showpause","1"};
cvar_t scr_printspeed = {"scr_printspeed","8"}; cvar_t scr_printspeed = {"scr_printspeed","8"};
cvar_t scr_showfps = {"scr_showfps", "0"};
cvar_t gl_triplebuffer = {"gl_triplebuffer", "1", true }; cvar_t gl_triplebuffer = {"gl_triplebuffer", "1", true };
extern cvar_t crosshair; extern cvar_t crosshair;
@ -378,6 +381,8 @@ void SCR_Init (void)
Cvar_RegisterVariable (&scr_showpause); Cvar_RegisterVariable (&scr_showpause);
Cvar_RegisterVariable (&scr_centertime); Cvar_RegisterVariable (&scr_centertime);
Cvar_RegisterVariable (&scr_printspeed); Cvar_RegisterVariable (&scr_printspeed);
Cvar_RegisterVariable (&scr_showfps);
Cvar_RegisterVariable (&gl_triplebuffer); Cvar_RegisterVariable (&gl_triplebuffer);
// //
@ -394,7 +399,49 @@ void SCR_Init (void)
scr_initialized = true; scr_initialized = true;
} }
//============================================================================
/*
==============
SCR_DrawFPS -- johnfitz
==============
*/
void SCR_DrawFPS (void)
{
static double oldtime = 0;
static double lastfps = 0;
static int oldframecount = 0;
double elapsed_time;
int frames;
elapsed_time = realtime - oldtime;
frames = r_framecount - oldframecount;
if (elapsed_time < 0 || frames < 0)
{
oldtime = realtime;
oldframecount = r_framecount;
return;
}
// update value every 3/4 second
if (elapsed_time > 0.75)
{
lastfps = frames / elapsed_time;
oldtime = realtime;
oldframecount = r_framecount;
}
if (scr_showfps.value)
{
char st[16];
int x, y;
sprintf (st, "%4.0f fps", lastfps);
x = 320 - (strlen(st)<<3);
y = 200 - 8;
Draw_String (0, 0, st);
}
}
/* /*
============== ==============
@ -912,6 +959,7 @@ void SCR_UpdateScreen (void)
SCR_DrawPause (); SCR_DrawPause ();
SCR_CheckDrawCenterString (); SCR_CheckDrawCenterString ();
Sbar_Draw (); Sbar_Draw ();
SCR_DrawFPS ();
SCR_DrawConsole (); SCR_DrawConsole ();
M_Draw (); M_Draw ();
} }