From 6ba6b6eb811c3fe293cfdd883e00344caf68f7a9 Mon Sep 17 00:00:00 2001 From: TimePath Date: Fri, 14 Aug 2015 10:25:57 +1000 Subject: [PATCH] Allow custom construction of registered objects --- qcsrc/common/items/all.qh | 2 +- qcsrc/common/mapinfo.qh | 6 ++++-- qcsrc/common/monsters/all.qh | 2 +- qcsrc/common/nades.qh | 2 +- qcsrc/common/registry.qh | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 3bbd1946f..e666ad353 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -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 { \ diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 8d10b02ab..22b17d900 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -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; \ diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index 38a83a0f1..45adf5e59 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -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) { \ diff --git a/qcsrc/common/nades.qh b/qcsrc/common/nades.qh index 7b50bcc56..d029da43e 100644 --- a/qcsrc/common/nades.qh +++ b/qcsrc/common/nades.qh @@ -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) diff --git a/qcsrc/common/registry.qh b/qcsrc/common/registry.qh index 3ce8c471e..5a15337cf 100644 --- a/qcsrc/common/registry.qh +++ b/qcsrc/common/registry.qh @@ -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; \ -- 2.39.2