From: TimePath Date: Tue, 29 Aug 2017 10:48:12 +0000 (+1000) Subject: Stats: don't assign to world X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8faec261f8ed416e7cf3970083663012fda80c65;p=xonotic%2Fxonotic-data.pk3dir.git Stats: don't assign to world --- diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index ae1bbff65..e1767b3fd 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -81,7 +81,7 @@ MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile) entity nade_type = Nade_FromProjectile(proj.cnt); if (nade_type == NADE_TYPE_Null) return; - if(STAT(NADES_SMALL, NULL)) + if(STAT(NADES_SMALL)) { proj.mins = '-8 -8 -8'; proj.maxs = '8 8 8'; diff --git a/qcsrc/common/physics/movetypes/movetypes.qh b/qcsrc/common/physics/movetypes/movetypes.qh index dbd765d98..85912ee1c 100644 --- a/qcsrc/common/physics/movetypes/movetypes.qh +++ b/qcsrc/common/physics/movetypes/movetypes.qh @@ -13,18 +13,18 @@ const int WATERLEVEL_SUBMERGED = 3; #define SET_ONSLICK(s) ((s).flags |= FL_ONSLICK) #define UNSET_ONSLICK(s) ((s).flags &= ~FL_ONSLICK) -#define GAMEPLAYFIX_DOWNTRACEONGROUND(s) STAT(GAMEPLAYFIX_DOWNTRACEONGROUND, NULL) -#define GAMEPLAYFIX_EASIERWATERJUMP(s) STAT(GAMEPLAYFIX_EASIERWATERJUMP, NULL) -#define GAMEPLAYFIX_STEPDOWN(s) STAT(GAMEPLAYFIX_STEPDOWN, NULL) -#define GAMEPLAYFIX_STEPMULTIPLETIMES(s) STAT(GAMEPLAYFIX_STEPMULTIPLETIMES, NULL) -#define GAMEPLAYFIX_UNSTICKPLAYERS(s) STAT(GAMEPLAYFIX_UNSTICKPLAYERS, NULL) -#define GAMEPLAYFIX_WATERTRANSITION(s) STAT(GAMEPLAYFIX_WATERTRANSITION, NULL) -#define UPWARD_VELOCITY_CLEARS_ONGROUND(s) STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, NULL) - -#define PHYS_STEPHEIGHT(s) STAT(MOVEVARS_STEPHEIGHT, NULL) -#define PHYS_NOSTEP(s) STAT(NOSTEP, NULL) -#define PHYS_JUMPSTEP(s) STAT(MOVEVARS_JUMPSTEP, NULL) -#define PHYS_WALLFRICTION(s) STAT(MOVEVARS_WALLFRICTION, NULL) +#define GAMEPLAYFIX_DOWNTRACEONGROUND(s) STAT(GAMEPLAYFIX_DOWNTRACEONGROUND) +#define GAMEPLAYFIX_EASIERWATERJUMP(s) STAT(GAMEPLAYFIX_EASIERWATERJUMP) +#define GAMEPLAYFIX_STEPDOWN(s) STAT(GAMEPLAYFIX_STEPDOWN) +#define GAMEPLAYFIX_STEPMULTIPLETIMES(s) STAT(GAMEPLAYFIX_STEPMULTIPLETIMES) +#define GAMEPLAYFIX_UNSTICKPLAYERS(s) STAT(GAMEPLAYFIX_UNSTICKPLAYERS) +#define GAMEPLAYFIX_WATERTRANSITION(s) STAT(GAMEPLAYFIX_WATERTRANSITION) +#define UPWARD_VELOCITY_CLEARS_ONGROUND(s) STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND) + +#define PHYS_STEPHEIGHT(s) STAT(MOVEVARS_STEPHEIGHT) +#define PHYS_NOSTEP(s) STAT(NOSTEP) +#define PHYS_JUMPSTEP(s) STAT(MOVEVARS_JUMPSTEP) +#define PHYS_WALLFRICTION(s) STAT(MOVEVARS_WALLFRICTION) #ifdef CSQC .float bouncestop; diff --git a/qcsrc/common/physics/player.qh b/qcsrc/common/physics/player.qh index d5a8e605a..ae59381e5 100644 --- a/qcsrc/common/physics/player.qh +++ b/qcsrc/common/physics/player.qh @@ -80,7 +80,7 @@ bool IsFlying(entity a); #define PHYS_JETPACK_MAXSPEED_UP(s) STAT(JETPACK_MAXSPEED_UP, s) #define PHYS_JETPACK_REVERSE_THRUST(s) STAT(JETPACK_REVERSE_THRUST, s) -#define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, NULL) +#define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS) #define PHYS_JUMPVELOCITY(s) STAT(MOVEVARS_JUMPVELOCITY, s) #define PHYS_MAXAIRSPEED(s) STAT(MOVEVARS_MAXAIRSPEED, s) @@ -97,7 +97,7 @@ bool IsFlying(entity a); #define PHYS_WARSOWBUNNY_TOPSPEED(s) STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, s) #define PHYS_WARSOWBUNNY_TURNACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, s) -#define PHYS_SLICK_APPLYGRAVITY(s) STAT(SLICK_APPLYGRAVITY, NULL) +#define PHYS_SLICK_APPLYGRAVITY(s) STAT(SLICK_APPLYGRAVITY) #define PHYS_INPUT_BUTTON_ATCK(s) PHYS_INPUT_BUTTON_BUTTON1(s) #define PHYS_INPUT_BUTTON_JUMP(s) PHYS_INPUT_BUTTON_BUTTON2(s) diff --git a/qcsrc/dpdefs/post.qh b/qcsrc/dpdefs/post.qh index 16fd93450..70e5f3784 100644 --- a/qcsrc/dpdefs/post.qh +++ b/qcsrc/dpdefs/post.qh @@ -11,8 +11,8 @@ #undef setcolor #ifdef MENUQC - #define NULL (0, null_entity) + #define NULL (RVALUE, null_entity) #define world NULL #else - #define NULL (0, world) + #define NULL (RVALUE, world) #endif diff --git a/qcsrc/lib/macro.qh b/qcsrc/lib/macro.qh index 1541b9997..f2ec6df4a 100644 --- a/qcsrc/lib/macro.qh +++ b/qcsrc/lib/macro.qh @@ -9,6 +9,9 @@ #define MACRO_END } while (0) #endif +/** Marker for use in (RVALUE, (expr)) */ +#define RVALUE 0 + #define _CAT(a, b) a ## b #define CAT(a, b) _CAT(a, b) diff --git a/qcsrc/lib/misc.qh b/qcsrc/lib/misc.qh index 21e0c5239..6c29a4b88 100644 --- a/qcsrc/lib/misc.qh +++ b/qcsrc/lib/misc.qh @@ -10,6 +10,7 @@ #include "p99.qh" #define OVERLOAD(F, ...) P99_IF_EMPTY(__VA_ARGS__)(P99_PASTE2(F, _00)())(P99_PASTE3(F, _, P00_NARG(__VA_ARGS__))(__VA_ARGS__)) + /** for use within a macro */ #define OVERLOAD_(F, ...) P99_IF_EMPTY(__VA_ARGS__)(P99_PASTE2(F, _00)())(P99_PASTE3(F, _, P00_NARG(__VA_ARGS__))(__VA_ARGS__)) #else #define EVAL(...) __VA_ARGS__ diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index f4c246f33..0a61cc003 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,10 +11,10 @@ // Step 2: const self #if 1 - #define self (0, 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() @@ -32,7 +34,7 @@ // Step 5: this should work #if 1 #undef self - #define self (0, this) + #define self (RVALUE, this) #endif // Step 6: remove SELFPARAM, add parameters @@ -56,11 +58,11 @@ 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) + (RVALUE, (e).self##T) #define _SELFWRAP_SET(T, e, f) \ ((e).__##T = (f)) #define _SELFWRAP_GET(T, e) \ - (0, (e).__##T) + (RVALUE, (e).__##T) SELFWRAP(think, void, (), (entity this), (this)) #define setthink(e, f) SELFWRAP_SET(think, e, f) diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index 4642f7640..1100c474c 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -33,8 +33,8 @@ int g_magic_stats_hole = 0; void stats_get() {} #define STAT(...) EVAL_STAT(OVERLOAD(STAT, __VA_ARGS__)) #define EVAL_STAT(...) __VA_ARGS__ - #define STAT_1(id) STAT_2(id, NULL) - #define STAT_2(id, cl) (0, _STAT(id)) + #define STAT_1(id) (RVALUE, _STAT(id)) + #define STAT_2(id, cl) STAT_1(id) #define getstat_int(id) getstati(id, 0, 24) #define getstat_bool(id) boolean(getstati(id)) @@ -61,9 +61,14 @@ int g_magic_stats_hole = 0; } #define REGISTER_STAT_3(x, T, expr) REGISTER_STAT_2(x, T) #elif defined(SVQC) + /** Internal use only */ + entity STATS; /** Add all registered stats, access with `STAT(ID, player)` or `.type stat = _STAT(ID); player.stat` */ void stats_add() {} - #define STAT(id, cl) (cl)._STAT(id) + #define STAT(...) EVAL_STAT(OVERLOAD_(STAT, __VA_ARGS__)) + #define EVAL_STAT(...) __VA_ARGS__ + #define STAT_1(id) (RVALUE, STAT_2(id, STATS)) + #define STAT_2(id, cl) (cl)._STAT(id) #define addstat_int(id, fld) addstat(id, AS_INT, fld) #define addstat_bool(id, fld) addstat(id, AS_INT, fld) @@ -83,9 +88,10 @@ int g_magic_stats_hole = 0; const int AS_FLOAT = 8; .int __stat_null; - /** Prevent engine stats being sent */ - STATIC_INIT(stats_clear) + STATIC_INIT(stats) { + STATS = new(stats); + // Prevent engine stats being sent int r = STATS_ENGINE_RESERVE; for (int i = 0, n = 256 - r; i < n; ++i) { #define X(_, name, id) if (i == id) continue; @@ -111,10 +117,11 @@ int g_magic_stats_hole = 0; addstat_##T(STAT_##id.m_id, fld); \ } void GlobalStats_update(entity this) {} + /** TODO: do we want the global copy to update? */ #define REGISTER_STAT_3(id, T, expr) \ REGISTER_STAT_2(id, T); \ [[accumulate]] void GlobalStats_update(entity this) { STAT(id, this) = (expr); } \ - STATIC_INIT(worldstat_##id) { entity this = NULL; STAT(id, this) = (expr); } + STATIC_INIT(worldstat_##id) { entity this = STATS; STAT(id, this) = (expr); } #else #define REGISTER_STAT_2(id, type) #define REGISTER_STAT_3(id, T, expr) diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index dfad188fa..f8f856f06 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -521,7 +521,7 @@ void detect_maptype() o.y += random() * (world.maxs.y - world.mins.y); o.z += random() * (world.maxs.z - world.mins.z); - tracebox(o, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), o - '0 0 32768', MOVE_WORLDONLY, NULL); + tracebox(o, STAT(PL_MIN), STAT(PL_MAX), o - '0 0 32768', MOVE_WORLDONLY, NULL); if(trace_fraction == 1) continue;