diff options
author | Rindbee <idleman@yeah.net> | 2023-04-07 17:44:38 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-04-07 17:44:38 +0200 |
commit | 2b0acb61be451158c8dc29577318f0cfb0f113e1 (patch) | |
tree | 9623e63dc17b784fd117a9549f748bcde9913e47 /scene/2d | |
parent | 88d446f6c6eff3e3bb3013099325b9d37ce3aad3 (diff) |
Fix RemoteTransform2D could fail to update AnimatableBody2D's position or rotation
Configure the transform per condition, and then only set it once to
prevent multiple `NOTIFICATION_LOCAL_TRANSFORM_CHANGED` notifications
from being sent.
(cherry picked from commit 100b4b1f287600bde9c4f2704c2addbb3d65448e)
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/remote_transform_2d.cpp | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index c6730f7ab2..cd0d9f3750 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -60,54 +60,51 @@ void RemoteTransform2D::_update_remote() { return; } + if (!(update_remote_position || update_remote_rotation || update_remote_scale)) { + return; // The transform data of the RemoteTransform2D is not used at all. + } + //todo make faster if (use_global_coordinates) { if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_global_transform(get_global_transform()); - } else { - Transform2D n_trans = n->get_global_transform(); - Transform2D our_trans = get_global_transform(); - Vector2 n_scale = n->get_scale(); + return; + } - if (!update_remote_position) { - our_trans.set_origin(n_trans.get_origin()); - } - if (!update_remote_rotation) { - our_trans.set_rotation(n_trans.get_rotation()); - } + Transform2D n_trans = n->get_global_transform(); + Transform2D our_trans = get_global_transform(); - n->set_global_transform(our_trans); + // There are more steps in the operation of set_rotation, so avoid calling it. + Transform2D trans = update_remote_rotation ? our_trans : n_trans; - if (update_remote_scale) { - n->set_scale(get_global_scale()); - } else { - n->set_scale(n_scale); - } + if (update_remote_rotation ^ update_remote_position) { + trans.set_origin(update_remote_position ? our_trans.get_origin() : n_trans.get_origin()); + } + if (update_remote_rotation ^ update_remote_scale) { + trans.set_scale(update_remote_scale ? our_trans.get_scale() : n_trans.get_scale()); } + n->set_global_transform(trans); } else { if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_transform(get_transform()); - } else { - Transform2D n_trans = n->get_transform(); - Transform2D our_trans = get_transform(); - Vector2 n_scale = n->get_scale(); + return; + } - if (!update_remote_position) { - our_trans.set_origin(n_trans.get_origin()); - } - if (!update_remote_rotation) { - our_trans.set_rotation(n_trans.get_rotation()); - } + Transform2D n_trans = n->get_transform(); + Transform2D our_trans = get_transform(); - n->set_transform(our_trans); + // There are more steps in the operation of set_rotation, so avoid calling it. + Transform2D trans = update_remote_rotation ? our_trans : n_trans; - if (update_remote_scale) { - n->set_scale(get_scale()); - } else { - n->set_scale(n_scale); - } + if (update_remote_rotation ^ update_remote_position) { + trans.set_origin(update_remote_position ? our_trans.get_origin() : n_trans.get_origin()); + } + if (update_remote_rotation ^ update_remote_scale) { + trans.set_scale(update_remote_scale ? our_trans.get_scale() : n_trans.get_scale()); } + + n->set_transform(trans); } } |