]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/registry.qh
Merge branch 'maint' of https://gitlab.com/xonotic/xonotic-data.pk3dir into maint
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / registry.qh
1 #ifndef REGISTRY_H
2 #define REGISTRY_H
3
4 #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
5
6 #define REGISTER(initfunc, ns, array, counter, id, class, fld)  \
7     entity ns##_##id;                                           \
8     REGISTER_INIT(ns, id) { }                                   \
9     void Register_##ns##_##id() {                               \
10         entity this = NEW(class);                               \
11         ns##_##id = this;                                       \
12         this.fld = counter;                                     \
13         array[counter++] = this;                                \
14         Register_##ns##_##id##_init(this);                      \
15     }                                                           \
16     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
17     REGISTER_INIT(ns, id)
18
19 void __static_init() { }
20 #define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
21 #define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
22
23 #endif