Skip to content

Commit 0e9a59b

Browse files
committed
Merge pull request godotengine#105901 from lawnjelly/fti_reduce_xform_notifications4
FTI - Reduce `VisualInstance3D` xform notifications
2 parents 2270224 + e10003c commit 0e9a59b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

scene/3d/camera_3d.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ void Camera3D::_update_camera() {
164164

165165
void Camera3D::_physics_interpolated_changed() {
166166
_update_process_mode();
167+
Node3D::_physics_interpolated_changed();
167168
}
168169

169170
void Camera3D::set_desired_process_modes(bool p_process_internal, bool p_physics_process_internal) {

scene/3d/node_3d.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,21 @@ Vector3 Node3D::to_global(Vector3 p_local) const {
12411241
return get_global_transform().xform(p_local);
12421242
}
12431243

1244+
void Node3D::_physics_interpolated_changed() {
1245+
ERR_THREAD_GUARD;
1246+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
1247+
}
1248+
1249+
void Node3D::_set_notify_transform_when_fti_off(bool p_enable) {
1250+
ERR_THREAD_GUARD;
1251+
data.notify_transform_when_fti_off = p_enable;
1252+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
1253+
}
1254+
12441255
void Node3D::set_notify_transform(bool p_enabled) {
12451256
ERR_THREAD_GUARD;
1246-
data.notify_transform = p_enabled;
1257+
data.notify_transform_requested = p_enabled;
1258+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
12471259
}
12481260

12491261
bool Node3D::is_transform_notification_enabled() const {
@@ -1525,6 +1537,8 @@ Node3D::Node3D() :
15251537
data.ignore_notification = false;
15261538
data.notify_local_transform = false;
15271539
data.notify_transform = false;
1540+
data.notify_transform_requested = false;
1541+
data.notify_transform_when_fti_off = false;
15281542

15291543
data.visible = true;
15301544
data.disable_scale = false;

scene/3d/node_3d.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class Node3D : public Node {
134134
bool notify_local_transform : 1;
135135
bool notify_transform : 1;
136136

137+
bool notify_transform_requested : 1;
138+
bool notify_transform_when_fti_off : 1;
139+
137140
bool visible : 1;
138141
bool disable_scale : 1;
139142

@@ -199,6 +202,9 @@ class Node3D : public Node {
199202
// (e.g. changing Camera zoom even if position hasn't changed).
200203
void fti_notify_node_changed(bool p_transform_changed = true);
201204

205+
void _set_notify_transform_when_fti_off(bool p_enable);
206+
virtual void _physics_interpolated_changed() override;
207+
202208
// Opportunity after FTI to update the servers
203209
// with global_transform_interpolated,
204210
// and any custom interpolated data in derived classes.

scene/3d/visual_instance_3d.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ void VisualInstance3D::_notification(int p_what) {
8888
} break;
8989

9090
case NOTIFICATION_TRANSFORM_CHANGED: {
91-
// ToDo : Can we turn off notify transform for physics interpolated cases?
91+
// NOTIFICATION normally turned off for physics interpolated cases (via
92+
// `notify_transform_when_fti_off`), however derived classes can still turn this back on,
93+
// so always wrap with is_physics_interpolation_enabled().
9294
if (_is_vi_visible() && !(is_inside_tree() && get_tree()->is_physics_interpolation_enabled()) && !_is_using_identity_transform()) {
9395
// Physics interpolation global off, always send.
9496
RenderingServer::get_singleton()->instance_set_transform(instance, get_global_transform());
@@ -204,7 +206,7 @@ RID VisualInstance3D::get_base() const {
204206
VisualInstance3D::VisualInstance3D() {
205207
instance = RenderingServer::get_singleton()->instance_create();
206208
RenderingServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id());
207-
set_notify_transform(true);
209+
_set_notify_transform_when_fti_off(true);
208210
}
209211

210212
VisualInstance3D::~VisualInstance3D() {

0 commit comments

Comments
 (0)