Skip to content

Commit 65eb3a2

Browse files
committed
FTI - Optimize SceneTree traversal
1 parent 656eeda commit 65eb3a2

File tree

8 files changed

+707
-41
lines changed

8 files changed

+707
-41
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,12 @@
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+
The approach used for 3D scene traversal when physics interpolation is enabled.
1423+
- [code]DEFAULT[/code]: The default optimized method.
1424+
- [code]Legacy[/code]: The previous reference method used for scene tree traversal, which is slower.
1425+
- [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.
1426+
</member>
14211427
<member name="physics/3d/smooth_trimesh_collision" type="bool" setter="" getter="" default="false">
14221428
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.
14231429
[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: 6 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_xform = data.local_transform == Transform();
288292
} break;
289293

290294
case NOTIFICATION_PAUSED: {
@@ -1127,6 +1131,8 @@ 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_xform = false;
1135+
data.fti_processed = false;
11301136

11311137
data.merging_mode = MERGING_MODE_INHERIT;
11321138

scene/3d/spatial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Spatial : public Node {
5353
OBJ_CATEGORY("3D");
5454

5555
friend class SceneTreeFTI;
56+
friend class SceneTreeFTITests;
5657

5758
public:
5859
enum MergingMode : unsigned int {
@@ -129,6 +130,8 @@ class Spatial : public Node {
129130
bool fti_on_tick_property_list : 1;
130131
bool fti_global_xform_interp_set : 1;
131132
bool fti_frame_xform_force_update : 1;
133+
bool fti_is_identity_xform : 1;
134+
bool fti_processed : 1;
132135

133136
bool merging_allowed : 1;
134137

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)