1 /** Components always interpolate from the previous state */
2 #define COMPONENT(com) \
3 void com_##com##_interpolate(entity it, float a); \
6 #define FOREACH_COMPONENT(com, body) FOREACH_ENTITY_FLOAT(com_##com, true, body)
9 #define EVENT(T, args) .bool evt_##T##_listener; .void args evt_##T
11 #define emit(T, ...) \
13 FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \
16 #define subscribe(listener, T) \
18 listener.evt_##T##_listener = true; \
23 * framelimit 0 is no limit, interpolation does not apply
24 * framerate below minfps will result in less than 100% speed
26 #define SYSTEM(sys, frameLimit, minfps) \
27 void sys_##sys##_update(entity this, float dt); \
28 float autocvar_xon_sys_##sys##_dt = ((frameLimit) ? (1 / (frameLimit)) : 0); \
29 float autocvar_xon_sys_##sys##_minfps = (1 / (1 / (minfps)))
31 #define SYSTEM_UPDATE(sys) \
34 float dt = autocvar_xon_sys_##sys##_dt; \
35 float minfps = autocvar_xon_sys_##sys##_minfps; \
36 static float accumulator = 0; \
39 accumulator += min(frametime, 1 / (minfps)); \
41 accumulator += frametime; \
45 while (accumulator >= dt) \
48 FOREACH_COMPONENT(sys, sys_##sys##_update(it, dt)); \
52 if (!a) a = accumulator / dt; \
53 FOREACH_COMPONENT(sys, com_##sys##_interpolate(it, a)); \
58 #include "components/_mod.inc"
59 #include "events/_mod.inc"
60 #include "systems/_mod.inc"