mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-17 17:08:39 +00:00
Tool specific pointing and blocking pointable type (#13992)
This commit is contained in:
parent
fb461d21a5
commit
5958714309
39 changed files with 676 additions and 67 deletions
|
@ -102,24 +102,33 @@ bool Environment::line_of_sight(v3f pos1, v3f pos2, v3s16 *p)
|
|||
}
|
||||
|
||||
/*
|
||||
Check if a node is pointable
|
||||
Check how a node can be pointed at
|
||||
*/
|
||||
inline static bool isPointableNode(const MapNode &n,
|
||||
const NodeDefManager *nodedef , bool liquids_pointable)
|
||||
inline static PointabilityType isPointableNode(const MapNode &n,
|
||||
const NodeDefManager *nodedef, bool liquids_pointable,
|
||||
const std::optional<Pointabilities> &pointabilities)
|
||||
{
|
||||
const ContentFeatures &features = nodedef->get(n);
|
||||
return features.pointable ||
|
||||
(liquids_pointable && features.isLiquid());
|
||||
if (pointabilities) {
|
||||
std::optional<PointabilityType> match =
|
||||
pointabilities->matchNode(features.name, features.groups);
|
||||
if (match)
|
||||
return match.value();
|
||||
}
|
||||
|
||||
if (features.isLiquid() && liquids_pointable)
|
||||
return PointabilityType::POINTABLE;
|
||||
return features.pointable;
|
||||
}
|
||||
|
||||
void Environment::continueRaycast(RaycastState *state, PointedThing *result)
|
||||
void Environment::continueRaycast(RaycastState *state, PointedThing *result_p)
|
||||
{
|
||||
const NodeDefManager *nodedef = getMap().getNodeDefManager();
|
||||
if (state->m_initialization_needed) {
|
||||
// Add objects
|
||||
if (state->m_objects_pointable) {
|
||||
std::vector<PointedThing> found;
|
||||
getSelectedActiveObjects(state->m_shootline, found);
|
||||
getSelectedActiveObjects(state->m_shootline, found, state->m_pointabilities);
|
||||
for (const PointedThing &pointed : found) {
|
||||
state->m_found.push(pointed);
|
||||
}
|
||||
|
@ -184,10 +193,15 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result)
|
|||
bool is_valid_position;
|
||||
|
||||
n = map.getNode(np, &is_valid_position);
|
||||
if (!(is_valid_position && isPointableNode(n, nodedef,
|
||||
state->m_liquids_pointable))) {
|
||||
if (!is_valid_position)
|
||||
continue;
|
||||
|
||||
PointabilityType pointable = isPointableNode(n, nodedef,
|
||||
state->m_liquids_pointable,
|
||||
state->m_pointabilities);
|
||||
// If it can be pointed through skip
|
||||
if (pointable == PointabilityType::POINTABLE_NOT)
|
||||
continue;
|
||||
}
|
||||
|
||||
PointedThing result;
|
||||
|
||||
|
@ -234,6 +248,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result)
|
|||
if (!is_colliding) {
|
||||
continue;
|
||||
}
|
||||
result.pointability = pointable;
|
||||
result.type = POINTEDTHING_NODE;
|
||||
result.node_undersurface = np;
|
||||
result.distanceSq = min_distance_sq;
|
||||
|
@ -275,12 +290,16 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result)
|
|||
state->m_previous_node = state->m_iterator.m_current_node_pos;
|
||||
state->m_iterator.next();
|
||||
}
|
||||
// Return empty PointedThing if nothing left on the ray
|
||||
|
||||
// Return empty PointedThing if nothing left on the ray or it is blocking pointable
|
||||
if (state->m_found.empty()) {
|
||||
result->type = POINTEDTHING_NOTHING;
|
||||
result_p->type = POINTEDTHING_NOTHING;
|
||||
} else {
|
||||
*result = state->m_found.top();
|
||||
*result_p = state->m_found.top();
|
||||
state->m_found.pop();
|
||||
if (result_p->pointability == PointabilityType::POINTABLE_BLOCKING) {
|
||||
result_p->type = POINTEDTHING_NOTHING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue