]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/self.qh
Merge branch 'master' into Mario/balance
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / self.qh
1 #pragma once
2
3 // Transition from global 'self' to local 'this'
4
5 // Step 1: auto oldself
6 #if 1
7     #define SELFPARAM() noref const entity this = self
8 #endif
9
10 // Step 2: const self
11 #if 1
12     #define self (0, self)
13     [[alias("self")]] entity __self;
14     #define setself(s) (__self = s)
15     #define WITHSELF(value, block) WITH(entity, __self, value, (0, block))
16 #endif
17
18 // Step 3: propagate SELFPARAM()
19 #if 1
20     #undef self
21     #define self (this, self)
22     #undef SELFPARAM
23     #define SELFPARAM() const entity this = __self
24     #define ENGINE_EVENT() const entity this = __self
25 #endif
26
27 // Step 4: kill unstructured setself
28 #if 1
29     #undef setself
30 #endif
31
32 // Step 5: this should work
33 #if 1
34     #undef self
35     #define self (0, this)
36 #endif
37
38 // Step 6: remove SELFPARAM, add parameters
39 #if 1
40     #undef SELFPARAM
41 #endif
42
43 // Step 7: remove WITHSELF, no replacement
44 #if 0
45     #undef WITHSELF
46     #define WITHSELF(value, block) block
47 #endif
48
49 #define SELFWRAP(T, R, oldargs, args, forward) \
50     .R oldargs T; \
51     .R oldargs __##T = T; \
52     .R args self##T; \
53     R T##_self oldargs { ENGINE_EVENT(); return this.self##T forward; }
54
55 noref entity _selftemp;
56 #define SELFWRAP_SET(T, e, f) \
57     (_selftemp = (e), _selftemp.__##T = ((f) ? T##_self : func_null), _selftemp.self##T = (f))
58 #define SELFWRAP_GET(T, e) \
59     (0, (e).self##T)
60 #define _SELFWRAP_SET(T, e, f) \
61     ((e).__##T = (f))
62 #define _SELFWRAP_GET(T, e) \
63     (0, (e).__##T)
64
65 SELFWRAP(think, void, (), (entity this), (this))
66 #define setthink(e, f) SELFWRAP_SET(think, e, f)
67 #define getthink(e) SELFWRAP_GET(think, e)
68
69 #ifndef MENUQC
70 SELFWRAP(touch, void, (), (entity this, entity toucher), (this, other))
71 #define settouch(e, f) SELFWRAP_SET(touch, e, f)
72 #define gettouch(e) SELFWRAP_GET(touch, e)
73 #endif
74
75 #ifndef MENUQC
76 SELFWRAP(blocked, void, (), (entity this, entity blocker), (this, other))
77 #define setblocked(e, f) SELFWRAP_SET(blocked, e, f)
78 #define blocked stopusingthis
79 #endif
80
81 SELFWRAP(predraw, void, (), (entity this), (this))
82 #define setpredraw(e, f) SELFWRAP_SET(predraw, e, f)
83
84 #ifndef MENUQC
85 SELFWRAP(customizeentityforclient, bool, (), (entity this, entity client), (this, other))
86 #define setcefc(e, f) SELFWRAP_SET(customizeentityforclient, e, f)
87 #define getcefc(e) SELFWRAP_GET(customizeentityforclient, e)
88 #endif
89
90 SELFWRAP(camera_transform, vector, (vector org, vector ang), (entity this, vector org, vector ang), (this, org, ang))
91 #define setcamera_transform(e, f) SELFWRAP_SET(camera_transform, e, f)
92
93 /** return false to remove from the client */
94 SELFWRAP(SendEntity, bool, (entity to, int sendflags), (entity this, entity to, int sendflags), (this, to, sendflags))
95 #define setSendEntity(e, f) SELFWRAP_SET(SendEntity, e, f)
96 #define getSendEntity(e) SELFWRAP_GET(SendEntity, e)
97
98 #define ChangeYaw(e, ...) (__self = (e), builtin_ChangeYaw(__VA_ARGS__))
99 #define checkclient(e, ...) (__self = (e), builtin_checkclient(__VA_ARGS__))
100 #ifndef SVQC
101     #define droptofloor(e, ...) (__self = (e), builtin_droptofloor(__VA_ARGS__))
102 #endif
103 #define error(...) (__self = (NULL), builtin_error(__VA_ARGS__))
104 #define movetogoal(e, ...) (__self = (e), builtin_movetogoal(__VA_ARGS__))
105 #ifndef SVQC
106     #define objerror(e, ...) (__self = (e), builtin_objerror(__VA_ARGS__))
107 #else
108     void make_safe_for_remove(entity this);
109     #define objerror(e, ...) (__self = (e), make_safe_for_remove(__self), builtin_objerror(__VA_ARGS__))
110 #endif
111 #define walkmove(e, ...) (__self = (e), builtin_walkmove(__VA_ARGS__))
112
113 #ifndef MENUQC
114 void adaptor_think2use(entity this) { if (this.use) this.use(this, NULL, NULL); }
115 #endif