Modified show FPS algorithm to show average frames over the course of one second and only updates text display at that time.

This commit is contained in:
mjbudd77 2021-10-08 21:53:16 -04:00
parent b69043bbf0
commit fcfddba64b
2 changed files with 37 additions and 12 deletions

View File

@ -724,28 +724,52 @@ bool FCEUI_ShowFPS()
} }
void FCEUI_SetShowFPS(bool showFPS) void FCEUI_SetShowFPS(bool showFPS)
{ {
if ( Show_FPS != showFPS )
{
ResetFPS();
}
Show_FPS = showFPS; Show_FPS = showFPS;
} }
void FCEUI_ToggleShowFPS() void FCEUI_ToggleShowFPS()
{ {
Show_FPS ^= 1; Show_FPS ^= 1;
ResetFPS();
} }
static uint64 boop[60]; static uint64 boop_ts = 0;
static int boopcount = 0; static unsigned int boopcount = 0;
void ResetFPS(void)
{
boop_ts = 0;
boopcount = 0;
}
void ShowFPS(void) void ShowFPS(void)
{ {
if(Show_FPS == false) if (Show_FPS == false)
{
return; return;
}
static char fpsmsg[16] = { 0 };
uint64 ts = FCEUD_GetTime(); uint64 ts = FCEUD_GetTime();
uint64 da = ts - boop[boopcount]; uint64 da;
char fpsmsg[16];
int booplimit = PAL?50:60; if ( boop_ts == 0 )
boop[boopcount] = ts; {
boop_ts = ts;
}
da = ts - boop_ts;
if ( da > FCEUD_GetTimeFreq() )
{
sprintf(fpsmsg, "%.1f", (double)boopcount / ((double)da / FCEUD_GetTimeFreq()));
boopcount = 0;
boop_ts = ts;
}
boopcount++;
sprintf(fpsmsg, "%.1f", (double)booplimit / ((double)da / FCEUD_GetTimeFreq()));
DrawTextTrans(XBuf + ((256 - ClipSidesOffset) - 40) + (FSettings.FirstSLine + 4) * 256, 256, (uint8*)fpsmsg, 0xA0); DrawTextTrans(XBuf + ((256 - ClipSidesOffset) - 40) + (FSettings.FirstSLine + 4) * 256, 256, (uint8*)fpsmsg, 0xA0);
// It's not averaging FPS over exactly 1 second, but it's close enough.
boopcount = (boopcount + 1) % booplimit;
} }

View File

@ -37,6 +37,7 @@ void FCEUI_SetSnapshotAsName(std::string name);
bool FCEUI_ShowFPS(); bool FCEUI_ShowFPS();
void FCEUI_SetShowFPS(bool showFPS); void FCEUI_SetShowFPS(bool showFPS);
void FCEUI_ToggleShowFPS(); void FCEUI_ToggleShowFPS();
void ShowFPS(); void ShowFPS(void);
void snapAVI(); void ResetFPS(void);
void snapAVI(void);
#endif #endif