From: TimePath Date: Sun, 29 Nov 2015 00:32:01 +0000 (+1100) Subject: Stats: port vectors X-Git-Tag: xonotic-v0.8.2~1609^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=229104225e03b92717b3b2760e6b6d2c5a2cddfe;p=xonotic%2Fxonotic-data.pk3dir.git Stats: port vectors --- diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 80468a62b..7d8624df4 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -267,22 +267,12 @@ vector autocvar_sv_player_headsize = '24 24 12'; // not so constant -#ifdef SVQC -#define PL_VIEW_OFS autocvar_sv_player_viewoffset -#define PL_MIN autocvar_sv_player_mins -#define PL_MAX autocvar_sv_player_maxs -#define PL_CROUCH_VIEW_OFS autocvar_sv_player_crouch_viewoffset -#define PL_CROUCH_MIN autocvar_sv_player_crouch_mins -#define PL_CROUCH_MAX autocvar_sv_player_crouch_maxs -#define PL_HEAD autocvar_sv_player_headsize -#elif defined(CSQC) -#define PL_VIEW_OFS vec3(getstatf(STAT_PL_VIEW_OFS1), getstatf(STAT_PL_VIEW_OFS2), getstatf(STAT_PL_VIEW_OFS3)) -#define PL_MIN vec3(getstatf(STAT_PL_MIN1), getstatf(STAT_PL_MIN2), getstatf(STAT_PL_MIN3)) -#define PL_MAX vec3(getstatf(STAT_PL_MAX1), getstatf(STAT_PL_MAX2), getstatf(STAT_PL_MAX3)) -#define PL_CROUCH_VIEW_OFS vec3(getstatf(STAT_PL_CROUCH_VIEW_OFS1), getstatf(STAT_PL_CROUCH_VIEW_OFS2), getstatf(STAT_PL_CROUCH_VIEW_OFS3)) -#define PL_CROUCH_MIN vec3(getstatf(STAT_PL_CROUCH_MIN1), getstatf(STAT_PL_CROUCH_MIN2), getstatf(STAT_PL_CROUCH_MIN3)) -#define PL_CROUCH_MAX vec3(getstatf(STAT_PL_CROUCH_MAX1), getstatf(STAT_PL_CROUCH_MAX2), getstatf(STAT_PL_CROUCH_MAX3)) -#endif +#define PL_VIEW_OFS STAT(PL_VIEW_OFS, NULL) +#define PL_CROUCH_VIEW_OFS STAT(PL_CROUCH_VIEW_OFS, NULL) +#define PL_MIN STAT(PL_MIN, NULL) +#define PL_CROUCH_MIN STAT(PL_CROUCH_MIN, NULL) +#define PL_MAX STAT(PL_MAX, NULL) +#define PL_CROUCH_MAX STAT(PL_CROUCH_MAX, NULL) // a bit more constant const vector PL_MAX_CONST = '16 16 45'; diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index f55bf3351..71bc63e1b 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -30,42 +30,8 @@ float Physics_ClientOption(entity pl, string option) return cvar(strcat("sv_", option)); } -void Physics_AddStats() -{ - // static view offset and hitbox vectors - // networked for all you bandwidth pigs out there - addstat(STAT_PL_VIEW_OFS1, AS_FLOAT, stat_pl_view_ofs_x); - addstat(STAT_PL_VIEW_OFS2, AS_FLOAT, stat_pl_view_ofs_y); - addstat(STAT_PL_VIEW_OFS3, AS_FLOAT, stat_pl_view_ofs_z); - addstat(STAT_PL_CROUCH_VIEW_OFS1, AS_FLOAT, stat_pl_crouch_view_ofs_x); - addstat(STAT_PL_CROUCH_VIEW_OFS2, AS_FLOAT, stat_pl_crouch_view_ofs_y); - addstat(STAT_PL_CROUCH_VIEW_OFS3, AS_FLOAT, stat_pl_crouch_view_ofs_z); - - addstat(STAT_PL_MIN1, AS_FLOAT, stat_pl_min_x); - addstat(STAT_PL_MIN2, AS_FLOAT, stat_pl_min_y); - addstat(STAT_PL_MIN3, AS_FLOAT, stat_pl_min_z); - addstat(STAT_PL_MAX1, AS_FLOAT, stat_pl_max_x); - addstat(STAT_PL_MAX2, AS_FLOAT, stat_pl_max_y); - addstat(STAT_PL_MAX3, AS_FLOAT, stat_pl_max_z); - addstat(STAT_PL_CROUCH_MIN1, AS_FLOAT, stat_pl_crouch_min_x); - addstat(STAT_PL_CROUCH_MIN2, AS_FLOAT, stat_pl_crouch_min_y); - addstat(STAT_PL_CROUCH_MIN3, AS_FLOAT, stat_pl_crouch_min_z); - addstat(STAT_PL_CROUCH_MAX1, AS_FLOAT, stat_pl_crouch_max_x); - addstat(STAT_PL_CROUCH_MAX2, AS_FLOAT, stat_pl_crouch_max_y); - addstat(STAT_PL_CROUCH_MAX3, AS_FLOAT, stat_pl_crouch_max_z); -} - void Physics_UpdateStats(entity this, float maxspd_mod) { - // blah - this.stat_pl_view_ofs = PL_VIEW_OFS; - this.stat_pl_crouch_view_ofs = PL_CROUCH_VIEW_OFS; - - this.stat_pl_min = PL_MIN; - this.stat_pl_max = PL_MAX; - this.stat_pl_crouch_min = PL_CROUCH_MIN; - this.stat_pl_crouch_max = PL_CROUCH_MAX; - STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw"), maxspd_mod); STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw")) ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw"), maxspd_mod) diff --git a/qcsrc/common/physics.qh b/qcsrc/common/physics.qh index 114d0418b..682e58712 100644 --- a/qcsrc/common/physics.qh +++ b/qcsrc/common/physics.qh @@ -190,12 +190,6 @@ bool IsFlying(entity a); bool Physics_Valid(string thecvar); - .vector stat_pl_view_ofs; - .vector stat_pl_crouch_view_ofs; - - .vector stat_pl_min, stat_pl_max; - .vector stat_pl_crouch_min, stat_pl_crouch_max; - .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW); .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED); diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index 84ce034ed..a57555edf 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -17,39 +17,17 @@ const int STAT_ITEMS = 15; // .items | .items2 << 23 | serverflags << 28 const int STAT_VIEWHEIGHT = 16; // .view_ofs_z #endif -enum { - STAT_WEAPONS = 32, - STAT_WEAPONS2, - STAT_WEAPONS3, +REGISTER_STAT(WEAPONS, vectori) +REGISTER_STAT(WEAPONSINMAP, vectori) - STAT_WEAPONSINMAP, - STAT_WEAPONSINMAP2, - STAT_WEAPONSINMAP3, +REGISTER_STAT(PL_VIEW_OFS, vector, autocvar_sv_player_viewoffset) +REGISTER_STAT(PL_CROUCH_VIEW_OFS, vector, autocvar_sv_player_crouch_viewoffset) - STAT_PL_VIEW_OFS1, - STAT_PL_VIEW_OFS2, - STAT_PL_VIEW_OFS3, +REGISTER_STAT(PL_MIN, vector, autocvar_sv_player_mins) +REGISTER_STAT(PL_CROUCH_MIN, vector, autocvar_sv_player_crouch_mins) - STAT_PL_CROUCH_VIEW_OFS1, - STAT_PL_CROUCH_VIEW_OFS2, - STAT_PL_CROUCH_VIEW_OFS3, - - STAT_PL_MIN1, - STAT_PL_MIN2, - STAT_PL_MIN3, - - STAT_PL_MAX1, - STAT_PL_MAX2, - STAT_PL_MAX3, - - STAT_PL_CROUCH_MIN1, - STAT_PL_CROUCH_MIN2, - STAT_PL_CROUCH_MIN3, - - STAT_PL_CROUCH_MAX1, - STAT_PL_CROUCH_MAX2, - STAT_PL_CROUCH_MAX3, -}; +REGISTER_STAT(PL_MAX, vector, autocvar_sv_player_maxs) +REGISTER_STAT(PL_CROUCH_MAX, vector, autocvar_sv_player_crouch_maxs) REGISTER_STAT(KH_KEYS, int) /** weapon requested to switch to; next WANTED weapon (for HUD) */ diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 6315808e0..214f0d2c5 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -70,22 +70,6 @@ WepSet WepSet_FromWeapon(int a) { return '1 0 0' * power2of(a); } #ifdef SVQC -void WepSet_AddStat() -{ - addstat(STAT_WEAPONS, AS_INT, weapons_x); - if (Weapons_MAX > 24) - addstat(STAT_WEAPONS2, AS_INT, weapons_y); - if (Weapons_MAX > 48) - addstat(STAT_WEAPONS3, AS_INT, weapons_z); -} -void WepSet_AddStat_InMap() -{ - addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x); - if (Weapons_MAX > 24) - addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y); - if (Weapons_MAX > 48) - addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z); -} void WriteWepSet(float dst, WepSet w) { if (Weapons_MAX > 48) @@ -99,23 +83,11 @@ void WriteWepSet(float dst, WepSet w) #ifdef CSQC WepSet WepSet_GetFromStat() { - WepSet w = '0 0 0'; - w.x = getstati(STAT_WEAPONS); - if (Weapons_MAX > 24) - w.y = getstati(STAT_WEAPONS2); - if (Weapons_MAX > 48) - w.z = getstati(STAT_WEAPONS3); - return w; + return STAT(WEAPONS); } WepSet WepSet_GetFromStat_InMap() { - WepSet w = '0 0 0'; - w_x = getstati(STAT_WEAPONSINMAP); - if (Weapons_MAX > 24) - w_y = getstati(STAT_WEAPONSINMAP2); - if (Weapons_MAX > 48) - w_z = getstati(STAT_WEAPONSINMAP3); - return w; + return STAT(WEAPONSINMAP); } WepSet ReadWepSet() { diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index af2795064..baa11371a 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -10,8 +10,6 @@ typedef vector WepSet; #define WEPSET(id) WepSet_FromWeapon(WEP_##id.m_id) WepSet WepSet_FromWeapon(int a); #ifdef SVQC -void WepSet_AddStat(); -void WepSet_AddStat_InMap(); void WriteWepSet(float dest, WepSet w); #endif diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 59ddf25ff..8ad8be56e 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -50,17 +50,27 @@ entity this = inst; \ ns##_##id = this; \ this.registered_id = #id; \ - this.fld = array##_COUNT; \ - _##array[array##_COUNT++] = this; \ - if (!array##_first) array##_first = this; \ - if (array##_last) array##_last.REGISTRY_NEXT = this; \ - array##_last = this; \ + REGISTRY_PUSH(array, fld, this); \ Register_##ns##_##id##_init(this); \ Register_##ns##_##id##_init_post(this); \ } \ ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \ REGISTER_INIT(ns, id) +#define REGISTRY_PUSH(array, fld, it) do { \ + it.fld = array##_COUNT; \ + _##array[array##_COUNT++] = it; \ + if (!array##_first) array##_first = it; \ + if (array##_last) array##_last.REGISTRY_NEXT = it; \ + array##_last = it; \ +} while (0) + +#define REGISTRY_RESERVE(registry, fld, id, suffix) do { \ + entity e = new(registry_reserved); \ + e.registered_id = #id #suffix; \ + REGISTRY_PUSH(registry, fld, e); \ +} while (0) + /** internal next pointer */ #define REGISTRY_NEXT enemy .entity REGISTRY_NEXT; diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index 929c5902e..32927f4bd 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -7,6 +7,7 @@ #include "sort.qh" .int m_id; +typedef vector vectori; #define REGISTER_STAT(...) EVAL(OVERLOAD(REGISTER_STAT, __VA_ARGS__)) #if defined(CSQC) @@ -19,17 +20,23 @@ #define getstat_int(id) getstati(id, 0, 24) #define getstat_bool(id) boolean(getstati(id)) #define getstat_float(id) getstatf(id) + #define getstat_vector(id) vec3(getstat_float(id + 0), getstat_float(id + 1), getstat_float(id + 2)) + #define getstat_vectori(id) vec3(getstat_int(id + 0), getstat_int(id + 1), getstat_int(id + 2)) #define _STAT(id) g_stat_##id - #define REGISTER_STAT_2(id, type) \ - type _STAT(id); \ + #define REGISTER_STAT_2(id, T) \ + T _STAT(id); \ REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \ { \ make_pure(this); \ + if (#T == "vector" || #T == "vectori") { \ + REGISTRY_RESERVE(Stats, m_id, id, _y); \ + REGISTRY_RESERVE(Stats, m_id, id, _z); \ + } \ } \ [[accumulate]] void stats_get() \ { \ - _STAT(id) = getstat_##type(STAT_##id.m_id); \ + _STAT(id) = getstat_##T(STAT_##id.m_id); \ } #define REGISTER_STAT_3(x, T, expr) REGISTER_STAT(x, T) #elif defined(SVQC) @@ -40,6 +47,16 @@ #define addstat_int(id, fld) addstat(id, AS_INT, fld) #define addstat_bool(id, fld) addstat(id, AS_INT, fld) #define addstat_float(id, fld) addstat(id, AS_FLOAT, fld) + #define addstat_vector(id, fld) do { \ + addstat_float(id + 0, fld##_x); \ + addstat_float(id + 1, fld##_y); \ + addstat_float(id + 2, fld##_z); \ + } while (0) + #define addstat_vectori(id, fld) do { \ + addstat_int(id + 0, fld##_x); \ + addstat_int(id + 1, fld##_y); \ + addstat_int(id + 2, fld##_z); \ + } while (0) const int AS_STRING = 1; const int AS_INT = 2; const int AS_FLOAT = 8; @@ -55,24 +72,31 @@ } #define _STAT(id) stat_##id - #define REGISTER_STAT_2(id, type) \ - .type _STAT(id); \ + #define REGISTER_STAT_2(id, T) \ + .T _STAT(id); \ REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \ { \ make_pure(this); \ + if (#T == "vector" || #T == "vectori") { \ + REGISTRY_RESERVE(Stats, m_id, id, _y); \ + REGISTRY_RESERVE(Stats, m_id, id, _z); \ + } \ } \ [[accumulate]] void stats_add() \ { \ - addstat_##type(STAT_##id.m_id, _STAT(id)); \ + addstat_##T(STAT_##id.m_id, _STAT(id)); \ } void GlobalStats_update(entity this) {} - #define REGISTER_STAT_3(x, T, expr) REGISTER_STAT(x, T); [[accumulate]] void GlobalStats_update(entity this) { STAT(x, this) = (expr); } + #define REGISTER_STAT_3(x, T, expr) \ + REGISTER_STAT(x, T); \ + [[accumulate]] void GlobalStats_update(entity this) { STAT(x, this) = (expr); } \ + STATIC_INIT(worldstat_##x) { entity this = world; STAT(x, this) = (expr); } #else #define REGISTER_STAT_2(id, type) #define REGISTER_STAT_3(x, T, expr) #endif -const int STATS_ENGINE_RESERVE = 32 + (8 * 3); // Not sure how to handle vector stats yet, reserve them too +const int STATS_ENGINE_RESERVE = 32; REGISTRY(Stats, 256 - STATS_ENGINE_RESERVE) REGISTER_REGISTRY(RegisterStats) diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 4994c1936..ddbbfd9e4 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2424,8 +2424,8 @@ void PlayerPreThink () if (!self.crouch) { self.crouch = true; - self.view_ofs = self.stat_pl_crouch_view_ofs; - setsize (self, self.stat_pl_crouch_min, self.stat_pl_crouch_max); + self.view_ofs = STAT(PL_CROUCH_VIEW_OFS, self); + setsize (self, STAT(PL_CROUCH_MIN, self), STAT(PL_CROUCH_MAX, self)); // setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway } } @@ -2433,12 +2433,12 @@ void PlayerPreThink () { if (self.crouch) { - tracebox(self.origin, self.stat_pl_min, self.stat_pl_max, self.origin, false, self); + tracebox(self.origin, STAT(PL_MIN, self), STAT(PL_MAX, self), self.origin, false, self); if (!trace_startsolid) { self.crouch = false; - self.view_ofs = self.stat_pl_view_ofs; - setsize (self, self.stat_pl_min, self.stat_pl_max); + self.view_ofs = STAT(PL_VIEW_OFS, self); + setsize (self, STAT(PL_MIN, self), STAT(PL_MAX, self)); } } } diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index a54ca8cc3..e52801a92 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -256,7 +256,8 @@ void FixClientCvars(entity e); // WEAPONTODO: remove this WepSet weaponsInMap; -.WepSet weaponsinmap; +#define weapons _STAT(WEAPONS) +#define weaponsinmap _STAT(WEAPONSINMAP) .float respawn_countdown; // next number to count diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index e0ea152a5..2fc291b96 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -558,7 +558,6 @@ void Nagger_Init(); void ClientInit_Spawn(); void WeaponStats_Init(); void WeaponStats_Shutdown(); -void Physics_AddStats(); spawnfunc(worldspawn) { float fd, l, j, n; @@ -755,13 +754,8 @@ spawnfunc(worldspawn) WeaponStats_Init(); - WepSet_AddStat(); - WepSet_AddStat_InMap(); Nagger_Init(); - // physics - Physics_AddStats(); - next_pingtime = time + 5; detect_maptype();