From e5fe20ad83e01b3c8262ac90af984da47d8a16a1 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 12 Apr 2026 10:48:04 -0700 Subject: Work in terms of time deltas; remove dependency on timer module --- simloop/include/simloop.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'simloop/include') diff --git a/simloop/include/simloop.h b/simloop/include/simloop.h index 1e5b4e0..b08dcac 100644 --- a/simloop/include/simloop.h +++ b/simloop/include/simloop.h @@ -37,35 +37,34 @@ */ #pragma once -#include - #include +typedef uint64_t simloop_time_t; + typedef struct SimloopArgs { - int update_fps; ///< Update frame rate. Must be >0. - int max_render_fps; ///< Render frame rate cap. 0 to disable. - Timer* timer; ///< Timer that drives the simulation. + int update_fps; ///< Update frame rate. Must be >0. + int max_render_fps; ///< Render frame rate cap. 0 to disable. } SimloopArgs; typedef struct SimloopOut { - uint64_t frame; ///< Frame counter. - time_delta render_elapsed; ///< Amount of time elapsed in the rendering. - time_delta update_elapsed; ///< Amount of time elapsed in the simulation. - time_delta update_dt; ///< Delta time for simulation updates. - bool should_update; ///< Whether the simulation should update. - bool should_render; ///< Whether the simulation should be rendered. + uint64_t frame; ///< Frame counter. + simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. + simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. + simloop_time_t update_dt; ///< Delta time for simulation updates. + bool should_update; ///< Whether the simulation should update. + bool should_render; ///< Whether the simulation should be rendered. } SimloopOut; typedef struct SimloopTimeline { - time_delta ddt; ///< Desired delta time. - time_point last_step; ///< Time of the last simulation step. + simloop_time_t ddt; ///< Desired delta time. + simloop_time_t time; ///< Time point of the last simulation step. } SimloopTimeline; typedef struct Simloop { + simloop_time_t clock; ///< Tracks simulation time. + uint64_t frame; ///< Frame counter, number of updates done. SimloopTimeline update; ///< Update timeline. SimloopTimeline render; ///< Render timeline. - uint64_t frame; ///< Frame counter. - Timer* timer; bool first_iter; bool updates_since_last_render; } Simloop; @@ -76,4 +75,4 @@ Simloop simloop_make(const SimloopArgs*); /// Step the simulation loop. /// /// The simulation always triggers a render of the initial state of simulation. -void simloop_update(Simloop*, SimloopOut*); +void simloop_update(Simloop*, simloop_time_t dt, SimloopOut*); -- cgit v1.2.3