diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/src/loop.c | 12 |
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; } } |
