3 // Transition from global 'self' to local 'this'
5 // Step 1: auto oldself
7 #define SELFPARAM() noref const entity this = self
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))
18 // Step 3: propagate SELFPARAM()
21 #define self (this, self)
23 #define SELFPARAM() const entity this = __self
24 #define ENGINE_EVENT() const entity this = __self
27 // Step 4: kill unstructured setself
32 // Step 5: this should work
35 #define self (0, this)
38 // Step 6: remove SELFPARAM, add parameters
43 // Step 7: remove WITHSELF, no replacement
46 #define WITHSELF(value, block) block
49 #define SELFWRAP(T, R, oldargs, args, forward) \
51 .R oldargs __##T = T; \
53 R T##_self oldargs { ENGINE_EVENT(); return this.self##T forward; }
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) \
60 #define _SELFWRAP_SET(T, e, f) \
62 #define _SELFWRAP_GET(T, e) \
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)
69 SELFWRAP(touch, void, (), (entity this), (this))
70 #define settouch(e, f) SELFWRAP_SET(touch, e, f)
71 #define gettouch(e) SELFWRAP_GET(touch, e)
73 SELFWRAP(blocked, void, (), (entity this), (this))
74 #define setblocked(e, f) SELFWRAP_SET(blocked, e, f)
75 #define blocked stopusingthis
77 SELFWRAP(predraw, void, (), (entity this), (this))
78 #define setpredraw(e, f) SELFWRAP_SET(predraw, e, f)
80 SELFWRAP(customizeentityforclient, bool, (), (entity this), (this))
81 #define setcefc(e, f) SELFWRAP_SET(customizeentityforclient, e, f)
82 #define getcefc(e) SELFWRAP_GET(customizeentityforclient, e)
84 SELFWRAP(camera_transform, vector, (vector org, vector ang), (entity this, vector org, vector ang), (this, org, ang))
85 #define setcamera_transform(e, f) SELFWRAP_SET(camera_transform, e, f)
87 SELFWRAP(SendEntity, bool, (entity to, int sendflags), (entity this, entity to, int sendflags), (this, to, sendflags))
88 #define setSendEntity(e, f) SELFWRAP_SET(SendEntity, e, f)
91 void make_safe_for_remove(entity this);
94 void objerror(entity this, string s)
97 make_safe_for_remove(this);
99 WITHSELF(this, builtin_objerror(s));
103 void adaptor_think2touch(entity this) { WITH(entity, other, NULL, gettouch(this)(this)); }
104 void adaptor_think2use(entity this) { if (this.use) this.use(this, NULL, NULL); }