]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/util/numeric.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / util / numeric.h
index 450a98e40b0335368a0900e95be60e2058b0d61c..b96c94faa70cad3a14cc89134ab09d7181c03623 100644 (file)
@@ -24,10 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "../irr_v2d.h"
 #include "../irr_v3d.h"
 #include "../irr_aabb3d.h"
-#include <irrList.h>
+#include <list>
 
 // Calculate the borders of a "d-radius" cube
-void getFacePositions(core::list<v3s16> &list, u16 d);
+void getFacePositions(std::list<v3s16> &list, u16 d);
 
 class IndentationRaiser
 {
@@ -139,6 +139,22 @@ inline v3s16 arealim(v3s16 p, s16 d)
        return p;
 }
 
+// The naive swap performs better than the xor version
+#define SWAP(t, x, y) do { \
+       t temp = x;            \
+       x = y;                 \
+       y = temp;              \
+} while (0)
+
+inline void sortBoxVerticies(v3s16 &p1, v3s16 &p2) {
+       if (p1.X > p2.X)
+               SWAP(s16, p1.X, p2.X);
+       if (p1.Y > p2.Y)
+               SWAP(s16, p1.Y, p2.Y);
+       if (p1.Z > p2.Z)
+               SWAP(s16, p1.Z, p2.Z);
+}
+
 
 /*
        See test.cpp for example cases.
@@ -332,5 +348,12 @@ inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxi
        }
 }
 
+inline float cycle_shift(float value, float by = 0, float max = 1)
+{
+    if (value + by < 0) return max + by + value;
+    if (value + by > max) return value + by - max;
+    return value + by;
+}
+
 #endif