]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Extract a few more functions
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 27 Aug 2015 03:01:10 +0000 (13:01 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 27 Aug 2015 03:01:10 +0000 (13:01 +1000)
qcsrc/common/triggers/subs.qc
qcsrc/lib/Defer.qh [new file with mode: 0644]
qcsrc/lib/Math.qh [new file with mode: 0644]
qcsrc/lib/Mean.qh [deleted file]
qcsrc/lib/_all.inc
qcsrc/server/antilag.qc
qcsrc/server/g_subs.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/pathlib.qc
qcsrc/server/pathlib/utility.qc

index f21455dc5f381f88f7ec245ca08280a5f43d9fe1..fa7c1c5e451b28f67a41eab1068c8d8c49cfa35f 100644 (file)
@@ -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 (file)
index 0000000..fd2619d
--- /dev/null
@@ -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 (file)
index 0000000..a8a5290
--- /dev/null
@@ -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 (file)
index 19d9f38..0000000
+++ /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
index ee665bcf94823997b03a60d6a3555516eac2ff55..bf79e4e1004aa02ea881f586bd80f01f93244329 100644 (file)
@@ -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"
index c51d3cf5ba536d01e5237da5fb2fe069adc5891a..f152c8216d93f8575ffe121dd04c3ad5701e19f5 100644 (file)
@@ -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);
index eacba6452869ce4bb9c95836f1de2b28ccf356d7..01bf62f82ba37591ecfa10ba47ddc0fe74a7eccb 100644 (file)
@@ -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;
index 71fb2de5e6a66b7e536698a29b0be77d2a26d656..0dabbf0fa38df393b90c894315ffc61028144a3f 100644 (file)
@@ -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)
index bfd9c0b35fca09633e67710f2f7b5acf26d49933..40e23387d28175249f715e7d7b96d3ba6375f7f6 100644 (file)
@@ -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;
index 4851dbcc0c52db8a957bf80d2ab85f2762fe80f8..ce12c1c631fed9bf994d4ace53a176cf776d540a 100644 (file)
@@ -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;