]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Stats: port vectors
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 29 Nov 2015 00:32:01 +0000 (11:32 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 29 Nov 2015 00:32:01 +0000 (11:32 +1100)
qcsrc/common/constants.qh
qcsrc/common/physics.qc
qcsrc/common/physics.qh
qcsrc/common/stats.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/lib/registry.qh
qcsrc/lib/stats.qh
qcsrc/server/cl_client.qc
qcsrc/server/defs.qh
qcsrc/server/g_world.qc

index 80468a62b7a8d2a308dfeae29fca973ef11f14c0..7d8624df4cdd21b52ba6b84854101b004bb3a6b9 100644 (file)
@@ -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';
index f55bf3351cf6edeb34610bcc9aea6fe33b190bc7..71bc63e1beb059b28eef78d6bb5864dc52d74a57 100644 (file)
@@ -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)
index 114d0418b1010b485d938b94ca30d1575fe35da2..682e58712fe718a15c5639fcbbe6d893391fd35c 100644 (file)
@@ -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);
 
index 84ce034ed07cd859ae6b7ffff4e149a1c58273c8..a57555edfa5b7b4f37bdc6a0fd962633e60f587f 100644 (file)
@@ -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) */
index 6315808e06ad45b47d845fc673b0db7cb6e8c08e..214f0d2c5c88e9c13d3737d3b2200fc6fd28c24a 100644 (file)
@@ -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()
 {
index af279506448160bb2cf89b5c60fed8c60d8ac237..baa11371acb4f598c34975eeb770876fcf136516 100644 (file)
@@ -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
 
index 59ddf25ff87ee30c627f14fc4cfd25b4ec23b072..8ad8be56e213f7704276f9b3e77dd2b479181aa5 100644 (file)
                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;
index 929c5902e8335ddd0ada8a66675edf9ab0cbd05d..32927f4bd8b7793eecfcdb0fad49908662e53254 100644 (file)
@@ -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)
        #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)
        #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;
        }
 
        #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)
index 4994c193652cd65b8266ae53c6262768bf669773..ddbbfd9e457401059059d42f0cdbadf2fc430144 100644 (file)
@@ -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));
                                }
                        }
                }
index a54ca8cc3b92374e282139ff4cd5a62aebd64eae..e52801a92c87e6be0688eb76662dd96b6cf82be0 100644 (file)
@@ -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
 
index e0ea152a5d1405f36bccf1cfe454999bc43c971c..2fc291b9663b3ae30ec779a3a86507e29541cdfc 100644 (file)
@@ -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();