Skip to content

Commit cbd6c8d

Browse files
committed
SceneTreeFTI faster access to Node children
1 parent 4a44078 commit cbd6c8d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

scene/main/node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint32_t)
4747
class Node : public Object {
4848
GDCLASS(Node, Object);
4949

50+
friend class SceneTreeFTI;
51+
5052
protected:
5153
// During group processing, these are thread-safe.
5254
// Outside group processing, these avoid the cost of sync by working as plain primitive types.

scene/main/scene_tree_fti.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,19 @@ void SceneTreeFTI::_update_dirty_nodes(Node *p_node, uint32_t p_current_frame, f
318318
return;
319319
}
320320

321+
// Temporary direct access to children cache for speed.
322+
// Maybe replaced later by a more generic fast access method
323+
// for children.
324+
p_node->_update_children_cache();
325+
Span<Node *> children = p_node->data.children_cache.span();
326+
uint32_t num_children = children.size();
327+
321328
// Not a Node3D.
322329
// Could be e.g. a viewport or something
323330
// so we should still recurse to children.
324331
if (!s) {
325-
for (int n = 0; n < p_node->get_child_count(); n++) {
326-
_update_dirty_nodes(p_node->get_child(n), p_current_frame, p_interpolation_fraction, p_active, nullptr, p_depth + 1);
332+
for (uint32_t n = 0; n < num_children; n++) {
333+
_update_dirty_nodes(children.ptr()[n], p_current_frame, p_interpolation_fraction, p_active, nullptr, p_depth + 1);
327334
}
328335
return;
329336
}
@@ -424,8 +431,8 @@ void SceneTreeFTI::_update_dirty_nodes(Node *p_node, uint32_t p_current_frame, f
424431
s->_clear_dirty_bits(Node3D::DIRTY_GLOBAL_INTERPOLATED_TRANSFORM);
425432

426433
// Recurse to children.
427-
for (int n = 0; n < p_node->get_child_count(); n++) {
428-
_update_dirty_nodes(p_node->get_child(n), p_current_frame, p_interpolation_fraction, p_active, s->data.fti_global_xform_interp_set ? &s->data.global_transform_interpolated : &s->data.global_transform, p_depth + 1);
434+
for (uint32_t n = 0; n < num_children; n++) {
435+
_update_dirty_nodes(children.ptr()[n], p_current_frame, p_interpolation_fraction, p_active, s->data.fti_global_xform_interp_set ? &s->data.global_transform_interpolated : &s->data.global_transform, p_depth + 1);
429436
}
430437
}
431438

0 commit comments

Comments
 (0)