From a0244f34e33a974c41eb5464052f152fca91feb6 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 27 Mar 2016 02:13:13 +1100 Subject: [PATCH] Self removal kit: update plan --- qcsrc/common/triggers/target/music.qc | 10 +++---- qcsrc/common/vehicles/sv_vehicles.qc | 1 + qcsrc/lib/misc.qh | 2 -- qcsrc/lib/self.qh | 43 +++++++++++---------------- qcsrc/server/cl_client.qc | 3 +- qcsrc/server/g_lights.qc | 5 ++++ qcsrc/server/spawnpoints.qc | 4 +-- 7 files changed, 31 insertions(+), 37 deletions(-) diff --git a/qcsrc/common/triggers/target/music.qc b/qcsrc/common/triggers/target/music.qc index 7083fcccd..5a4e86c48 100644 --- a/qcsrc/common/triggers/target/music.qc +++ b/qcsrc/common/triggers/target/music.qc @@ -38,12 +38,10 @@ void target_music_kill() { FOREACH_ENTITY_CLASS("target_music", true, { it.volume = 0; - WITHSELF(it, { - if (it.targetname == "") - target_music_sendto(MSG_ALL, 1); - else - target_music_sendto(MSG_ALL, 0); - }); + if (it.targetname == "") + WITHSELF(it, target_music_sendto(MSG_ALL, 1)); + else + WITHSELF(it, target_music_sendto(MSG_ALL, 0)); }); } void target_music_use() diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index f99d7622f..ccda73209 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -953,6 +953,7 @@ bool vehicle_impulse(entity this, int imp) void vehicles_enter(entity pl, entity veh) { + SELFPARAM(); entity oldself = self; // Remove this when bots know how to use vehicles diff --git a/qcsrc/lib/misc.qh b/qcsrc/lib/misc.qh index dfabebeeb..950000f04 100644 --- a/qcsrc/lib/misc.qh +++ b/qcsrc/lib/misc.qh @@ -45,5 +45,3 @@ LAMBDA(block) \ name = __with_save; \ } MACRO_END - -#define WITHSELF(value, block) WITH(entity, __self, value, block) diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index 01dd638c8..5d53694c7 100644 --- a/qcsrc/lib/self.qh +++ b/qcsrc/lib/self.qh @@ -2,40 +2,33 @@ // Transition from global 'self' to local 'this' -[[alias("self")]] entity __self; - // Step 1: auto oldself #if 1 -#if NDEBUG - #define SELFPARAM() noref entity this = __self - #define setself(s) (__self = s) - #define self __self -#else - noref string self_str; - #define SELFPARAM() self_str = "self"; noref entity this = __self - #define setself(s) (self_str = #s, __self = s) - #define self (print(__SOURCELOC__, ": ", self_str, "\n"), __self) + #define SELFPARAM() noref const entity this = self #endif + +// 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 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 3: propagate SELFPARAM() +#if 1 + #undef self + #define self (this, self) #endif -// Step 3: const self +// Step 4: kill unstructured setself #if 0 - #define SELFPARAM() noref const entity this = __self - entity setself(entity e) { return self = e; } - entity getself() { return self; } - #define self getself() + #undef setself #endif -// Step 4: enable when possible -// TODO: Remove SELFPARAM in favor of a parameter +// Step 5: this should work #if 0 - #define SELFPARAM() noref const entity this = __self - #define self this + #define self (0, this) #endif + +// Step 6: Remove SELFPARAM in favor of a parameter diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 6b99bc4a5..9edcf8d5f 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -68,7 +68,8 @@ void ClientDisconnect(); STATIC_METHOD(Client, Remove, void(Client this)) { TRANSMUTE(Observer, this); - WITHSELF(this, PutClientInServer(); ClientDisconnect()); + WITHSELF(this, PutClientInServer()); + WITHSELF(this, ClientDisconnect()); } void send_CSQC_teamnagger() { diff --git a/qcsrc/server/g_lights.qc b/qcsrc/server/g_lights.qc index 37177326f..74e03b7a0 100644 --- a/qcsrc/server/g_lights.qc +++ b/qcsrc/server/g_lights.qc @@ -36,6 +36,7 @@ flags: */ void dynlight_think() { + SELFPARAM(); if(!self.owner) remove(self); @@ -43,6 +44,7 @@ void dynlight_think() } void dynlight_find_aiment() { + SELFPARAM(); entity targ; if (!self.target) objerror ("dynlight: no target to follow"); @@ -59,6 +61,7 @@ void dynlight_find_aiment() } void dynlight_find_path() { + SELFPARAM(); entity targ; if (!self.target) objerror ("dynlight: no target to follow"); @@ -71,6 +74,7 @@ void dynlight_find_path() } void dynlight_find_target() { + SELFPARAM(); entity targ; if (!self.target) objerror ("dynlight: no target to follow"); @@ -83,6 +87,7 @@ void dynlight_find_target() } void dynlight_use() { + SELFPARAM(); if (self.light_lev == 0) self.light_lev = self.lefty; else diff --git a/qcsrc/server/spawnpoints.qc b/qcsrc/server/spawnpoints.qc index 4e7cf0f5d..51af4d16e 100644 --- a/qcsrc/server/spawnpoints.qc +++ b/qcsrc/server/spawnpoints.qc @@ -261,9 +261,7 @@ vector Spawn_Score(entity spot, float mindist, float teamcheck) ++found; if(ent.spawn_evalfunc) { - WITHSELF(ent, { - spawn_score = ent.spawn_evalfunc(this, spot, spawn_score); - }); + WITHSELF(ent, spawn_score = ent.spawn_evalfunc(this, spot, spawn_score)); if(spawn_score.x < 0) return spawn_score; } -- 2.39.2