Skip to content

Commit

Permalink
Meta-set nodedef: Part 4
Browse files Browse the repository at this point in the history
Mainly a refactor of parts of minetest#1118
  • Loading branch information
Thomas--S committed Jun 7, 2017
1 parent 5072d47 commit 75955f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/clientenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,10 @@ ClientActiveObject * ClientEnvironment::getSelectedActiveObject(
/*
Check if a node is pointable
*/
static inline bool isPointableNode(const MapNode &n,
static inline bool isPointableNode(const ContentFeatures &f,
INodeDefManager *ndef, bool liquids_pointable)
{
const ContentFeatures &features = ndef->get(n);
return features.pointable ||
(liquids_pointable && features.isLiquid());
return f.pointable || (liquids_pointable && f.isLiquid());
}

PointedThing ClientEnvironment::getPointedThing(
Expand Down Expand Up @@ -769,12 +767,14 @@ PointedThing ClientEnvironment::getPointedThing(
bool is_valid_position;

n = m_map->getNodeNoEx(np, &is_valid_position);
HybridPtr<const ContentFeatures> f_ptr = m_map->getNodeDefNoEx(np);
const ContentFeatures &f = *f_ptr;
if (!(is_valid_position &&
isPointableNode(n, nodedef, liquids_pointable))) {
isPointableNode(f, nodedef, liquids_pointable))) {
continue;
}
std::vector<aabb3f> boxes;
n.getSelectionBoxes(nodedef, &boxes,
n.getSelectionBoxes(f, &boxes,
n.getNeighbors(np, m_map));

v3f npf = intToFloat(np, BS);
Expand Down
5 changes: 3 additions & 2 deletions src/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,

any_position_valid = true;
INodeDefManager *nodedef = gamedef->getNodeDefManager();
const ContentFeatures &f = nodedef->get(n);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
if(f.walkable == false)
continue;
int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
Expand Down Expand Up @@ -316,7 +317,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
}
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
n.getCollisionBoxes(f, &nodeboxes, neighbors);
for(std::vector<aabb3f>::iterator
i = nodeboxes.begin();
i != nodeboxes.end(); ++i)
Expand Down
4 changes: 3 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3668,8 +3668,10 @@ PointedThing Game::updatePointedThing(
} else if (result.type == POINTEDTHING_NODE) {
// Update selection boxes
MapNode n = map.getNodeNoEx(result.node_undersurface);
HybridPtr<const ContentFeatures> f_ptr = map.getNodeDefNoEx(result.node_undersurface);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> boxes;
n.getSelectionBoxes(nodedef, &boxes,
n.getSelectionBoxes(f, &boxes,
n.getNeighbors(result.node_undersurface, &map));

f32 d = 0.002 * BS;
Expand Down
29 changes: 19 additions & 10 deletions src/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
node = map->getNodeNoEx(pp, &is_valid_position);
bool is_valid_position2;
MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(pp);
HybridPtr<const ContentFeatures> f_ptr2 = map->getNodeDefNoEx(pp2, &is_valid_position2);

if (!(is_valid_position && is_valid_position2)) {
is_climbing = false;
} else {
is_climbing = (nodemgr->get(node.getContent()).climbable
|| nodemgr->get(node2.getContent()).climbable) && !free_move;
const ContentFeatures &f = *f_ptr;
const ContentFeatures &f2 = *f_ptr2;
is_climbing = (f.climbable || f2.climbable) && !free_move;
}


Expand Down Expand Up @@ -445,8 +447,10 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
if (sneak_node_found) {
// Update saved top bounding box of sneak node
MapNode n = map->getNodeNoEx(m_sneak_node);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(m_sneak_node);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(nodemgr, &nodeboxes);
n.getCollisionBoxes(f, &nodeboxes);
m_sneak_node_bb_top = getTopBoundingBox(nodeboxes);

m_sneak_ladder_detected = physics_override_sneak_glitch &&
Expand Down Expand Up @@ -908,13 +912,16 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
v3s16 pp2 = floatToInt(position + v3f(0, -0.2 * BS, 0), BS);
node = map->getNodeNoEx(pp, &is_valid_position);
bool is_valid_position2;
MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(pp);
HybridPtr<const ContentFeatures> f_ptr2 = map->getNodeDefNoEx(pp2, &is_valid_position2);

if (!(is_valid_position && is_valid_position2))
if (!(is_valid_position && is_valid_position2)) {
is_climbing = false;
else
is_climbing = (nodemgr->get(node.getContent()).climbable ||
nodemgr->get(node2.getContent()).climbable) && !free_move;
} else {
const ContentFeatures &f = *f_ptr;
const ContentFeatures &f2 = *f_ptr2;
is_climbing = (f.climbable || f2.climbable) && !free_move;
}

/*
Collision uncertainty radius
Expand Down Expand Up @@ -1049,8 +1056,10 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
if (sneak_node_found) {
f32 cb_max = 0;
MapNode n = map->getNodeNoEx(m_sneak_node);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(m_sneak_node);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(nodemgr, &nodeboxes);
n.getCollisionBoxes(f, &nodeboxes);
for (std::vector<aabb3f>::iterator it = nodeboxes.begin();
it != nodeboxes.end(); ++it) {
aabb3f box = *it;
Expand Down

0 comments on commit 75955f8

Please sign in to comment.