]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow custom construction of registered objects
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 00:25:57 +0000 (10:25 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 14 Aug 2015 00:25:57 +0000 (10:25 +1000)
qcsrc/common/items/all.qh
qcsrc/common/mapinfo.qh
qcsrc/common/monsters/all.qh
qcsrc/common/nades.qh
qcsrc/common/registry.qh

index 3bbd1946f3ca7bd6191767f9eb4f9b06c340d782..e666ad3538ddc61f1243d0c85d0fe089f5d285a4 100644 (file)
@@ -8,7 +8,7 @@ const int MAX_ITEMS = 24;
 entity ITEMS[MAX_ITEMS], ITEMS_first, ITEMS_last;
 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, m_id)
+#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, m_id, NEW(class))
 REGISTER_REGISTRY(RegisterItems)
 
 #define ITEMS_FOREACH(pred, body) do {      \
index 8d10b02ab5519a1da69a8f5644cd39b2c37ae511..22b17d900de78e4e4fb451363d27fd29360e00c8 100644 (file)
@@ -21,6 +21,7 @@ CLASS(Gametype, Object)
     ATTRIB(Gametype, gametype_description, string, string_null)
     CONSTRUCTOR(Gametype, string hname, string sname, string g_name, bool gteamplay, string defaults, string gdescription)
     {
+        CONSTRUCT(Gametype);
         this.netname = g_name;
         this.mdl = sname;
         this.message = hname;
@@ -39,8 +40,9 @@ int MAPINFO_TYPE_ALL;
 
 #define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, defaults, gdescription)                    \
     int MAPINFO_TYPE_##NAME;                                                                                \
-    REGISTER(RegisterGametypes, MAPINFO_TYPE, MAPINFO_TYPES, MAPINFO_TYPE_COUNT, g_name, Gametype, m_id) {  \
-        CONSTRUCT(Gametype, hname, #sname, #g_name, gteamplay, defaults, gdescription);                     \
+    REGISTER(RegisterGametypes, MAPINFO_TYPE, MAPINFO_TYPES, MAPINFO_TYPE_COUNT, g_name, m_id,              \
+        NEW(Gametype, hname, #sname, #g_name, gteamplay, defaults, gdescription)                            \
+    ) {                                                                                                     \
         /* same as `1 << m_id` */                                                                           \
         MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME;                \
         this.items = MAPINFO_TYPE_##NAME;                                                                   \
index 38a83a0f1685801583b3543351eabfe042714a9b..45adf5e5906e3e0ac8988e5712ad9733a5ce1e88 100644 (file)
@@ -11,7 +11,7 @@ int MON_COUNT;
 const int MON_FIRST = 1;
 #define MON_LAST (MON_FIRST + MON_COUNT - 1)
 /** If you register a new monster, make sure to add it to all.inc */
-#define REGISTER_MONSTER(id, class) REGISTER(RegisterMonsters, MON, monster_info, MON_COUNT, id, class, monsterid)
+#define REGISTER_MONSTER(id, class) REGISTER(RegisterMonsters, MON, monster_info, MON_COUNT, id, monsterid, NEW(class))
 #include "monster.qh"
 #define REGISTER_MONSTER_SIMPLE(id, monsterflags, min_s, max_s, modelname, shortname, mname) \
     REGISTER_MONSTER(id, Monster) {                                     \
index 7b50bcc563b88fe0bb1f6f10d8113fefeb88232a..d029da43ecc34add6f6ac64a5477c3fd1392d91e 100644 (file)
@@ -27,7 +27,7 @@ void RegisterNades();
 const int NADES_MAX = 8;
 entity NADES[NADES_MAX], NADES_first, NADES_last;
 int NADES_COUNT;
-#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, Nade, m_id)
+#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, m_id, NEW(Nade))
 REGISTER_REGISTRY(RegisterNades)
 
 CLASS(Nade, Object)
index 3ce8c471e5442019462b7266fda6d347668b5a9e..5a15337cf64bd6944110d9c0f0a3bd4cf8816d4a 100644 (file)
@@ -5,12 +5,12 @@
 
 #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(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) { }                                   \
     .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;                                \