From 30904ed3bc6ba619e32742a1b838130609ab7949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Sat, 14 Oct 2023 16:45:27 +0800 Subject: [PATCH] Fix cannot update remote after disabling `use_global_coordinates` in `RemoteTransform2D` Due to the optimization in `CanvasItem`, `global_transform` is only updated when `get_global_transform()` is called, and then notify `NOTIFICATION_TRANSFORM_CHANGED`. That is, in the case where `global_transform` is not obtained, the notification will not be sent. So we use `NOTIFICATION_LOCAL_TRANSFORM_CHANGED` in this case. Use in combination to prevent certain optimizations. Same change for `RemoteTransform3D`, to prevent the same optimization from being used in `Node3D` in the future. --- scene/2d/remote_transform_2d.cpp | 23 ++++++++++++++++++++++- scene/3d/remote_transform_3d.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index cd0d9f37505..f7de4f3376b 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -114,6 +114,7 @@ void RemoteTransform2D::_notification(int p_what) { _update_cache(); } break; + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: case NOTIFICATION_TRANSFORM_CHANGED: { if (!is_inside_tree()) { break; @@ -127,6 +128,10 @@ void RemoteTransform2D::_notification(int p_what) { } void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) { + if (remote_node == p_remote_node) { + return; + } + remote_node = p_remote_node; if (is_inside_tree()) { _update_cache(); @@ -141,7 +146,13 @@ NodePath RemoteTransform2D::get_remote_node() const { } void RemoteTransform2D::set_use_global_coordinates(const bool p_enable) { + if (use_global_coordinates == p_enable) { + return; + } + use_global_coordinates = p_enable; + set_notify_transform(use_global_coordinates); + set_notify_local_transform(!use_global_coordinates); _update_remote(); } @@ -150,6 +161,9 @@ bool RemoteTransform2D::get_use_global_coordinates() const { } void RemoteTransform2D::set_update_position(const bool p_update) { + if (update_remote_position == p_update) { + return; + } update_remote_position = p_update; _update_remote(); } @@ -159,6 +173,9 @@ bool RemoteTransform2D::get_update_position() const { } void RemoteTransform2D::set_update_rotation(const bool p_update) { + if (update_remote_rotation == p_update) { + return; + } update_remote_rotation = p_update; _update_remote(); } @@ -168,6 +185,9 @@ bool RemoteTransform2D::get_update_rotation() const { } void RemoteTransform2D::set_update_scale(const bool p_update) { + if (update_remote_scale == p_update) { + return; + } update_remote_scale = p_update; _update_remote(); } @@ -215,6 +235,7 @@ void RemoteTransform2D::_bind_methods() { } RemoteTransform2D::RemoteTransform2D() { - set_notify_transform(true); + set_notify_transform(use_global_coordinates); + set_notify_local_transform(!use_global_coordinates); set_hide_clip_children(true); } diff --git a/scene/3d/remote_transform_3d.cpp b/scene/3d/remote_transform_3d.cpp index fe309a82f88..add58da4bac 100644 --- a/scene/3d/remote_transform_3d.cpp +++ b/scene/3d/remote_transform_3d.cpp @@ -113,6 +113,7 @@ void RemoteTransform3D::_notification(int p_what) { _update_cache(); } break; + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: case NOTIFICATION_TRANSFORM_CHANGED: { if (!is_inside_tree()) { break; @@ -126,6 +127,10 @@ void RemoteTransform3D::_notification(int p_what) { } void RemoteTransform3D::set_remote_node(const NodePath &p_remote_node) { + if (remote_node == p_remote_node) { + return; + } + remote_node = p_remote_node; if (is_inside_tree()) { _update_cache(); @@ -140,7 +145,15 @@ NodePath RemoteTransform3D::get_remote_node() const { } void RemoteTransform3D::set_use_global_coordinates(const bool p_enable) { + if (use_global_coordinates == p_enable) { + return; + } + use_global_coordinates = p_enable; + + set_notify_transform(use_global_coordinates); + set_notify_local_transform(!use_global_coordinates); + _update_remote(); } bool RemoteTransform3D::get_use_global_coordinates() const { @@ -148,6 +161,9 @@ bool RemoteTransform3D::get_use_global_coordinates() const { } void RemoteTransform3D::set_update_position(const bool p_update) { + if (update_remote_position == p_update) { + return; + } update_remote_position = p_update; _update_remote(); } @@ -157,6 +173,9 @@ bool RemoteTransform3D::get_update_position() const { } void RemoteTransform3D::set_update_rotation(const bool p_update) { + if (update_remote_rotation == p_update) { + return; + } update_remote_rotation = p_update; _update_remote(); } @@ -166,6 +185,9 @@ bool RemoteTransform3D::get_update_rotation() const { } void RemoteTransform3D::set_update_scale(const bool p_update) { + if (update_remote_scale == p_update) { + return; + } update_remote_scale = p_update; _update_remote(); } @@ -213,5 +235,6 @@ void RemoteTransform3D::_bind_methods() { } RemoteTransform3D::RemoteTransform3D() { - set_notify_transform(true); + set_notify_transform(use_global_coordinates); + set_notify_local_transform(!use_global_coordinates); }