Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick animation fixes for 4.2 #93938

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scene/animation/animation_blend_space_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion scene/animation/animation_blend_space_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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: {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
25 changes: 25 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading