X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fself.qh;h=092a8945b7a25faf0286cef3a7234c315b837772;hb=301702fff6cd39f10c89eef9880cd9a85fe5c53e;hp=eac0c644a664ce0afd52a0311994d111ddc3d21e;hpb=18e2cd311a581f77ba8eb9c5421dd219ff5d760d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index eac0c644a..092a8945b 100644 --- a/qcsrc/lib/self.qh +++ b/qcsrc/lib/self.qh @@ -1,37 +1,46 @@ -#ifndef SELF_H -#define SELF_H +#pragma once // Transition from global 'self' to local 'this' -[[alias("self")]] entity __self; - // Step 1: auto oldself #if 1 -#define SELFPARAM() noref entity this = __self -#define setself(s) (__self = s) -#define self __self + #define SELFPARAM() noref const entity this = self #endif -// Step 2: check SELFPARAM() is present for functions that use self -#if 0 -#define SELFPARAM() [[alias("__self")]] noref entity this = __self -#define setself(s) (__self = s) -#define self this +// Step 2: const self +#if 1 + #define self (0, self) + [[alias("self")]] entity __self; + #define setself(s) (__self = s) + #define WITHSELF(value, block) WITH(entity, __self, value, (0, block)) #endif -// Step 3: const self -#if 0 -#define SELFPARAM() noref const entity this = __self -entity setself(entity e) { return self = e; } -entity getself() { return self; } -#define self getself() +// Step 3: propagate SELFPARAM() +#if 1 + #undef self + #define self (this, self) #endif -// Step 4: enable when possible -// TODO: Remove SELFPARAM in favor of a parameter +// Step 4: kill unstructured setself #if 0 -#define SELFPARAM() noref const entity this = __self -#define self this + #undef setself #endif +// Step 5: this should work +#if 0 + #define self (0, this) #endif + +// Step 6: Remove SELFPARAM in favor of a parameter + +.void(entity this) selftouch; +void touch_self() { SELFPARAM(); this.selftouch(this); } +#define settouch(e, f) (e.touch = touch_self, e.selftouch = f) + +//.void(entity this) selfuse; +//void use_self() { SELFPARAM(); this.selfuse(this); } +//#define setuse(e, f) (e.use = use_self, e.selfuse = f) + +.void(entity this) selfthink; +void think_self() { SELFPARAM(); this.selfthink(this); } +#define setthink(e, f) (e.think = think_self, e.selfthink = f)