Merge pull request #75487 from Rindbee/improve_update_remote_in_RemoteTransform2D

Fix RemoteTransform2D could fail to update AnimatableBody2D's position or rotation
This commit is contained in:
Rémi Verschelde 2023-04-03 16:03:34 +02:00
commit 3c225c19c1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 35 additions and 38 deletions

View File

@ -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();
if (!update_remote_position) {
our_trans.set_origin(n_trans.get_origin());
}
if (!update_remote_rotation) {
our_trans.set_rotation(n_trans.get_rotation());
}
n->set_global_transform(our_trans);
if (update_remote_scale) {
n->set_scale(get_global_scale());
} else {
n->set_scale(n_scale);
}
return;
}
Transform2D n_trans = n->get_global_transform();
Transform2D our_trans = get_global_transform();
// 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_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();
if (!update_remote_position) {
our_trans.set_origin(n_trans.get_origin());
}
if (!update_remote_rotation) {
our_trans.set_rotation(n_trans.get_rotation());
}
n->set_transform(our_trans);
if (update_remote_scale) {
n->set_scale(get_scale());
} else {
n->set_scale(n_scale);
}
return;
}
Transform2D n_trans = n->get_transform();
Transform2D our_trans = get_transform();
// 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_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);
}
}