1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Optimize raycast performance (#15233)

by skipping nodes not on the ray with selection boxes smaller than 1x1x1 early on
This commit is contained in:
sfence 2024-12-14 17:01:06 +01:00 committed by GitHub
parent ba63c1505a
commit f7a695c212
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 0 deletions

View file

@ -163,6 +163,8 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result_p)
break; // About to go out of bounds
}
const v3s16 pos_on_ray = state->m_iterator.m_current_node_pos;
// For each untested node
for (s16 z = new_nodes.MinEdge.Z; z <= new_nodes.MaxEdge.Z; z++)
for (s16 y = new_nodes.MinEdge.Y; y <= new_nodes.MaxEdge.Y; y++)
@ -175,6 +177,10 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result_p)
if (!is_valid_position)
continue;
// Optimization: Skip non-oversized selection boxes for other positions.
if ((pos_on_ray != np) && !nodedef->get(n).has_big_selection_box)
continue;
PointabilityType pointable = isPointableNode(n, nodedef,
state->m_liquids_pointable,
state->m_pointabilities);