Skip to content

Commit c7764ef

Browse files
committed
FTI - Optimize SceneTree traversal
1 parent 7a0ab9d commit c7764ef

File tree

8 files changed

+709
-44
lines changed

8 files changed

+709
-44
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,6 +2482,12 @@
24822482
[b]Dummy[/b] is a 3D physics server that does nothing and returns only dummy values, effectively disabling all 3D physics functionality.
24832483
Third-party extensions and modules can add other physics engines to select with this setting.
24842484
</member>
2485+
<member name="physics/3d/physics_interpolation/scene_traversal" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
2486+
The approach used for 3D scene traversal when physics interpolation is enabled.
2487+
- [code]DEFAULT[/code]: The default optimized method.
2488+
- [code]Legacy[/code]: The previous reference method used for scene tree traversal, which is slower.
2489+
- [code]Debug[/code]: Swaps between [code]DEFAULT[/code] and [code]Legacy[/code] methods on alternating frames, and provides logging information (which in turn makes it slower). Intended for debugging only; you should use the [code]DEFAULT[/code] method in most cases.
2490+
</member>
24852491
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
24862492
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.
24872493
[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
@@ -176,7 +176,7 @@ class Node : public Object {
176176
mutable int internal_children_back_count_cache = 0;
177177
mutable int external_children_count_cache = 0;
178178
mutable int index = -1; // relative to front, normal or back.
179-
int depth = -1;
179+
int32_t depth = -1;
180180
int blocked = 0; // Safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed.
181181
StringName name;
182182
SceneTree *tree = nullptr;
@@ -379,6 +379,7 @@ class Node : public Object {
379379

380380
void _set_use_identity_transform(bool p_enable) { data.use_identity_transform = p_enable; }
381381
bool _is_using_identity_transform() const { return data.use_identity_transform; }
382+
int32_t _get_scene_tree_depth() const { return data.depth; }
382383

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

0 commit comments

Comments
 (0)