]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/registry.qh
0087c1bf71b77b69cf3513fcb0da62aa42017fed
[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     void Register_##ns##_##id() {                               \
12         entity this = NEW(class);                               \
13         ns##_##id = this;                                       \
14         this.fld = counter;                                     \
15         array[counter++] = this;                                \
16         Register_##ns##_##id##_init(this);                      \
17     }                                                           \
18     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
19     REGISTER_INIT(ns, id)
20
21 void __static_init() { }
22 #define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
23 #define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
24
25 #define STATIC_INIT(func) \
26     void _static_##func(); \
27     ACCUMULATE_FUNCTION(__static_init, _static_##func) \
28     void _static_##func()
29
30 #endif