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:
2026-08-23 17:43:51 +02:00
parent 55055a042d
commit 5ad0ddfbc0
4 changed files with 64 additions and 2 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ INPUT_SRC = src/platform/client/input/sdl.c
.include "config.mk" .include "config.mk"
ENGINE_SRCS = src/skele.c ${CLOCK_SRC} ENGINE_SRCS = src/skele.c src/fps.c ${CLOCK_SRC}
SOFT_PLAT_SRCS = src/platform/client/video/sdl.c ${INPUT_SRC} SOFT_PLAT_SRCS = src/platform/client/video/sdl.c ${INPUT_SRC}
GL_PLAT_SRCS = src/platform/client/video/gl.c ${INPUT_SRC} GL_PLAT_SRCS = src/platform/client/video/gl.c ${INPUT_SRC}
SOFT_CLIENT_SRCS = example/client/main.c SOFT_CLIENT_SRCS = example/client/main.c
+1 -1
View File
@@ -8,7 +8,7 @@ endif
include config.mk include config.mk
ENGINE_SRCS := src/skele.c $(CLOCK_SRC) ENGINE_SRCS := src/skele.c src/fps.c $(CLOCK_SRC)
SOFT_PLAT_SRCS := src/platform/client/video/sdl.c $(INPUT_SRC) SOFT_PLAT_SRCS := src/platform/client/video/sdl.c $(INPUT_SRC)
GL_PLAT_SRCS := src/platform/client/video/gl.c $(INPUT_SRC) GL_PLAT_SRCS := src/platform/client/video/gl.c $(INPUT_SRC)
SOFT_CLIENT_SRCS := example/client/main.c SOFT_CLIENT_SRCS := example/client/main.c
+21
View File
@@ -0,0 +1,21 @@
#ifndef SKELE_FPS_H
#define SKELE_FPS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern float skele_fps;
extern float skele_frame_time_ms;
extern float skele_frame_budget_ms;
void skele_fps_init(void);
void skele_fps_frame_mark(void);
#ifdef __cplusplus
}
#endif
#endif /* SKELE_FPS_H */
+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;
}
}