Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
self.qh
Go to the documentation of this file.
1#pragma once
2
3#include "macro.qh"
4
5// Transition from global 'self' to local 'this'
6
7// Step 1: auto oldself
8#if 1
9 #define SELFPARAM() noref const entity this = self
10#endif
11
12// Step 2: const self
13#if 1
14 #define self (RVALUE, self)
15 ALIAS("self") entity __self;
16 #define setself(s) (__self = s)
17 #define WITHSELF(value, block) WITH(entity, __self, value, (RVALUE, block))
18#endif
19
20// Step 3: propagate SELFPARAM()
21#if 1
22 #undef self
23 #define self (this, self)
24 #undef SELFPARAM
25 #define SELFPARAM() const entity this = __self
26 #define ENGINE_EVENT() const entity this = __self
27#endif
28
29// Step 4: kill unstructured setself
30#if 1
31 #undef setself
32#endif
33
34// Step 5: this should work
35#if 1
36 #undef self
37 #define self (RVALUE, this)
38#endif
39
40// Step 6: remove SELFPARAM, add parameters
41#if 1
42 #undef SELFPARAM
43#endif
44
45// Step 7: remove WITHSELF, no replacement
46#if 1
47 #undef WITHSELF
48 #define WITHSELF(value, block) block
49#endif
50
51#define SELFWRAP(T, R, oldargs, args, forward) \
52 .R oldargs T; \
53 noref .R oldargs __##T = T; \
54 .R args self##T; \
55 R T##_self oldargs \
56 { \
57 ENGINE_EVENT(); \
58 return this.self##T forward; \
59 }
60
62#define SELFWRAP_SET(T, e, f) \
63 (_selftemp = (e), _selftemp.__##T = ((f) ? T##_self : func_null), _selftemp.self##T = (f))
64#define SELFWRAP_GET(T, e) \
65 (RVALUE, (e).self##T)
66#define _SELFWRAP_SET(T, e, f) \
67 ((e).__##T = (f))
68#define _SELFWRAP_GET(T, e) \
69 (RVALUE, (e).__##T)
70
71SELFWRAP(think, void, (), (entity this), (this))
72#define setthink(e, f) SELFWRAP_SET(think, e, f)
73#define getthink(e) SELFWRAP_GET(think, e)
74
75#ifdef GAMEQC
76SELFWRAP(touch, void, (), (entity this, entity toucher), (this, other))
77#define settouch(e, f) SELFWRAP_SET(touch, e, f)
78#define gettouch(e) SELFWRAP_GET(touch, e)
79#endif
80
81#ifdef GAMEQC
82SELFWRAP(blocked, void, (), (entity this, entity blocker), (this, other))
83#define setblocked(e, f) SELFWRAP_SET(blocked, e, f)
84#define getblocked(e) SELFWRAP_GET(blocked, e)
85#endif
86
87SELFWRAP(predraw, void, (), (entity this), (this))
88#define setpredraw(e, f) SELFWRAP_SET(predraw, e, f)
89
90#ifdef GAMEQC
91SELFWRAP(customizeentityforclient, bool, (), (entity this, entity client), (this, other))
92#define setcefc(e, f) SELFWRAP_SET(customizeentityforclient, e, f)
93#define getcefc(e) SELFWRAP_GET(customizeentityforclient, e)
94#endif
95
96SELFWRAP(camera_transform, vector, (vector org, vector ang), (entity this, vector org, vector ang), (this, org, ang))
97#define setcamera_transform(e, f) SELFWRAP_SET(camera_transform, e, f)
98
99// return false to remove from the client
100SELFWRAP(SendEntity, bool, (entity to, int sendflags), (entity this, entity to, int sendflags), (this, to, sendflags))
101#define setSendEntity(e, f) SELFWRAP_SET(SendEntity, e, f)
102#define getSendEntity(e) SELFWRAP_GET(SendEntity, e)
103
104#define ChangeYaw(e, ...) (__self = (e), builtin_ChangeYaw(__VA_ARGS__))
105#define checkclient(e, ...) (__self = (e), builtin_checkclient(__VA_ARGS__))
106#define droptofloor(e, ...) (__self = (e), builtin_droptofloor(__VA_ARGS__))
107#define error(...) (__self = (NULL), builtin_error(__VA_ARGS__))
108#define movetogoal(e, ...) (__self = (e), builtin_movetogoal(__VA_ARGS__))
109#define walkmove(e, ...) (__self = (e), builtin_walkmove(__VA_ARGS__))
110
111#ifdef GAMEQC
112void adaptor_think2use(entity this) { if (this.use) this.use(this, NULL, NULL); }
113#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
entity other
#define use
#define ALIAS(var)
Definition _all.inc:44
#define NULL
Definition post.qh:14
#define SELFWRAP(T, R, oldargs, args, forward)
Definition self.qh:51
vector
Definition self.qh:96
vector org
Definition self.qh:96
entity entity toucher
Definition self.qh:76
vector vector ang
Definition self.qh:96
noref entity _selftemp
Definition self.qh:61