From 7adfa50770480660adc22c71077b525f952ecc6a Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 13 Aug 2016 16:53:19 +1000 Subject: [PATCH] Stats: allow manual ID override --- qcsrc/client/autocvars.qh | 1 - qcsrc/client/view.qc | 4 ---- qcsrc/lib/stats.qh | 30 ++++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index ec9ac10ae..3b9840333 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -475,4 +475,3 @@ float autocvar_crosshair_rpc_alpha = 1; float autocvar_crosshair_rpc_size = 1; int autocvar_cl_nade_timer; bool autocvar_cl_items_nofade; -float autocvar_slowmo; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 1458efe15..b0b98f977 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1408,10 +1408,6 @@ void CSQC_UpdateView(entity this, float w, float h) else view_quality = 1; - // this needs to be updated manually now due to the destruction of engine physics stats - if(!isdemo() && autocvar_slowmo != STAT(MOVEVARS_TIMESCALE)) - cvar_set("slowmo", ftos(STAT(MOVEVARS_TIMESCALE))); - button_attack2 = PHYS_INPUT_BUTTON_ATCK2(this); button_zoom = PHYS_INPUT_BUTTON_ZOOM(this); diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index 8aaacdec4..4642f7640 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -8,6 +8,24 @@ .int m_id; USING(vectori, vector); +const int STATS_ENGINE_RESERVE = 32; +// must be listed in ascending order +#define MAGIC_STATS(_, x) \ + _(x, MOVEVARS_TIMESCALE, 241) \ + /**/ + +int g_magic_stats_hole = 0; + +#define MAGIC_STATS_FIX_MANUAL(it, var, id) \ + if (it.registered_id == "STAT_" #var) { --g_magic_stats_hole; it.m_id = id; } else + +#define MAGIC_STATS_FIX_AUTO(it, var, id) \ + if (it.m_id == id) { ++g_magic_stats_hole; ++it.m_id; } + +#define MAGIC_STATS_FIX(it) \ + it.m_id += g_magic_stats_hole; \ + MAGIC_STATS(MAGIC_STATS_FIX_MANUAL, it) { MAGIC_STATS(MAGIC_STATS_FIX_AUTO, it) } + #define REGISTER_STAT(...) EVAL_REGISTER_STAT(OVERLOAD(REGISTER_STAT, __VA_ARGS__)) #define EVAL_REGISTER_STAT(...) __VA_ARGS__ #if defined(CSQC) @@ -68,8 +86,11 @@ USING(vectori, vector); /** Prevent engine stats being sent */ STATIC_INIT(stats_clear) { - int r = 32; + int r = STATS_ENGINE_RESERVE; for (int i = 0, n = 256 - r; i < n; ++i) { + #define X(_, name, id) if (i == id) continue; + MAGIC_STATS(X, ); + #undef X addstat(r + i, AS_INT, __stat_null); } } @@ -99,15 +120,16 @@ USING(vectori, vector); #define REGISTER_STAT_3(id, T, expr) #endif -const int STATS_ENGINE_RESERVE = 32; - REGISTRY(Stats, 256 - STATS_ENGINE_RESERVE) REGISTER_REGISTRY(Stats) REGISTRY_SORT(Stats) REGISTRY_CHECK(Stats) STATIC_INIT(RegisterStats_renumber) { - FOREACH(Stats, true, it.m_id = STATS_ENGINE_RESERVE + i); + FOREACH(Stats, true, { + it.m_id = STATS_ENGINE_RESERVE + i; + MAGIC_STATS_FIX(it); + }); } #ifdef SVQC STATIC_INIT(stats_add) { stats_add(); } -- 2.39.2