6 #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
7 #define REGISTER_INIT_POST(ns, id) [[accumulate]] void Register_##ns##_##id##_init_post(entity this)
10 * Register a new entity with a global constructor.
11 * Must be followed by a semicolon or a function body with a `this` parameter.
12 * Wrapper macros may perform actions after user initialization like so:
13 * #define REGISTER_FOO(id) \
14 * REGISTER(RegisterFoos, FOO, FOOS, FOOS_COUNT, id, m_id, NEW(Foo)); \
15 * REGISTER_INIT_POST(FOO, id) { \
16 * print("Registering foo #", this.m_id - 1, "\n"); \
18 * REGISTER_INIT(FOO, id)
20 * @param initfunc The global constructor to accumulate into
21 * @param ns Short for namespace, prefix for each global (ns##_##id)
22 * @param array The array to add each entity to. Also requires `array##_first` and `array##_last` to be defined
23 * @param counter Global to count number of entries
24 * @param id The identifier of the current entity being registered
25 * @param fld This field to store the current count into
26 * @param inst An expression to create a new instance, invoked for every registration
28 #define REGISTER(initfunc, ns, array, counter, id, fld, inst) \
30 REGISTER_INIT(ns, id) { } \
31 REGISTER_INIT_POST(ns, id) { } \
32 .entity enemy; /* internal next pointer */ \
33 void Register_##ns##_##id() { \
37 array[counter++] = this; \
38 if (!array##_first) array##_first = this; \
39 if ( array##_last) array##_last.enemy = this; \
40 array##_last = this; \
41 Register_##ns##_##id##_init(this); \
42 Register_##ns##_##id##_init_post(this); \
44 ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \