]> 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 d6f884c317257e7b554eeda574fd8b637d53b0bd..6e8557edfd8808a10c0426e6c102d1f1c1304a98 100644 (file)
@@ -1,17 +1,38 @@
 #ifndef REGISTRY_H
 #define REGISTRY_H
 
-#define REGISTER(initfunc, ns, array, counter, id, class)           \
-    entity ns##_##id;                                               \
-    void Register_##ns##_##id##_init(entity this) { }               \
-    void Register_##ns##_##id() {                                   \
-        entity this = NEW(class);                                   \
-        ns##_##id = this;                                           \
-        this.m_id = ns##_COUNT;                                     \
-        array[counter++] = this;                                    \
-        Register_##ns##_##id##_init(this);                          \
-    }                                                               \
-    ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)             \
-    [[accumulate]] void Register_##ns##_##id##_init(entity this)
+#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, 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 = 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)
+
+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