X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fself.qh;h=4299c19cd3674a286d3b5eea310a0754f3db0ad1;hb=17d9558bff4fa8c1d7f558897b7830cb0cf4dca6;hp=31d7d07c80db730f1db4f376a71c3f6f6dae1de9;hpb=d271f27a5ac351a3a7b39636932f6d661492be1d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index 31d7d07c8..4299c19cd 100644 --- a/qcsrc/lib/self.qh +++ b/qcsrc/lib/self.qh @@ -1,5 +1,7 @@ #pragma once +#include "macro.qh" + // Transition from global 'self' to local 'this' // Step 1: auto oldself @@ -9,38 +11,101 @@ // Step 2: const self #if 1 - #define self (0, self) - [[alias("self")]] entity __self; + #define self (RVALUE, self) + ALIAS("self") entity __self; #define setself(s) (__self = s) - #define WITHSELF(value, block) WITH(entity, __self, value, (0, block)) + #define WITHSELF(value, block) WITH(entity, __self, value, (RVALUE, block)) #endif // Step 3: propagate SELFPARAM() #if 1 #undef self #define self (this, self) + #undef SELFPARAM + #define SELFPARAM() const entity this = __self + #define ENGINE_EVENT() const entity this = __self #endif // Step 4: kill unstructured setself -#if 0 +#if 1 #undef setself #endif // Step 5: this should work +#if 1 + #undef self + #define self (RVALUE, this) +#endif + +// Step 6: remove SELFPARAM, add parameters +#if 1 + #undef SELFPARAM +#endif + +// Step 7: remove WITHSELF, no replacement #if 0 - #define self (0, this) + #undef WITHSELF + #define WITHSELF(value, block) block +#endif + +#define SELFWRAP(T, R, oldargs, args, forward) \ + .R oldargs T; \ + noref .R oldargs __##T = T; \ + .R args self##T; \ + R T##_self oldargs { ENGINE_EVENT(); 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) \ + (RVALUE, (e).self##T) +#define _SELFWRAP_SET(T, e, f) \ + ((e).__##T = (f)) +#define _SELFWRAP_GET(T, e) \ + (RVALUE, (e).__##T) + +SELFWRAP(think, void, (), (entity this), (this)) +#define setthink(e, f) SELFWRAP_SET(think, e, f) +#define getthink(e) SELFWRAP_GET(think, e) + +#ifdef GAMEQC +SELFWRAP(touch, void, (), (entity this, entity toucher), (this, other)) +#define settouch(e, f) SELFWRAP_SET(touch, e, f) +#define gettouch(e) SELFWRAP_GET(touch, e) #endif -// Step 6: Remove SELFPARAM in favor of a parameter +#ifdef GAMEQC +SELFWRAP(blocked, void, (), (entity this, entity blocker), (this, other)) +#define setblocked(e, f) SELFWRAP_SET(blocked, e, f) +#define blocked stopusingthis +#endif -.void(entity this) selftouch; -void touch_self() { SELFPARAM(); this.selftouch(this); } -#define settouch(e, f) (e.touch = touch_self, e.selftouch = f) +SELFWRAP(predraw, void, (), (entity this), (this)) +#define setpredraw(e, f) SELFWRAP_SET(predraw, e, f) -.void(entity this) selfuse; -void use_self() { SELFPARAM(); this.selfuse(this); } -#define setuse(e, f) (e.use = use_self, e.selfuse = f) +#ifdef GAMEQC +SELFWRAP(customizeentityforclient, bool, (), (entity this, entity client), (this, other)) +#define setcefc(e, f) SELFWRAP_SET(customizeentityforclient, e, f) +#define getcefc(e) SELFWRAP_GET(customizeentityforclient, e) +#endif -.void(entity this) selfthink; -void think_self() { SELFPARAM(); this.selfthink(this); } -#define setthink(e, f) (e.think = think_self, e.selfthink = f) +SELFWRAP(camera_transform, vector, (vector org, vector ang), (entity this, vector org, vector ang), (this, org, ang)) +#define setcamera_transform(e, f) SELFWRAP_SET(camera_transform, e, f) + +/** return false to remove from the client */ +SELFWRAP(SendEntity, bool, (entity to, int sendflags), (entity this, entity to, int sendflags), (this, to, sendflags)) +#define setSendEntity(e, f) SELFWRAP_SET(SendEntity, e, f) +#define getSendEntity(e) SELFWRAP_GET(SendEntity, e) + +#define ChangeYaw(e, ...) (__self = (e), builtin_ChangeYaw(__VA_ARGS__)) +#define checkclient(e, ...) (__self = (e), builtin_checkclient(__VA_ARGS__)) +#ifndef SVQC + #define droptofloor(e, ...) (__self = (e), builtin_droptofloor(__VA_ARGS__)) +#endif +#define error(...) (__self = (NULL), builtin_error(__VA_ARGS__)) +#define movetogoal(e, ...) (__self = (e), builtin_movetogoal(__VA_ARGS__)) +#define walkmove(e, ...) (__self = (e), builtin_walkmove(__VA_ARGS__)) + +#ifdef GAMEQC +void adaptor_think2use(entity this) { if (this.use) this.use(this, NULL, NULL); } +#endif