diff options
| author | 3gg <3gg@shellblade.net> | 2026-04-12 10:48:04 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-04-12 10:48:04 -0700 |
| commit | e5fe20ad83e01b3c8262ac90af984da47d8a16a1 (patch) | |
| tree | ffb55eabccc2018cb0359dc054fdadebfc815d65 /simloop/include | |
| parent | 9dceaee478545ed8df89722f5c90bb171de100e8 (diff) | |
Work in terms of time deltas; remove dependency on timer module
Diffstat (limited to 'simloop/include')
| -rw-r--r-- | simloop/include/simloop.h | 31 |
1 files changed, 15 insertions, 16 deletions
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 @@ | |||
| 37 | */ | 37 | */ |
| 38 | #pragma once | 38 | #pragma once |
| 39 | 39 | ||
| 40 | #include <timer.h> | ||
| 41 | |||
| 42 | #include <stdint.h> | 40 | #include <stdint.h> |
| 43 | 41 | ||
| 42 | typedef uint64_t simloop_time_t; | ||
| 43 | |||
| 44 | typedef struct SimloopArgs { | 44 | typedef struct SimloopArgs { |
| 45 | int update_fps; ///< Update frame rate. Must be >0. | 45 | int update_fps; ///< Update frame rate. Must be >0. |
| 46 | int max_render_fps; ///< Render frame rate cap. 0 to disable. | 46 | int max_render_fps; ///< Render frame rate cap. 0 to disable. |
| 47 | Timer* timer; ///< Timer that drives the simulation. | ||
| 48 | } SimloopArgs; | 47 | } SimloopArgs; |
| 49 | 48 | ||
| 50 | typedef struct SimloopOut { | 49 | typedef struct SimloopOut { |
| 51 | uint64_t frame; ///< Frame counter. | 50 | uint64_t frame; ///< Frame counter. |
| 52 | time_delta render_elapsed; ///< Amount of time elapsed in the rendering. | 51 | simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. |
| 53 | time_delta update_elapsed; ///< Amount of time elapsed in the simulation. | 52 | simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. |
| 54 | time_delta update_dt; ///< Delta time for simulation updates. | 53 | simloop_time_t update_dt; ///< Delta time for simulation updates. |
| 55 | bool should_update; ///< Whether the simulation should update. | 54 | bool should_update; ///< Whether the simulation should update. |
| 56 | bool should_render; ///< Whether the simulation should be rendered. | 55 | bool should_render; ///< Whether the simulation should be rendered. |
| 57 | } SimloopOut; | 56 | } SimloopOut; |
| 58 | 57 | ||
| 59 | typedef struct SimloopTimeline { | 58 | typedef struct SimloopTimeline { |
| 60 | time_delta ddt; ///< Desired delta time. | 59 | simloop_time_t ddt; ///< Desired delta time. |
| 61 | time_point last_step; ///< Time of the last simulation step. | 60 | simloop_time_t time; ///< Time point of the last simulation step. |
| 62 | } SimloopTimeline; | 61 | } SimloopTimeline; |
| 63 | 62 | ||
| 64 | typedef struct Simloop { | 63 | typedef struct Simloop { |
| 64 | simloop_time_t clock; ///< Tracks simulation time. | ||
| 65 | uint64_t frame; ///< Frame counter, number of updates done. | ||
| 65 | SimloopTimeline update; ///< Update timeline. | 66 | SimloopTimeline update; ///< Update timeline. |
| 66 | SimloopTimeline render; ///< Render timeline. | 67 | SimloopTimeline render; ///< Render timeline. |
| 67 | uint64_t frame; ///< Frame counter. | ||
| 68 | Timer* timer; | ||
| 69 | bool first_iter; | 68 | bool first_iter; |
| 70 | bool updates_since_last_render; | 69 | bool updates_since_last_render; |
| 71 | } Simloop; | 70 | } Simloop; |
| @@ -76,4 +75,4 @@ Simloop simloop_make(const SimloopArgs*); | |||
| 76 | /// Step the simulation loop. | 75 | /// Step the simulation loop. |
| 77 | /// | 76 | /// |
| 78 | /// The simulation always triggers a render of the initial state of simulation. | 77 | /// The simulation always triggers a render of the initial state of simulation. |
| 79 | void simloop_update(Simloop*, SimloopOut*); | 78 | void simloop_update(Simloop*, simloop_time_t dt, SimloopOut*); |
