do not rely on GetTime

This commit is contained in:
maksut 2023-10-14 15:44:42 +01:00
parent 685dcd76c1
commit 28a01aaab7

View File

@ -1230,19 +1230,16 @@ int GetFPS(void)
static int index = 0; static int index = 0;
static float history[FPS_CAPTURE_FRAMES_COUNT] = { 0 }; static float history[FPS_CAPTURE_FRAMES_COUNT] = { 0 };
static float average = 0, last = 0; static float average = 0, wait = 0;
float fpsFrame = GetFrameTime(); float fpsFrame = GetFrameTime();
if (fpsFrame == 0) return 0; if (fpsFrame == 0) return 0;
float newTime = (float)GetTime(); wait += fpsFrame;
if (last > newTime) if (wait > FPS_STEP)
last = newTime; // Last value is from a previous window so reset it
if ((newTime - last) > FPS_STEP)
{ {
last = newTime; wait = 0;
index = (index + 1)%FPS_CAPTURE_FRAMES_COUNT; index = (index + 1)%FPS_CAPTURE_FRAMES_COUNT;
average -= history[index]; average -= history[index];
history[index] = fpsFrame/FPS_CAPTURE_FRAMES_COUNT; history[index] = fpsFrame/FPS_CAPTURE_FRAMES_COUNT;