Skip to content

Commit 3397f0f

Browse files
committed
FTI - Optimize SceneTree traversal
1 parent 8f78e75 commit 3397f0f

File tree

8 files changed

+708
-44
lines changed

8 files changed

+708
-44
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,11 @@
24792479
[b]Dummy[/b] is a 3D physics server that does nothing and returns only dummy values, effectively disabling all 3D physics functionality.
24802480
Third-party extensions and modules can add other physics engines to select with this setting.
24812481
</member>
2482+
<member name="physics/3d/physics_interpolation/scene_traversal" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
2483+
Allows reverting to [code]Legacy[/code] method for scene tree traversal, which is slower.
2484+
Also offers a [code]Debug[/code] method which provides logging information.
2485+
[b]Note:[/b] This setting is intended for debugging only, you should use the [code]DEFAULT[/code] method in most cases.
2486+
</member>
24822487
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
24832488
If [code]true[/code], the 3D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 3D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process.
24842489
[b]Note:[/b] When [member physics/3d/physics_engine] is set to [code]Jolt Physics[/code], enabling this setting will prevent the 3D physics server from being able to provide any context when reporting errors and warnings, and will instead always refer to nodes as [code]&lt;unknown&gt;[/code].

scene/3d/node_3d.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ void Node3D::_notification(int p_what) {
270270
// unless they need to perform specific tasks (like changing process modes).
271271
fti_pump_xform();
272272
fti_pump_property();
273+
274+
// Detect whether we are using an identity transform.
275+
// This is an optimization for faster tree transform concatenation.
276+
data.fti_is_identity_xform = data.local_transform == Transform3D();
273277
} break;
274278
case NOTIFICATION_SUSPENDED:
275279
case NOTIFICATION_PAUSED: {
@@ -1448,6 +1452,8 @@ Node3D::Node3D() :
14481452
data.fti_on_tick_property_list = false;
14491453
data.fti_global_xform_interp_set = false;
14501454
data.fti_frame_xform_force_update = false;
1455+
data.fti_is_identity_xform = false;
1456+
data.fti_processed = false;
14511457

14521458
#ifdef TOOLS_ENABLED
14531459
data.gizmos_disabled = false;

scene/3d/node_3d.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Node3D : public Node {
5151
GDCLASS(Node3D, Node);
5252

5353
friend class SceneTreeFTI;
54+
friend class SceneTreeFTITests;
5455

5556
public:
5657
// Edit mode for the rotation.
@@ -143,6 +144,8 @@ class Node3D : public Node {
143144
bool fti_on_tick_property_list : 1;
144145
bool fti_global_xform_interp_set : 1;
145146
bool fti_frame_xform_force_update : 1;
147+
bool fti_is_identity_xform : 1;
148+
bool fti_processed : 1;
146149

147150
RID visibility_parent;
148151

scene/main/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Node : public Object {
174174
mutable int internal_children_back_count_cache = 0;
175175
mutable int external_children_count_cache = 0;
176176
mutable int index = -1; // relative to front, normal or back.
177-
int depth = -1;
177+
int32_t depth = -1;
178178
int blocked = 0; // Safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed.
179179
StringName name;
180180
SceneTree *tree = nullptr;
@@ -377,6 +377,7 @@ class Node : public Object {
377377

378378
void _set_use_identity_transform(bool p_enable) { data.use_identity_transform = p_enable; }
379379
bool _is_using_identity_transform() const { return data.use_identity_transform; }
380+
int32_t _get_scene_tree_depth() const { return data.depth; }
380381

381382
//call from SceneTree
382383
void _call_input(const Ref<InputEvent> &p_event);

0 commit comments

Comments
 (0)