X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Flib%2Fself.qh;h=50196a03a97d4f614725faa16113d3fdcbc207ab;hp=31d7d07c80db730f1db4f376a71c3f6f6dae1de9;hb=490a31934aa67cc7de5299a4d3f625d5271f8583;hpb=d271f27a5ac351a3a7b39636932f6d661492be1d diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index 31d7d07c8..50196a03a 100644 --- a/qcsrc/lib/self.qh +++ b/qcsrc/lib/self.qh @@ -19,6 +19,8 @@ #if 1 #undef self #define self (this, self) + #undef SELFPARAM + #define SELFPARAM() const entity this = __self #endif // Step 4: kill unstructured setself @@ -28,19 +30,49 @@ // Step 5: this should work #if 0 + #undef self #define self (0, this) #endif -// Step 6: Remove SELFPARAM in favor of a parameter +// Step 6: remove SELFPARAM, add parameters +#if 0 + #undef SELFPARAM +#endif + +// Step 7: remove WITHSELF, no replacement +#if 0 + #undef WITHSELF + #define WITHSELF(value, block) block +#endif + +#define SELFWRAP(T, R, args, forward) \ + .R() T; \ + .R() __##T = T; \ + .R args self##T; \ + R T##_self() { SELFPARAM(); return this.self##T forward; } + +noref entity _selftemp; +#define SELFWRAP_SET(T, e, f) \ + (_selftemp = (e), _selftemp.__##T = ((f) ? T##_self : func_null), _selftemp.self##T = (f)) +#define SELFWRAP_GET(T, e) \ + (0, (e).self##T) +#define _SELFWRAP_SET(T, e, f) \ + ((e).__##T = (f)) +#define _SELFWRAP_GET(T, e) \ + (0, (e).__##T) -.void(entity this) selftouch; -void touch_self() { SELFPARAM(); this.selftouch(this); } -#define settouch(e, f) (e.touch = touch_self, e.selftouch = f) +SELFWRAP(think, void, (entity this), (this)) +#define setthink(e, f) SELFWRAP_SET(think, e, f) +#define getthink(e) SELFWRAP_GET(think, e) -.void(entity this) selfuse; -void use_self() { SELFPARAM(); this.selfuse(this); } -#define setuse(e, f) (e.use = use_self, e.selfuse = f) +SELFWRAP(touch, void, (entity this), (this)) +#define settouch(e, f) SELFWRAP_SET(touch, e, f) +#define gettouch(e) SELFWRAP_GET(touch, e) -.void(entity this) selfthink; -void think_self() { SELFPARAM(); this.selfthink(this); } -#define setthink(e, f) (e.think = think_self, e.selfthink = f) +SELFWRAP(predraw, void, (entity this), (this)) +#define setpredraw(e, f) SELFWRAP_SET(predraw, e, f) + +#ifndef MENUQC +void adaptor_think2touch(entity this) { WITH(entity, other, NULL, gettouch(this)(this)); } +void adaptor_think2use(entity this) { if (this.use) this.use(this, NULL, NULL); } +#endif