Skip to content

Commit a26b432

Browse files
committed
FTI - Optimize SceneTree traversal
1 parent 009e0c5 commit a26b432

File tree

6 files changed

+390
-22
lines changed

6 files changed

+390
-22
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,11 @@
14181418
Sets which physics engine to use for 3D physics.
14191419
"DEFAULT" is currently the [url=https://bulletphysics.org]Bullet[/url] physics engine. The "GodotPhysics" engine is still supported as an alternative.
14201420
</member>
1421+
<member name="physics/3d/physics_interpolation/scene_traversal" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
1422+
Allows reverting to [code]Legacy[/code] method for scene tree traversal, which is slower.
1423+
Also offers a [code]Debug[/code] method which provides logging information.
1424+
[b]Note:[/b] This setting is intended for debugging only, you should use the [code]DEFAULT[/code] method in most cases.
1425+
</member>
14211426
<member name="physics/3d/smooth_trimesh_collision" type="bool" setter="" getter="" default="false">
14221427
If [code]true[/code], smooths out collision with trimesh shapes ([ConcavePolygonShape]) by telling the Bullet physics engine to generate internal edge information for every trimesh shape created.
14231428
[b]Note:[/b] Only effective if [member physics/3d/physics_engine] is set to [code]DEFAULT[/code] or [code]Bullet[/code], [i]not[/i] [code]GodotPhysics[/code].

scene/3d/spatial.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ void Spatial::_notification(int p_what) {
285285
// unless they need to perform specific tasks (like changing process modes).
286286
fti_pump_xform();
287287
fti_pump_property();
288+
289+
// Detect whether we are using an identity transform.
290+
// This is an optimization for faster tree transform concatenation.
291+
data.fti_is_identity = data.local_transform == Transform();
288292
} break;
289293

290294
case NOTIFICATION_PAUSED: {
@@ -1127,6 +1131,7 @@ Spatial::Spatial() :
11271131
data.fti_on_tick_property_list = false;
11281132
data.fti_global_xform_interp_set = false;
11291133
data.fti_frame_xform_force_update = false;
1134+
data.fti_is_identity = false;
11301135

11311136
data.merging_mode = MERGING_MODE_INHERIT;
11321137

scene/3d/spatial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ class Spatial : public Node {
129129
bool fti_on_tick_property_list : 1;
130130
bool fti_global_xform_interp_set : 1;
131131
bool fti_frame_xform_force_update : 1;
132+
bool fti_is_identity : 1;
132133

133134
bool merging_allowed : 1;
134135

136+
uint32_t fti_last_update_half_frame = UINT32_MAX;
137+
135138
int children_lock;
136139
Spatial *parent;
137140
List<Spatial *> children;

scene/main/node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class Node : public Object {
111111
HashMap<StringName, Node *> owned_unique_nodes;
112112
bool unique_name_in_owner = false;
113113

114+
int32_t depth;
114115
int pos;
115-
int depth;
116116
int blocked; // safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed.
117117
StringName name;
118118
SceneTree *tree;
@@ -266,6 +266,7 @@ class Node : public Object {
266266
bool _is_physics_interpolation_reset_requested() const { return data.physics_interpolation_reset_requested; }
267267
void _set_use_identity_transform(bool p_enable);
268268
bool _is_using_identity_transform() const { return data.use_identity_transform; }
269+
int32_t _get_scene_tree_depth() const { return data.depth; }
269270

270271
public:
271272
enum {

0 commit comments

Comments
 (0)