summaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorDániel Juhász <juhdanad@gmail.com>2017-01-04 19:18:40 +0100
committerest31 <est31@users.noreply.github.com>2017-01-04 19:18:40 +0100
commit3f8261830e0503cd59d8713d5c9aab12fc1491db (patch)
treeb49d898815a6c2e692cfe2fc0978cfedd49cd34f /src/mapnode.cpp
parent8aadc62856cc3789ed345ddf3870e311af60afe9 (diff)
downloadminetest-3f8261830e0503cd59d8713d5c9aab12fc1491db.tar.gz
minetest-3f8261830e0503cd59d8713d5c9aab12fc1491db.tar.bz2
minetest-3f8261830e0503cd59d8713d5c9aab12fc1491db.zip
Improve getPointedThing() (#4346)
* Improved getPointedThing() The new algorithm checks every node exactly once. Now the point and normal vector of the collision is also returned in the PointedThing (currently they are not used outside of the function). Now the CNodeDefManager keeps the union of all possible nodeboxes, so the raycast won't miss any nodes. Also if there are only small nodeboxes, getPointedThing() is exceptionally fast. Also adds unit test for VoxelLineIterator. * Cleanup, code move This commit moves getPointedThing() and Client::getSelectedActiveObject() to ClientEnvironment. The map nodes now can decide which neighbors they are connecting to (MapNode::getNeighbors()).
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 5efebf3d8..f1a7f3e61 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "porting.h"
#include "nodedef.h"
+#include "map.h"
#include "content_mapnode.h" // For mapnode_translate_*_internal
#include "serialization.h" // For ser_ver_supported
#include "util/serialize.h"
@@ -453,6 +454,51 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
}
}
+static inline void getNeighborConnectingFace(
+ v3s16 p, INodeDefManager *nodedef,
+ Map *map, MapNode n, u8 bitmask, u8 *neighbors)
+{
+ MapNode n2 = map->getNodeNoEx(p);
+ if (nodedef->nodeboxConnects(n, n2, bitmask))
+ *neighbors |= bitmask;
+}
+
+u8 MapNode::getNeighbors(v3s16 p, Map *map)
+{
+ INodeDefManager *nodedef=map->getNodeDefManager();
+ u8 neighbors = 0;
+ const ContentFeatures &f = nodedef->get(*this);
+ // locate possible neighboring nodes to connect to
+ if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) {
+ v3s16 p2 = p;
+
+ p2.Y++;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 1, &neighbors);
+
+ p2 = p;
+ p2.Y--;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 2, &neighbors);
+
+ p2 = p;
+ p2.Z--;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 4, &neighbors);
+
+ p2 = p;
+ p2.X--;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 8, &neighbors);
+
+ p2 = p;
+ p2.Z++;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 16, &neighbors);
+
+ p2 = p;
+ p2.X++;
+ getNeighborConnectingFace(p2, nodedef, map, *this, 32, &neighbors);
+ }
+
+ return neighbors;
+}
+
void MapNode::getNodeBoxes(INodeDefManager *nodemgr, std::vector<aabb3f> *boxes, u8 neighbors)
{
const ContentFeatures &f = nodemgr->get(*this);