aboutsummaryrefslogtreecommitdiff
path: root/simloop/include/simloop.h
diff options
context:
space:
mode:
Diffstat (limited to 'simloop/include/simloop.h')
-rw-r--r--simloop/include/simloop.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/simloop/include/simloop.h b/simloop/include/simloop.h
new file mode 100644
index 0000000..6a83b23
--- /dev/null
+++ b/simloop/include/simloop.h
@@ -0,0 +1,40 @@
1#pragma once
2
3#include <stdint.h>
4
5typedef uint64_t simloop_time_t; ///< Time delta in nanoseconds.
6
7typedef struct SimloopArgs {
8 int update_fps; ///< Update frame rate. Must be >0.
9 int max_render_fps; ///< Render frame rate cap. 0 to disable.
10} SimloopArgs;
11
12typedef struct SimloopOut {
13 uint64_t frame; ///< Frame counter.
14 simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation.
15 simloop_time_t update_dt; ///< Delta time for simulation updates.
16 simloop_time_t throttle; ///< Render throttle if max render fps is given.
17 double percent_frame; ///< Percent progress between this frame and
18 ///< the next. Used for smooth animation.
19 bool should_update; ///< Whether the simulation should update.
20} SimloopOut;
21
22typedef struct SimloopTimeline {
23 simloop_time_t ddt; ///< Desired delta time.
24 simloop_time_t time; ///< Time point of the last simulation step.
25} SimloopTimeline;
26
27typedef struct Simloop {
28 simloop_time_t clock; ///< Tracks simulation time.
29 uint64_t frame; ///< Frame counter, number of updates done.
30 SimloopTimeline update; ///< Update timeline.
31 simloop_time_t render_ddt; ///< Desired render delta time.
32} Simloop;
33
34/// Create a simulation loop.
35Simloop simloop_make(const SimloopArgs*);
36
37/// Step the simulation loop.
38///
39/// The simulation always triggers a render of the initial state of simulation.
40void simloop_update(Simloop*, simloop_time_t dt, SimloopOut*);