]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/registry.qh
Merge branch 'maint' (early part before Transifex)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / registry.qh
index 4c24b491d9b33661bf562a333009dc1d89db5f30..6e8557edfd8808a10c0426e6c102d1f1c1304a98 100644 (file)
@@ -1,17 +1,27 @@
 #ifndef REGISTRY_H
 #define REGISTRY_H
 
+#include "oo.qh"
+#include "util.qh"
+
 #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
+#define REGISTER_INIT_POST(ns, id) [[accumulate]] void Register_##ns##_##id##_init_post(entity this)
 
-#define REGISTER(initfunc, ns, array, counter, id, class, fld)  \
+#define REGISTER(initfunc, ns, array, counter, id, fld, inst)   \
     entity ns##_##id;                                           \
     REGISTER_INIT(ns, id) { }                                   \
+    REGISTER_INIT_POST(ns, id) { }                              \
+    .entity enemy; /* internal next pointer */                  \
     void Register_##ns##_##id() {                               \
-        entity this = NEW(class);                               \
+        entity this = inst;                                     \
         ns##_##id = this;                                       \
         this.fld = counter;                                     \
         array[counter++] = this;                                \
+        if (!array##_first)    array##_first = this;            \
+        if ( array##_last)     array##_last.enemy = this;       \
+        array##_last = this;                                    \
         Register_##ns##_##id##_init(this);                      \
+        Register_##ns##_##id##_init_post(this);                 \
     }                                                           \
     ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
     REGISTER_INIT(ns, id)
@@ -20,4 +30,9 @@ void __static_init() { }
 #define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
 #define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
 
+#define STATIC_INIT(func) \
+    void _static_##func(); \
+    ACCUMULATE_FUNCTION(__static_init, _static_##func) \
+    void _static_##func()
+
 #endif