+#include "../registry.qh"
+
#ifndef ALL_H
#define 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 ITEMS_FOREACH(pred, body) do { \
for (int i = 0; i < ITEM_COUNT; i++) { \
} \
} while(0)
-void RegisterItems();
void Dump_Items();
#endif
#define GAMEITEM_H
#include "../oo.qh"
#define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__)
+/** If you register a new item, make sure to add it to all.inc */
CLASS(GameItem, Object)
ATTRIB(GameItem, m_id, int, 0)
METHOD(GameItem, show, void(entity this))
void ITEM_HANDLE(Show, entity this) { this.show(this); }
ENDCLASS(GameItem)
-
-int ITEM_COUNT;
-/** If you register a new item, make sure to add it to all.inc */
-#define REGISTER_ITEM(id, class) \
- entity ITEM_##id; \
- void RegisterItems_init_##id(entity this) {} \
- void RegisterItems_##id() { \
- entity this = NEW(class); \
- ITEM_##id = this; \
- this.m_id = ITEM_COUNT; \
- ITEMS[ITEM_COUNT++] = this; \
- RegisterItems_init_##id(this); \
- } \
- ACCUMULATE_FUNCTION(RegisterItems, RegisterItems_##id) \
- [[accumulate]] void RegisterItems_init_##id(entity this)
#endif
--- /dev/null
+#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)
+
+#endif