#pragma once #include typedef uint64_t simloop_time_t; ///< Time delta in nanoseconds. typedef struct SimloopArgs { 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. simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. simloop_time_t update_dt; ///< Delta time for simulation updates. simloop_time_t throttle; ///< Render throttle if max render fps is given. double percent_frame; ///< Percent progress between this frame and ///< the next. Used for smooth animation. bool should_update; ///< Whether the simulation should update. } SimloopOut; typedef struct SimloopTimeline { 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. simloop_time_t render_ddt; ///< Desired render delta time. } Simloop; /// Create a simulation loop. 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*, simloop_time_t dt, SimloopOut*);