Skip to content

Commit d1a3043

Browse files
committed
SceneTreeFTI faster access to Node children
1 parent 8f78e75 commit d1a3043

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

scene/main/node.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,13 @@ class Node : public Object {
501501
Node *get_parent() const;
502502
Node *find_parent(const String &p_pattern) const;
503503

504+
// Fast unsafe access to children, for bottleneck code.
505+
// Use get_child_count() / get_child() for safe access.
506+
// These are raw and include internal children.
507+
// Callers *must* call `update_cached_children()` if there is a possibility cached children are not up to date.
508+
void update_cached_children() const { _update_children_cache(); }
509+
Span<Node *> get_cached_children() const { return data.children_cache.span(); }
510+
504511
Window *get_window() const;
505512
Window *get_last_exclusive_window() const;
506513

scene/main/scene_tree_fti.cpp

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

321+
p_node->update_cached_children();
322+
Span<Node *> children = p_node->get_cached_children();
323+
uint32_t num_children = children.size();
324+
321325
// Not a Node3D.
322326
// Could be e.g. a viewport or something
323327
// so we should still recurse to children.
324328
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);
329+
for (uint32_t n = 0; n < num_children; n++) {
330+
_update_dirty_nodes(children.ptr()[n], p_current_frame, p_interpolation_fraction, p_active, nullptr, p_depth + 1);
327331
}
328332
return;
329333
}
@@ -424,8 +428,8 @@ void SceneTreeFTI::_update_dirty_nodes(Node *p_node, uint32_t p_current_frame, f
424428
s->_clear_dirty_bits(Node3D::DIRTY_GLOBAL_INTERPOLATED_TRANSFORM);
425429

426430
// 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);
431+
for (uint32_t n = 0; n < num_children; n++) {
432+
_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);
429433
}
430434
}
431435

0 commit comments

Comments
 (0)