]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/test.cpp
Update Lua API documentation to include minetest.get_modnames()
[dragonfireclient.git] / src / test.cpp
index 5b969017fb78cc8c1f24ecafb4f0c7bc9052ca8e..9b1346274a4c4613c4af401b50c94a7360ddb22a 100644 (file)
@@ -18,16 +18,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "test.h"
-#include "common_irrlicht.h"
+#include "irrlichttypes_extrabloated.h"
 #include "debug.h"
 #include "map.h"
 #include "player.h"
 #include "main.h"
 #include "socket.h"
 #include "connection.h"
-#include "utility.h"
 #include "serialization.h"
 #include "voxel.h"
+#include "collision.h"
 #include <sstream>
 #include "porting.h"
 #include "content_mapnode.h"
@@ -35,9 +35,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "mapsector.h"
 #include "settings.h"
 #include "log.h"
-#include "utility_string.h"
+#include "util/string.h"
 #include "voxelalgorithms.h"
 #include "inventory.h"
+#include "util/numeric.h"
+#include "util/serialize.h"
 
 /*
        Asserts that the exception occurs
@@ -80,7 +82,7 @@ void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *n
        f = ContentFeatures();
        f.name = itemdef.name;
        for(int i = 0; i < 6; i++)
-               f.tname_tiles[i] = "default_stone.png";
+               f.tiledef[i].name = "default_stone.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        ndef->set(i, f);
@@ -100,10 +102,10 @@ void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *n
                "{default_dirt.png&default_grass_side.png";
        f = ContentFeatures();
        f.name = itemdef.name;
-       f.tname_tiles[0] = "default_grass.png";
-       f.tname_tiles[1] = "default_dirt.png";
+       f.tiledef[0].name = "default_grass.png";
+       f.tiledef[1].name = "default_dirt.png";
        for(int i = 2; i < 6; i++)
-               f.tname_tiles[i] = "default_dirt.png^default_grass_side.png";
+               f.tiledef[i].name = "default_dirt.png^default_grass_side.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        ndef->set(i, f);
@@ -1074,6 +1076,153 @@ struct TestMapSector
 };
 #endif
 
+struct TestCollision
+{
+       void Run()
+       {
+               /*
+                       axisAlignedCollision
+               */
+
+               for(s16 bx = -3; bx <= 3; bx++)
+               for(s16 by = -3; by <= 3; by++)
+               for(s16 bz = -3; bz <= 3; bz++)
+               {
+                       // X-
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
+                               v3f v(1, 0, 0);
+                               f32 dtime = 0;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 1.000) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
+                               v3f v(-1, 0, 0);
+                               f32 dtime = 0;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == -1);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx-2, by+1.5, bz, bx-1, by+2.5, bz-1);
+                               v3f v(1, 0, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == -1);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
+                               v3f v(0.5, 0.1, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 3.000) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
+                               v3f v(0.5, 0.1, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 3.000) < 0.001);
+                       }
+
+                       // X+
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
+                               v3f v(-1, 0, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 1.000) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
+                               v3f v(1, 0, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == -1);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx+2, by, bz+1.5, bx+3, by+1, bz+3.5);
+                               v3f v(-1, 0, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == -1);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
+                               v3f v(-0.5, 0.2, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 1);  // Y, not X!
+                               assert(fabs(dtime - 2.500) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
+                               aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
+                               v3f v(-0.5, 0.3, 0);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 2.000) < 0.001);
+                       }
+
+                       // TODO: Y-, Y+, Z-, Z+
+
+                       // misc
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx+2.3, by+2.29, bz+2.29, bx+4.2, by+4.2, bz+4.2);
+                               v3f v(-1./3, -1./3, -1./3);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 0.9) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx+2.29, by+2.3, bz+2.29, bx+4.2, by+4.2, bz+4.2);
+                               v3f v(-1./3, -1./3, -1./3);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 1);
+                               assert(fabs(dtime - 0.9) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx+2.29, by+2.29, bz+2.3, bx+4.2, by+4.2, bz+4.2);
+                               v3f v(-1./3, -1./3, -1./3);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 2);
+                               assert(fabs(dtime - 0.9) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.3, by-2.29, bz-2.29);
+                               v3f v(1./7, 1./7, 1./7);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 0);
+                               assert(fabs(dtime - 16.1) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.3, bz-2.29);
+                               v3f v(1./7, 1./7, 1./7);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 1);
+                               assert(fabs(dtime - 16.1) < 0.001);
+                       }
+                       {
+                               aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
+                               aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.29, bz-2.3);
+                               v3f v(1./7, 1./7, 1./7);
+                               f32 dtime;
+                               assert(axisAlignedCollision(s, m, v, 0, dtime) == 2);
+                               assert(fabs(dtime - 16.1) < 0.001);
+                       }
+               }
+       }
+};
+
 struct TestSocket
 {
        void Run()
@@ -1543,6 +1692,7 @@ void run_tests()
        TESTPARAMS(TestInventory, idef);
        //TEST(TestMapBlock);
        //TEST(TestMapSector);
+       TEST(TestCollision);
        if(INTERNET_SIMULATOR == false){
                TEST(TestSocket);
                dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;