From: TimePath Date: Thu, 27 Aug 2015 03:01:10 +0000 (+1000) Subject: Extract a few more functions X-Git-Tag: xonotic-v0.8.2~2015 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=15218c58cd7fc3878715aa71b8358a0ea0585638;p=xonotic%2Fxonotic-data.pk3dir.git Extract a few more functions --- diff --git a/qcsrc/common/triggers/subs.qc b/qcsrc/common/triggers/subs.qc index f21455dc5..fa7c1c5e4 100644 --- a/qcsrc/common/triggers/subs.qc +++ b/qcsrc/common/triggers/subs.qc @@ -4,18 +4,6 @@ void() SUB_CalcMoveDone; void() SUB_CalcAngleMoveDone; //void() SUB_UseTargets; -/* -================== -SUB_Remove - -Remove self -================== -*/ -void SUB_Remove() -{ - remove (self); -} - /* ================== SUB_Friction diff --git a/qcsrc/lib/Defer.qh b/qcsrc/lib/Defer.qh new file mode 100644 index 000000000..fd2619d6f --- /dev/null +++ b/qcsrc/lib/Defer.qh @@ -0,0 +1,51 @@ +#ifndef MENUQC +#ifndef DEFER_H +#define DEFER_H +#include "OO.qh" + +entityclass(Defer); +class(Defer) .entity owner; +class(Defer) .void() think; +class(Defer) .float nextthink; + +/* +================== +SUB_Remove + +Remove self +================== +*/ +void SUB_Remove() +{ + remove (self); +} + +void defer_think() +{ + entity oself; + + oself = self; + self = self.owner; + oself.think = SUB_Remove; + oself.nextthink = time; + + oself.use(); +} + +/* + Execute func() after time + fdelay. + self when func is executed = self when defer is called +*/ +void defer(float fdelay, void() func) +{ + entity e; + + e = spawn(); + e.owner = self; + e.use = func; + e.think = defer_think; + e.nextthink = time + fdelay; +} + +#endif +#endif diff --git a/qcsrc/lib/Math.qh b/qcsrc/lib/Math.qh new file mode 100644 index 000000000..a8a52907a --- /dev/null +++ b/qcsrc/lib/Math.qh @@ -0,0 +1,93 @@ +#ifndef MATH_H +#define MATH_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 + +/* +================== +crandom + +Returns a random number between -1.0 and 1.0 +================== +*/ +float crandom (void) +{ + return 2 * (random () - 0.5); +} + + +/* +================== +Angc used for animations +================== +*/ + + +float angc (float a1, float a2) +{ + float a; + + while (a1 > 180) + a1 = a1 - 360; + while (a1 < -179) + a1 = a1 + 360; + + while (a2 > 180) + a2 = a2 - 360; + while (a2 < -179) + a2 = a2 + 360; + + a = a1 - a2; + while (a > 180) + a = a - 360; + while (a < -179) + a = a + 360; + + return a; +} + +float fsnap(float val,float fsize) +{ + return rint(val / fsize) * fsize; +} + +vector vsnap(vector point,float fsize) +{ + vector vret; + + vret.x = rint(point.x / fsize) * fsize; + vret.y = rint(point.y / fsize) * fsize; + vret.z = ceil(point.z / fsize) * fsize; + + return vret; +} + +vector lerpv(float t0, vector v0, float t1, vector v1, float t) +{ + return v0 + (v1 - v0) * ((t - t0) / (t1 - t0)); +} + +#endif diff --git a/qcsrc/lib/Mean.qh b/qcsrc/lib/Mean.qh deleted file mode 100644 index 19d9f384d..000000000 --- a/qcsrc/lib/Mean.qh +++ /dev/null @@ -1,29 +0,0 @@ -#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 ee665bcf9..bf79e4e10 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -3,10 +3,11 @@ #include "Accumulate.qh" #include "Counting.qh" #include "Cvar.qh" +#include "Defer.qh" #include "Draw.qh" #include "I18N.qh" #include "Lazy.qh" -#include "Mean.qh" +#include "Math.qh" #include "Nil.qh" #include "noise.qc" #include "OO.qh" diff --git a/qcsrc/server/antilag.qc b/qcsrc/server/antilag.qc index c51d3cf5b..f152c8216 100644 --- a/qcsrc/server/antilag.qc +++ b/qcsrc/server/antilag.qc @@ -58,11 +58,6 @@ float antilag_find(entity e, float t) return -1; } -vector lerpv(float t0, vector v0, float t1, vector v1, float t) -{ - return v0 + (v1 - v0) * ((t - t0) / (t1 - t0)); -} - vector antilag_takebackorigin(entity e, float t) { int i0 = antilag_find(e, t); diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index eacba6452..01bf62f82 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -280,48 +280,6 @@ vector findbetterlocation (vector org, float mindist) return org; } -/* -================== -crandom - -Returns a random number between -1.0 and 1.0 -================== -*/ -float crandom (void) -{ - return 2 * (random () - 0.5); -} - -/* -================== -Angc used for animations -================== -*/ - - -float angc (float a1, float a2) -{ - float a; - - while (a1 > 180) - a1 = a1 - 360; - while (a1 < -179) - a1 = a1 + 360; - - while (a2 > 180) - a2 = a2 - 360; - while (a2 < -179) - a2 = a2 + 360; - - a = a1 - a2; - while (a > 180) - a = a - 360; - while (a < -179) - a = a + 360; - - return a; -} - float LOD_customize() { float d; diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 71fb2de5e..0dabbf0fa 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -1931,33 +1931,6 @@ float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float } -void defer_think() -{ - entity oself; - - oself = self; - self = self.owner; - oself.think = SUB_Remove; - oself.nextthink = time; - - oself.use(); -} - -/* - Execute func() after time + fdelay. - self when func is executed = self when defer is called -*/ -void defer(float fdelay, void() func) -{ - entity e; - - e = spawn(); - e.owner = self; - e.use = func; - e.think = defer_think; - e.nextthink = time + fdelay; -} - .string aiment_classname; .float aiment_deadflag; void SetMovetypeFollow(entity ent, entity e) diff --git a/qcsrc/server/pathlib.qc b/qcsrc/server/pathlib.qc index bfd9c0b35..40e23387d 100644 --- a/qcsrc/server/pathlib.qc +++ b/qcsrc/server/pathlib.qc @@ -63,22 +63,6 @@ void pathlib_deletepath(entity start) } } -float fsnap(float val,float fsize) -{ - return rint(val / fsize) * fsize; -} - -vector vsnap(vector point,float fsize) -{ - vector vret; - - vret.x = rint(point.x / fsize) * fsize; - vret.y = rint(point.y / fsize) * fsize; - vret.z = ceil(point.z / fsize) * fsize; - - return vret; -} - float walknode_stepsize; vector walknode_stepup; vector walknode_maxdrop; diff --git a/qcsrc/server/pathlib/utility.qc b/qcsrc/server/pathlib/utility.qc index 4851dbcc0..ce12c1c63 100644 --- a/qcsrc/server/pathlib/utility.qc +++ b/qcsrc/server/pathlib/utility.qc @@ -2,22 +2,6 @@ #include "pathlib.qh" -float fsnap(float val,float fsize) -{ - return rint(val / fsize) * fsize; -} - -vector vsnap(vector point,float fsize) -{ - vector vret; - - vret.x = rint(point.x / fsize) * fsize; - vret.y = rint(point.y / fsize) * fsize; - vret.z = ceil(point.z / fsize) * fsize; - - return vret; -} - float location_isok(vector point, float water_isok, float air_isok) { float pc,pc2;