]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/registry.qh
Objectify gametypes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / registry.qh
1 #ifndef REGISTRY_H
2 #define REGISTRY_H
3
4 #include "util.qh"
5
6 #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
7
8 #define REGISTER(initfunc, ns, array, counter, id, class, fld)  \
9     entity ns##_##id;                                           \
10     REGISTER_INIT(ns, id) { }                                   \
11     .entity enemy; /* internal next pointer */                  \
12     void Register_##ns##_##id() {                               \
13         entity this = NEW(class);                               \
14         ns##_##id = this;                                       \
15         this.fld = counter;                                     \
16         array[counter++] = this;                                \
17         if (!array##_first)    array##_first = this;            \
18         if ( array##_last)     array##_last.enemy = this;       \
19         array##_last = this;                                    \
20         Register_##ns##_##id##_init(this);                      \
21     }                                                           \
22     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
23     REGISTER_INIT(ns, id)
24
25 void __static_init() { }
26 #define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
27 #define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
28
29 #define STATIC_INIT(func) \
30     void _static_##func(); \
31     ACCUMULATE_FUNCTION(__static_init, _static_##func) \
32     void _static_##func()
33
34 #endif