feat: add fps module for rolling frame/fps diagnostics

Real-time 1-second rolling window, independent of tick rate or
display refresh.
This commit is contained in:
anth64 committed 2026-08-23 17:43:51 +02:00
1 parent 55055a042d
commit 5ad0ddfbc0
4 files changed
+64 -2

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#include "fps.h"
#include "clock.h"
float skele_fps = 0.0f;
float skele_frame_time_ms = 0.0f;
float skele_frame_budget_ms = 0.0f;
static uint64_t win_start = 0;
static uint64_t last_frame_ns = 0;
static uint64_t frame_ns_accum = 0;
static uint32_t frame_count = 0;
void skele_fps_init(void)
{
win_start = skele_time_ns();
last_frame_ns = win_start;
frame_ns_accum = 0;
frame_count = 0;
skele_fps = 0.0f;
skele_frame_time_ms = 0.0f;
}
void skele_fps_frame_mark(void)
{
uint64_t now = skele_time_ns();
frame_ns_accum += now - last_frame_ns;
last_frame_ns = now;
frame_count++;
if (now - win_start >= 1000000000ULL) {
double elapsed_s = (double)(now - win_start) / 1e9;
skele_fps = (float)(frame_count / elapsed_s);
skele_frame_time_ms =
(float)((frame_ns_accum / (double)frame_count) / 1e6);
win_start = now;
frame_ns_accum = 0;
frame_count = 0;
}
}