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