From 8809d457e5a0819b8b81b00894edae1d0721a169 Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 27 Aug 2015 12:45:07 +1000 Subject: [PATCH] Extract mean --- qcsrc/lib/Mean.qh | 29 +++++++++++++++++++++++++++++ qcsrc/lib/_all.inc | 1 + qcsrc/server/anticheat.qc | 25 ------------------------- 3 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 qcsrc/lib/Mean.qh diff --git a/qcsrc/lib/Mean.qh b/qcsrc/lib/Mean.qh new file mode 100644 index 000000000..19d9f384d --- /dev/null +++ b/qcsrc/lib/Mean.qh @@ -0,0 +1,29 @@ +#ifndef MEAN_H +#define MEAN_H + +void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight) +{ + if (weight == 0) + return; + if (mean == 0) + e.(a) *= pow(value, weight); + else + e.(a) += pow(value, mean) * weight; + e.(c) += weight; +} + +float mean_evaluate(entity e, .float a, .float c, float mean) +{ + if (e.(c) == 0) + return 0; + if (mean == 0) + return pow(e.(a), 1.0 / e.(c)); + else + return pow(e.(a) / e.(c), 1.0 / mean); +} + +#define MEAN_ACCUMULATE(prefix,v,w) mean_accumulate(self,prefix##_accumulator,prefix##_count,prefix##_mean,v,w) +#define MEAN_EVALUATE(prefix) mean_evaluate(self,prefix##_accumulator,prefix##_count,prefix##_mean) +#define MEAN_DECLARE(prefix,m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator + +#endif diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index a3bcbcb5c..ee665bcf9 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -6,6 +6,7 @@ #include "Draw.qh" #include "I18N.qh" #include "Lazy.qh" +#include "Mean.qh" #include "Nil.qh" #include "noise.qc" #include "OO.qh" diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index d065cb59f..6647633ff 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -13,31 +13,6 @@ .float anticheat_jointime; -void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight) -{ - if (weight == 0) - return; - if (mean == 0) - e.(a) *= pow(value, weight); - else - e.(a) += pow(value, mean) * weight; - e.(c) += weight; -} - -float mean_evaluate(entity e, .float a, .float c, float mean) -{ - if (e.(c) == 0) - return 0; - if (mean == 0) - return pow(e.(a), 1.0 / e.(c)); - else - return pow(e.(a) / e.(c), 1.0 / mean); -} - -#define MEAN_ACCUMULATE(prefix,v,w) mean_accumulate(self,prefix##_accumulator,prefix##_count,prefix##_mean,v,w) -#define MEAN_EVALUATE(prefix) mean_evaluate(self,prefix##_accumulator,prefix##_count,prefix##_mean) -#define MEAN_DECLARE(prefix,m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator - .float anticheat_fixangle_endtime; float anticheat_div0_evade_evasion_delta; -- 2.39.2