From dd6003ec64820b28de476d18541211e6aab7f410 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 7 Nov 2015 12:48:56 +1100 Subject: [PATCH] Stats: registry --- qcsrc/client/hud/panel/modicons.qc | 2 +- qcsrc/client/view.qc | 1 + qcsrc/common/constants.qh | 9 --- qcsrc/common/stats.qh | 4 +- qcsrc/lib/_all.inc | 1 + qcsrc/lib/stats.qh | 72 +++++++++++++++++++ .../mutators/mutator/gamemode_keyhunt.qc | 4 +- 7 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 qcsrc/lib/stats.qh diff --git a/qcsrc/client/hud/panel/modicons.qc b/qcsrc/client/hud/panel/modicons.qc index 238491848..a8cb7c266 100644 --- a/qcsrc/client/hud/panel/modicons.qc +++ b/qcsrc/client/hud/panel/modicons.qc @@ -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; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 6f37f39e3..4f5fdc3b8 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 192b8f6a1..80468a62b 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -26,11 +26,6 @@ // 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; diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index 9bdcb5773..a09dc9ca8 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -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; diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index cffa8f722..ceb59b780 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -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 index 000000000..2b0d55dc5 --- /dev/null +++ b/qcsrc/lib/stats.qh @@ -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 diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index 8eea91758..8d4240e29 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -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); } -- 2.39.2