]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/collision.cpp
Mapgen V5: Fix use of uninitialized value in ctor
[dragonfireclient.git] / src / collision.cpp
index df3878f4c6c26dcdb638bbcb6cf4a179021d9727..9e0c85531cf4ced2cf987e17f4bcb9eca17e8d0a 100644 (file)
@@ -32,7 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "profiler.h"
 
 // float error is 10 - 9.96875 = 0.03125
-#define COLL_ZERO 0.032
+//#define COLL_ZERO 0.032 // broken unit tests
+#define COLL_ZERO 0
 
 // Helper function:
 // Checks for collision of a moving aabbox with a static aabbox
@@ -195,7 +196,9 @@ bool wouldCollideWithCeiling(
 collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                f32 pos_max_d, const aabb3f &box_0,
                f32 stepheight, f32 dtime,
-               v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self)
+               v3f &pos_f, v3f &speed_f,
+               v3f &accel_f,ActiveObject* self,
+               bool collideWithObjects)
 {
        Map *map = &env->getMap();
        //TimeTaker tt("collisionMoveSimple");
@@ -248,15 +251,19 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
        for(s16 z = min_z; z <= max_z; z++)
        {
                v3s16 p(x,y,z);
-               try{
+
+               bool is_position_valid;
+               MapNode n = map->getNodeNoEx(p, &is_position_valid);
+
+               if (is_position_valid) {
                        // Object collides into walkable nodes
-                       MapNode n = map->getNode(p);
+
                        const ContentFeatures &f = gamedef->getNodeDefManager()->get(n);
                        if(f.walkable == false)
                                continue;
                        int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
 
-                       std::vector<aabb3f> nodeboxes = n.getNodeBoxes(gamedef->ndef());
+                       std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(gamedef->ndef());
                        for(std::vector<aabb3f>::iterator
                                        i = nodeboxes.begin();
                                        i != nodeboxes.end(); i++)
@@ -272,8 +279,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                                is_object.push_back(false);
                        }
                }
-               catch(InvalidPositionException &e)
-               {
+               else {
                        // Collide with unloaded nodes
                        aabb3f box = getNodeBox(p, BS);
                        cboxes.push_back(box);
@@ -286,6 +292,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
        }
        } // tt2
 
+       if(collideWithObjects)
        {
                ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
                //TimeTaker tt3("collisionMoveSimple collect object boxes");
@@ -333,7 +340,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                        if (object != NULL)
                        {
                                aabb3f object_collisionbox;
-                               if (object->getCollisionBox(&object_collisionbox))
+                               if (object->getCollisionBox(&object_collisionbox) &&
+                                               object->collideWithObjects())
                                {
                                        cboxes.push_back(object_collisionbox);
                                        is_unloaded.push_back(false);