Improve FPS tracking

This commit is contained in:
MysterD 2023-11-22 00:00:06 -08:00
parent 44e5a252f3
commit 39a95ff6d0
1 changed files with 13 additions and 8 deletions

View File

@ -76,9 +76,6 @@ f64 gGameSpeed = 1.0f; // TODO: should probably remove
static const f64 sFrameTime = (1.0 / ((double)FRAMERATE)); static const f64 sFrameTime = (1.0 / ((double)FRAMERATE));
static f64 sFrameTargetTime = 0; static f64 sFrameTargetTime = 0;
static f64 sFrameTimeStart; static f64 sFrameTimeStart;
static f64 sLastFrameTimeStart;
static f32 sAvgFrames = 1;
static f32 sAvgFps = 0;
bool gGameInited = false; bool gGameInited = false;
bool gGfxInited = false; bool gGfxInited = false;
@ -187,14 +184,22 @@ void produce_interpolation_frames_and_delay(void) {
frames++; frames++;
} }
f32 fps = frames / (clock_elapsed_f64() - sFrameTimeStart); static u64 sFramesSinceFpsUpdate = 0;
sAvgFps = sAvgFps * 0.95 + fps * 0.05; static u64 sLastFpsUpdateTime = 0;
sAvgFrames = sAvgFrames * 0.9 + frames * 0.1;
sFramesSinceFpsUpdate += frames;
u64 sCurrentFpsUpdateTime = (u64)clock_elapsed_f64();
if (sLastFpsUpdateTime != sCurrentFpsUpdateTime) {
u32 fps = sFramesSinceFpsUpdate / ((f32)(sCurrentFpsUpdateTime - sLastFpsUpdateTime));
sLastFpsUpdateTime = sCurrentFpsUpdateTime;
sFramesSinceFpsUpdate = 0;
//printf("fps: %u\n", fps);
}
sFrameTimeStart = sFrameTargetTime; sFrameTimeStart = sFrameTargetTime;
sFrameTargetTime += sFrameTime * gGameSpeed; sFrameTargetTime += sFrameTime * gGameSpeed;
gRenderingInterpolated = false; gRenderingInterpolated = false;
//printf(">>> fpt: %llu, fps: %f :: %f\n", frames, sAvgFps, fps);
} }
inline static void buffer_audio(void) { inline static void buffer_audio(void) {