]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/items/item.qh
Adjust item definition syntax
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / item.qh
index 1c8939beb09800d497c9eab75f581c3bcc981075..43231cc1f10b8426b0a5cb2bb9b5040de99472ae 100644 (file)
@@ -1,40 +1,27 @@
 #ifndef GAMEITEM_H
 #define GAMEITEM_H
 #include "../oo.qh"
+#define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__)
 CLASS(GameItem, Object)
-    METHOD(GameItem, respondTo, bool(entity, int))
+    ATTRIB(GameItem, m_id, int, 0)
+    METHOD(GameItem, show, void(entity this))
+    void GameItem_show(entity this) { print("A game item\n"); }
+    void ITEM_HANDLE(Show, entity this) { this.show(this); }
 ENDCLASS(GameItem)
 
 
-
-#define LAMBDA(...) { __VA_ARGS__ ; }
-
-#define ITEM_SIGNALS(_) \
-    _(Default, void, (entity it), LAMBDA({ it.respondTo(it, SIGNAL); })) \
-    /* Common item signals */
-
-#define ITEM_SIGNAL(id) __Item_Signal_##id
-
-#define ITEM_ENUM(id, ret, params, body) ITEM_SIGNAL(id) ,
-enum { ITEM_SIGNALS(ITEM_ENUM) };
-#undef ITEM_ENUM
-
-#define ITEM_SEND(id, ret, params, body) ret __Item_Send_##id params { const noref int SIGNAL = ITEM_SIGNAL(id); body }
-ITEM_SIGNALS(ITEM_SEND)
-#undef ITEM_SEND
-#define ITEM_SEND(id, ...) __Item_Send_##id(__VA_ARGS__)
-
-
-
 int ITEM_COUNT;
+/** If you register a new item, make sure to add it to all.inc */
 #define REGISTER_ITEM(id, class, body)          \
     entity ITEM_##id;                           \
+    void RegisterItems_init_##id(entity this) { body } \
     void RegisterItems_##id() {                 \
-        const noref entity this = NEW(class);   \
+        entity this = NEW(class);               \
         ITEM_##id = this;                       \
+        this.m_id = ITEM_COUNT;                 \
         ITEMS[ITEM_COUNT++] = this;             \
-        body                                    \
+        RegisterItems_init_##id(this);          \
     }                                           \
-    ACCUMULATE_FUNCTION(RegisterItems, RegisterItems_##id)
-
+    ACCUMULATE_FUNCTION(RegisterItems, RegisterItems_##id) \
+    [[accumulate]] void RegisterItems_init_##id(entity this)
 #endif