Skip to content

Commit e10003c

Browse files
committed
FTI - Reduce VisualInstance3D xform notifications
1 parent b89c47b commit e10003c

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
@@ -1157,9 +1157,21 @@ Vector3 Node3D::to_global(Vector3 p_local) const {
11571157
return get_global_transform().xform(p_local);
11581158
}
11591159

1160+
void Node3D::_physics_interpolated_changed() {
1161+
ERR_THREAD_GUARD;
1162+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
1163+
}
1164+
1165+
void Node3D::_set_notify_transform_when_fti_off(bool p_enable) {
1166+
ERR_THREAD_GUARD;
1167+
data.notify_transform_when_fti_off = p_enable;
1168+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
1169+
}
1170+
11601171
void Node3D::set_notify_transform(bool p_enabled) {
11611172
ERR_THREAD_GUARD;
1162-
data.notify_transform = p_enabled;
1173+
data.notify_transform_requested = p_enabled;
1174+
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
11631175
}
11641176

11651177
bool Node3D::is_transform_notification_enabled() const {
@@ -1441,6 +1453,8 @@ Node3D::Node3D() :
14411453
data.ignore_notification = false;
14421454
data.notify_local_transform = false;
14431455
data.notify_transform = false;
1456+
data.notify_transform_requested = false;
1457+
data.notify_transform_when_fti_off = false;
14441458

14451459
data.visible = true;
14461460
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)