]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/items/item.qh
Move LAMBDA
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / item.qh
1 #ifndef GAMEITEM_H
2 #define GAMEITEM_H
3 #include "../oo.qh"
4 CLASS(GameItem, Object)
5     METHOD(GameItem, respondTo, bool(entity, int))
6 ENDCLASS(GameItem)
7
8
9
10 #define ITEM_SIGNALS(_) \
11     _(Default, void, (entity it), LAMBDA({ it.respondTo(it, SIGNAL); })) \
12     /* Common item signals */
13
14 #define ITEM_SIGNAL(id) __Item_Signal_##id
15
16 #define ITEM_ENUM(id, ret, params, body) ITEM_SIGNAL(id) ,
17 enum { ITEM_SIGNALS(ITEM_ENUM) };
18 #undef ITEM_ENUM
19
20 #define ITEM_SEND(id, ret, params, body) ret __Item_Send_##id params { const noref int SIGNAL = ITEM_SIGNAL(id); body }
21 ITEM_SIGNALS(ITEM_SEND)
22 #undef ITEM_SEND
23 #define ITEM_SEND(id, ...) __Item_Send_##id(__VA_ARGS__)
24
25
26
27 int ITEM_COUNT;
28 #define REGISTER_ITEM(id, class, body)          \
29     entity ITEM_##id;                           \
30     void RegisterItems_##id() {                 \
31         const noref entity this = NEW(class);   \
32         ITEM_##id = this;                       \
33         ITEMS[ITEM_COUNT++] = this;             \
34         body                                    \
35     }                                           \
36     ACCUMULATE_FUNCTION(RegisterItems, RegisterItems_##id)
37
38 #endif