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
26 // Step 4: kill unstructured setself
31 // Step 5: this should work
34 #define self (0, this)
37 // Step 6: remove SELFPARAM, add parameters
42 // Step 7: remove WITHSELF, no replacement
45 #define WITHSELF(value, block) block
48 #define SELFWRAP(T, R, args, forward) \
52 R T##_self() { SELFPARAM(); return this.self##T forward; }
54 noref entity _selftemp;
55 #define SELFWRAP_SET(T, e, f) \
56 (_selftemp = (e), _selftemp.__##T = ((f) ? T##_self : func_null), _selftemp.self##T = (f))
57 #define SELFWRAP_GET(T, e) \
59 #define _SELFWRAP_SET(T, e, f) \
61 #define _SELFWRAP_GET(T, e) \
64 SELFWRAP(think, void, (entity this), (this))
65 #define setthink(e, f) _SELFWRAP_SET(think, e, f)
66 #define getthink(e) _SELFWRAP_GET(think, e)
68 SELFWRAP(touch, void, (entity this), (this))
69 #define settouch(e, f) _SELFWRAP_SET(touch, e, f)
70 #define gettouch(e) _SELFWRAP_GET(touch, e)
72 SELFWRAP(predraw, void, (entity this), (this))
73 #define setpredraw(e, f) SELFWRAP_SET(predraw, e, f)
76 void adaptor_think2touch() { SELFPARAM(); WITH(entity, other, NULL, gettouch(this)()); }
77 void adaptor_think2use() { SELFPARAM(); if (this.use) this.use(this, NULL, NULL); }