Merge pull request #93938 from TokageItLab/cp-anim-4-2

Cherry-pick animation fixes for 4.2
This commit is contained in:
Rémi Verschelde 2024-07-05 12:18:59 +02:00 committed by GitHub
commit 32a7ddca38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 5 deletions

View File

@ -273,7 +273,7 @@ void AnimationNodeBlendSpace1D::_add_blend_point(int p_index, const Ref<Animatio
}
double AnimationNodeBlendSpace1D::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
if (blend_points_used == 0) {
if (!blend_points_used) {
return 0.0;
}

View File

@ -445,6 +445,10 @@ void AnimationNodeBlendSpace2D::_blend_triangle(const Vector2 &p_pos, const Vect
double AnimationNodeBlendSpace2D::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) {
_update_triangles();
if (!blend_points_used) {
return 0;
}
Vector2 blend_pos = get_parameter(blend_position);
int cur_closest = get_parameter(closest);
double cur_length_internal = get_parameter(length_internal);
@ -453,7 +457,7 @@ double AnimationNodeBlendSpace2D::_process(const AnimationMixer::PlaybackInfo p_
AnimationMixer::PlaybackInfo pi = p_playback_info;
if (blend_mode == BLEND_MODE_INTERPOLATED) {
if (triangles.size() == 0) {
if (triangles.is_empty()) {
return 0;
}

View File

@ -1572,7 +1572,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
}
if (seeked) {
// Seek.
int idx = a->track_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT);
int idx = a->track_find_key(i, time, Animation::FIND_MODE_NEAREST);
if (idx < 0) {
continue;
}
@ -1585,6 +1585,9 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
double at_anim_pos = 0.0;
switch (anim->get_loop_mode()) {
case Animation::LOOP_NONE: {
if (!is_external_seeking && ((!backward && time >= pos + (double)anim->get_length()) || (backward && time <= pos))) {
continue; // Do nothing if current time is outside of length when started.
}
at_anim_pos = MIN((double)anim->get_length(), time - pos); // Seek to end.
} break;
case Animation::LOOP_LINEAR: {
@ -1596,7 +1599,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
default:
break;
}
if (player2->is_playing()) {
if (player2->is_playing() || !is_external_seeking) {
player2->seek(at_anim_pos, false, p_update_only);
player2->play(anim_name);
t->playing = true;

View File

@ -149,7 +149,7 @@ void AnimationPlayer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
set_active(true);
set_active(active);
play(autoplay);
_check_immediately_after_start();
}

View File

@ -1397,6 +1397,15 @@ void Control::_set_position(const Point2 &p_point) {
void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
ERR_MAIN_THREAD_GUARD;
#ifdef TOOLS_ENABLED
// Can't compute anchors, set position directly and return immediately.
if (saving && !is_inside_tree()) {
data.pos_cache = p_point;
return;
}
#endif
if (p_keep_offsets) {
_compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
} else {
@ -1457,6 +1466,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) {
new_size.y = min.y;
}
#ifdef TOOLS_ENABLED
// Can't compute anchors, set size directly and return immediately.
if (saving && !is_inside_tree()) {
data.size_cache = new_size;
return;
}
#endif
if (p_keep_offsets) {
_compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
} else {
@ -3135,6 +3152,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const {
void Control::_notification(int p_notification) {
ERR_MAIN_THREAD_GUARD;
switch (p_notification) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_EDITOR_PRE_SAVE: {
saving = true;
} break;
case NOTIFICATION_EDITOR_POST_SAVE: {
saving = false;
} break;
#endif
case NOTIFICATION_POSTINITIALIZE: {
data.initialized = true;

View File

@ -47,6 +47,10 @@ class ThemeContext;
class Control : public CanvasItem {
GDCLASS(Control, CanvasItem);
#ifdef TOOLS_ENABLED
bool saving = false;
#endif
public:
enum Anchor {
ANCHOR_BEGIN = 0,