]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Stats: registry
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Nov 2015 01:48:56 +0000 (12:48 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Nov 2015 01:49:13 +0000 (12:49 +1100)
qcsrc/client/hud/panel/modicons.qc
qcsrc/client/view.qc
qcsrc/common/constants.qh
qcsrc/common/stats.qh
qcsrc/lib/_all.inc
qcsrc/lib/stats.qh [new file with mode: 0644]
qcsrc/server/mutators/mutator/gamemode_keyhunt.qc

index 238491848c7d0a4e0a3d44e46587043bc27822cb..a8cb7c2660042a16077b2069eed0b89f64436e79 100644 (file)
@@ -279,7 +279,7 @@ void HUD_Mod_KH(vector pos, vector mySize)
 
        // Read current state
 
-       int state = getstati(STAT_KH_KEYS);
+       int state = STAT(KH_KEYS);
        int i, key_state;
        int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
        all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
index 6f37f39e346d1a272ca3ada94ac1eecdf80ff19d..4f5fdc3b8de0daea1ad5c08a0fe9303fbed24abd 100644 (file)
@@ -1064,6 +1064,7 @@ void CSQC_UpdateView(float w, float h)
 
        ++framecount;
 
+       stats_get();
        hud = getstati(STAT_HUD);
 
        if(hud != HUD_NORMAL && lasthud == HUD_NORMAL)
index 192b8f6a1bd04174469e25af57d09f3269f792cb..80468a62b7a8d2a308dfeae29fca973ef11f14c0 100644 (file)
 // Revision 22: hook shot origin
 #define CSQC_REVISION 22
 
-const int AS_STRING = 1;
-const int AS_INT = 2;
-const int AS_FLOAT_TRUNCATED = 2;
-const int AS_FLOAT = 8;
-
 REGISTER_NET_TEMP(TE_CSQC_PICTURE)
 REGISTER_NET_TEMP(TE_CSQC_RACE)
 REGISTER_NET_TEMP(TE_CSQC_TEAMNAGGER)
@@ -112,10 +107,6 @@ const int CVAR_READONLY = 4;
 ///////////////////////////
 // csqc communication stuff
 
-const int CTF_STATE_ATTACK = 1;
-const int CTF_STATE_DEFEND = 2;
-const int CTF_STATE_COMMANDER = 3;
-
 const int HUD_NORMAL = 0;
 const int HUD_BUMBLEBEE_GUN = 25;
 
index 9bdcb5773a5e4bcff57fe8079b53542babfa2bef..a09dc9ca88afa039601243eba384384471030cef 100644 (file)
@@ -52,8 +52,8 @@ const int STAT_VIEWZOOM               = 21;
 // 29 empty?
 // 30 empty?
 // 31 empty?
-const int STAT_KH_KEYS                = 32;
-const int STAT_CTF_STATE              = 33;
+REGISTER_STAT(KH_KEYS, int)
+// 33 empty?
 // 34 empty?
 const int STAT_WEAPONS                = 35;
 const int STAT_SWITCHWEAPON           = 36;
index cffa8f7223112bd286813b5a8d98b926b81ddcd6..ceb59b780a7db71dd87640d9831cd78d810534b5 100644 (file)
@@ -62,6 +62,7 @@
 #include "sort.qh"
 #include "spawnfunc.qh"
 #include "static.qh"
+#include "stats.qh"
 #include "string.qh"
 #include "struct.qh"
 #include "test.qc"
diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh
new file mode 100644 (file)
index 0000000..2b0d55d
--- /dev/null
@@ -0,0 +1,72 @@
+#ifndef LIB_STATS_H
+#define LIB_STATS_H
+
+#include "registry.qh"
+#include "sort.qh"
+
+.int m_id;
+
+#if defined(CSQC)
+       /** Get all stats and store them as globals, access with `STAT(ID)` */
+       void stats_get() {}
+       #define STAT(...) EVAL(OVERLOAD(STAT, __VA_ARGS__))
+    #define STAT_1(id) STAT_2(id, NULL)
+       #define STAT_2(id, cl) (0, _STAT(id))
+
+       #define getstat_int(id) getstati(id, 0, 24)
+       #define getstat_bool(id) boolean(getstati(id))
+       #define getstat_float(id) getstatf(id)
+
+       #define _STAT(id) g_stat_##id
+       #define REGISTER_STAT(id, type) \
+               type _STAT(id); \
+               REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
+               { \
+                       make_pure(this); \
+               } \
+               [[accumulate]] void stats_get() \
+               { \
+                       _STAT(id) = getstat_##type(STAT_##id.m_id); \
+               }
+#elif defined(SVQC)
+       /** 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 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)
+       const int AS_STRING = 1;
+       const int AS_INT = 2;
+       const int AS_FLOAT = 8;
+
+       #define _STAT(id) stat_##id
+       #define REGISTER_STAT(id, type) \
+               .type _STAT(id); \
+               REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
+               { \
+                       make_pure(this); \
+               } \
+               [[accumulate]] void stats_add() \
+               { \
+                       addstat_##type(STAT_##id.m_id, _STAT(id)); \
+               }
+#else
+       #define REGISTER_STAT(id, type)
+#endif
+
+const int STATS_ENGINE_RESERVE = 32;
+
+REGISTRY(Stats, BITS(8) - STATS_ENGINE_RESERVE)
+REGISTER_REGISTRY(RegisterStats)
+REGISTRY_SORT(Stats, 0)
+REGISTRY_CHECK(Stats)
+STATIC_INIT(RegisterStats_renumber)
+{
+       FOREACH(Stats, true, LAMBDA(it.m_id = STATS_ENGINE_RESERVE + i));
+}
+#ifdef SVQC
+STATIC_INIT(stats_add) { stats_add(); }
+#endif
+
+#endif
index 8eea91758699920f50dd97334c0bcd1f548615a1..8d4240e29aa3478b35dbfdfc6b0e0e95179dc1d6 100644 (file)
@@ -102,7 +102,7 @@ float kh_no_radar_circles;
 //     bits  5- 9: team of key 2, or 0 for no such key, or 30 for dropped, or 31 for self
 //     bits 10-14: team of key 3, or 0 for no such key, or 30 for dropped, or 31 for self
 //     bits 15-19: team of key 4, or 0 for no such key, or 30 for dropped, or 31 for self
-.float kh_state;
+.float kh_state = _STAT(KH_KEYS);
 .float siren_time;  //  time delay the siren
 //.float stuff_time;  //  time delay to stuffcmd a cvar
 
@@ -1095,8 +1095,6 @@ void kh_Initialize()  // sets up th KH environment
        kh_controller.model = "";
        kh_controller.modelindex = 0;
 
-       addstat(STAT_KH_KEYS, AS_INT, kh_state);
-
        kh_ScoreRules(kh_teams);
 }