Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / Registry.qh
1 #ifndef REGISTRY_H
2 #define REGISTRY_H
3
4 #include "OO.qh"
5
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)
8
9 #define REGISTER(initfunc, ns, array, counter, id, fld, inst)   \
10     entity ns##_##id;                                           \
11     REGISTER_INIT(ns, id) { }                                   \
12     REGISTER_INIT_POST(ns, id) { }                              \
13     .entity enemy; /* internal next pointer */                  \
14     void Register_##ns##_##id() {                               \
15         entity this = inst;                                     \
16         ns##_##id = this;                                       \
17         this.fld = counter;                                     \
18         array[counter++] = this;                                \
19         if (!array##_first)    array##_first = this;            \
20         if ( array##_last)     array##_last.enemy = this;       \
21         array##_last = this;                                    \
22         Register_##ns##_##id##_init(this);                      \
23         Register_##ns##_##id##_init_post(this);                 \
24     }                                                           \
25     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
26     REGISTER_INIT(ns, id)
27
28 #endif