summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-03-13 17:16:42 +0000
committeronelin <oscar@nelin.dk>2025-03-13 17:16:42 +0000
commitbb170ff42b30dd44c2352bd2c93ad2974241721c (patch)
tree5db471233793d77d810fafebd2a575d9fb54408a /src
parent02ddad3b34d57924fc4120d7ea633d6aef751027 (diff)
Cap the FPS to fps target
Diffstat (limited to 'src')
-rw-r--r--src/core/src/loop.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/core/src/loop.c b/src/core/src/loop.c
index 1663219..db2033d 100644
--- a/src/core/src/loop.c
+++ b/src/core/src/loop.c
@@ -382,10 +382,16 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) {
render_present(p->window);
const f64 rendertime_dt = get_time() - rendertime_begin;
+ /* Regulate FPS */
+ f64 frame_end = get_time();
+ const f64 fps_diff = fps_cap - (frame_end - now);
+
+ if (fps_cap >= (frame_end - now)) {
+ delay(fps_diff);
+ }
/* Print stats */
- const f64 now = get_time();
- const f64 dt_measurement = now - last_fps_measurement;
+ const f64 dt_measurement = frame_end - last_fps_measurement;
/* only make measurements once a second */
if (dt_measurement > 1000.0) {
@@ -400,7 +406,7 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) {
, rendertime_dt
);
- last_fps_measurement = now;
+ last_fps_measurement = frame_end;
last_fps_ticks = ticks;
}
}