From c4775145ca195a5e5c7c3622e874180d162c71be Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 12 Aug 2015 18:17:43 +1000 Subject: [PATCH] Namespace registry functions --- qcsrc/common/items/all.qc | 4 ++-- qcsrc/common/items/all.qh | 6 +++--- qcsrc/common/registry.qh | 26 ++++++++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/qcsrc/common/items/all.qc b/qcsrc/common/items/all.qc index fa198bb83..2de5afb4c 100644 --- a/qcsrc/common/items/all.qc +++ b/qcsrc/common/items/all.qc @@ -1,5 +1,5 @@ -#ifndef ALL_C -#define ALL_C +#ifndef ITEMS_ALL_C +#define ITEMS_ALL_C #include "all.qh" #include "all.inc" diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 647958628..4ef8bd4da 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -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++) { \ diff --git a/qcsrc/common/registry.qh b/qcsrc/common/registry.qh index d6f884c31..c87d7184c 100644 --- a/qcsrc/common/registry.qh +++ b/qcsrc/common/registry.qh @@ -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 -- 2.39.2