diff options
Diffstat (limited to 'simloop/include')
| -rw-r--r-- | simloop/include/simloop.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/simloop/include/simloop.h b/simloop/include/simloop.h new file mode 100644 index 0000000..f267d40 --- /dev/null +++ b/simloop/include/simloop.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* Simulation loop module. | ||
| 2 | * | ||
| 3 | * This implements a simulation loop but in a way that the client retains | ||
| 4 | * control flow. The client steps the loop and then checks whether the | ||
| 5 | * simulation must be updated and/or the result rendered. | ||
| 6 | */ | ||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <timer.h> | ||
| 10 | |||
| 11 | #include <stdint.h> | ||
| 12 | |||
| 13 | typedef struct SimloopArgs { | ||
| 14 | int update_fps; ///< Update frame rate. Must be >0. | ||
| 15 | int max_render_fps; ///< Render frame rate cap. 0 to disable. | ||
| 16 | Timer* timer; ///< Timer that drives the simulation. | ||
| 17 | } SimloopArgs; | ||
| 18 | |||
| 19 | typedef struct SimloopOut { | ||
| 20 | uint64_t frame; ///< Frame counter. | ||
| 21 | time_delta render_elapsed; ///< Amount of time elapsed in the rendering. | ||
| 22 | time_delta update_elapsed; ///< Amount of time elapsed in the simulation. | ||
| 23 | time_delta update_dt; ///< Delta time for simulation updates. | ||
| 24 | int updates_pending; ///< Number of frames the simulation should produce. | ||
| 25 | bool should_render; ///< Whether the simulation should be rendered. | ||
| 26 | } SimloopOut; | ||
| 27 | |||
| 28 | typedef struct SimloopTimeline { | ||
| 29 | time_delta ddt; ///< Desired delta time. | ||
| 30 | time_point last_step; ///< Time of the last simulation step. | ||
| 31 | } SimloopTimeline; | ||
| 32 | |||
| 33 | typedef struct Simloop { | ||
| 34 | SimloopTimeline update; ///< Update timeline. | ||
| 35 | SimloopTimeline render; ///< Render timeline. | ||
| 36 | uint64_t frame; ///< Frame counter. | ||
| 37 | Timer* timer; | ||
| 38 | } Simloop; | ||
| 39 | |||
| 40 | /// Create a simulation loop. | ||
| 41 | Simloop simloop_make(const SimloopArgs*); | ||
| 42 | |||
| 43 | /// Step the simulation loop. | ||
| 44 | void simloop_update(Simloop*, SimloopOut*); | ||
