]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Namespace registry functions
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 12 Aug 2015 08:17:43 +0000 (18:17 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 12 Aug 2015 08:20:54 +0000 (18:20 +1000)
qcsrc/common/items/all.qc
qcsrc/common/items/all.qh
qcsrc/common/registry.qh

index fa198bb8328b709f090c035663e896fd62b4f0c1..2de5afb4ca4869dbe75ee6d10c91ec31e4a94497 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef ALL_C
-#define ALL_C
+#ifndef ITEMS_ALL_C
+#define ITEMS_ALL_C
 #include "all.qh"
 
 #include "all.inc"
index 647958628069ba633346e94c9b8fcafe3f4ea9d4..4ef8bd4dad28be8bdea27466c1ee4c1f6233fc6a 100644 (file)
@@ -1,14 +1,14 @@
 #include "../registry.qh"
 
-#ifndef ALL_H
-#define ALL_H
+#ifndef ITEMS_ALL_H
+#define ITEMS_ALL_H
 
 void RegisterItems();
 const int MAX_ITEMS = 24;
 entity ITEMS[MAX_ITEMS];
 int ITEM_COUNT;
 /** If you register a new item, make sure to add it to all.inc */
-#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, class)
+#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, class, m_id)
 
 #define ITEMS_FOREACH(pred, body) do {      \
     for (int i = 0; i < ITEM_COUNT; i++) {  \
index d6f884c317257e7b554eeda574fd8b637d53b0bd..c87d7184cd2c47d176e1f59b154d1bae82e35616 100644 (file)
@@ -1,17 +1,19 @@
 #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)
+#define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
+
+#define REGISTER(initfunc, ns, array, counter, id, class, fld)  \
+    entity ns##_##id;                                           \
+    REGISTER_INIT(ns, id) { }                                   \
+    void Register_##ns##_##id() {                               \
+        entity this = NEW(class);                               \
+        ns##_##id = this;                                       \
+        this.fld = ns##_COUNT;                                  \
+        array[counter++] = this;                                \
+        Register_##ns##_##id##_init(this);                      \
+    }                                                           \
+    ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id)         \
+    REGISTER_INIT(ns, id)
 
 #endif