3 /** Components always interpolate from the previous state */
4 #define COMPONENT(com) \
5 void com_##com##_interpolate(entity it, float a); \
8 #define FOREACH_COMPONENT(com, body) FOREACH_ENTITY_FLOAT(com_##com, true, body)
11 #define EVENT(T, args) .bool evt_##T##_listener; .void args evt_##T
13 #define emit(T, ...) \
15 FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \
18 #define subscribe(listener, T, fn) \
20 listener.evt_##T = (fn); \
21 listener.evt_##T##_listener = true; \
26 * framelimit 0 is no limit, interpolation does not apply
27 * framerate below minfps will result in less than 100% speed
29 #define SYSTEM(sys, frameLimit, minfps) \
30 void sys_##sys##_update(entity this, float dt); \
31 noref float autocvar_xon_sys_##sys##_dt = ((frameLimit) ? (1 / (frameLimit)) : 0); \
32 noref float autocvar_xon_sys_##sys##_minfps = (1 / (1 / (minfps)))
34 #define SYSTEM_UPDATE(sys) \
37 float dt = autocvar_xon_sys_##sys##_dt; \
38 float minfps = autocvar_xon_sys_##sys##_minfps; \
39 static float accumulator = 0; \
42 accumulator += min(frametime, 1 / (minfps)); \
44 accumulator += frametime; \
48 while (accumulator >= dt) \
51 FOREACH_COMPONENT(sys, sys_##sys##_update(it, dt)); \
55 if (!a) a = accumulator / dt; \
56 FOREACH_COMPONENT(sys, com_##sys##_interpolate(it, a)); \