diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-07 15:13:55 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-07 15:13:55 +0100 |
commit | a7937fe54cd2c1f407a529e46e2708aea5ce7243 (patch) | |
tree | 46b1c74331d3a51b26dacba5e3eee49b2ce3da54 | |
parent | 489d26e96e6f1b8d935a2e8cc879d67a3e655743 (diff) | |
parent | bd8395882ebf6259d2b5f3c0e5225291d41b9518 (diff) |
Merge pull request #69722 from TokageItLab/more-refactor-immediate-anim
More refactor AnimationPlayer process for Method track which change animation with Immediate mode
-rw-r--r-- | scene/animation/animation_player.cpp | 52 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 1 |
2 files changed, 22 insertions, 31 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index ff3112ecbb..4800a83255 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1044,24 +1044,24 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta, double prev_pos = cd.pos; // The animation may be changed during process, so it is safer that the state is changed before process. cd.pos = next_pos; - _animation_process_animation(cd.from, prev_pos, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started, looped_flag); - if (is_just_played) { - return; // Animation has been changed in the process (may be caused by method track), abort process. - } + AnimationData *prev_from = cd.from; + _animation_process_animation(cd.from, prev_pos, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started, looped_flag); + // End detection. if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) { - if (&cd == &playback.current) { - if (!backwards && prev_pos <= len && next_pos == len) { - // Playback finished. - end_reached = true; - end_notify = prev_pos < len; // Notify only if not already at the end. - } - if (backwards && prev_pos >= 0 && next_pos == 0) { - // Playback finished. - end_reached = true; - end_notify = prev_pos > 0; // Notify only if not already at the beginning. - } + if (prev_from != playback.current.from) { + return; // Animation has been changed in the process (may be caused by method track), abort process. + } + if (!backwards && prev_pos <= len && next_pos == len) { + // Playback finished. + end_reached = true; + end_notify = prev_pos < len; // Notify only if not already at the end. + } + if (backwards && prev_pos >= 0 && next_pos == 0) { + // Playback finished. + end_reached = true; + end_notify = prev_pos > 0; // Notify only if not already at the beginning. } } } @@ -1130,8 +1130,6 @@ void AnimationPlayer::_animation_update_transforms() { } } - cache_update_size = 0; - for (int i = 0; i < cache_update_prop_size; i++) { TrackNodeCache::PropertyAnim *pa = cache_update_prop[i]; @@ -1193,38 +1191,33 @@ void AnimationPlayer::_animation_update_transforms() { } } - cache_update_prop_size = 0; - for (int i = 0; i < cache_update_bezier_size; i++) { TrackNodeCache::BezierAnim *ba = cache_update_bezier[i]; ERR_CONTINUE(ba->accum_pass != accum_pass); ba->object->set_indexed(ba->bezier_property, ba->bezier_accum); } - - cache_update_bezier_size = 0; } void AnimationPlayer::_animation_process(double p_delta) { if (playback.current.from) { end_reached = false; end_notify = false; - is_just_played = false; bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process. if (playback.started) { playback.started = false; } - _animation_process2(p_delta, started); + cache_update_size = 0; + cache_update_prop_size = 0; + cache_update_bezier_size = 0; - if (is_just_played) { - cache_update_size = 0; - cache_update_prop_size = 0; - cache_update_bezier_size = 0; - return; // Animation has been changed in the process (may be caused by method track), clear update caches and abort process. + AnimationData *prev_from = playback.current.from; + _animation_process2(p_delta, started); + if (prev_from != playback.current.from) { + return; // Animation has been changed in the process (may be caused by method track), abort process. } - _animation_update_transforms(); if (end_reached) { @@ -1675,7 +1668,6 @@ void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, floa c.assigned = name; c.seeked = false; c.started = true; - is_just_played = true; if (!end_reached) { queued.clear(); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 352835a544..0b95ee4e9e 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -255,7 +255,6 @@ private: List<StringName> queued; - bool is_just_played = false; bool end_reached = false; bool end_notify = false; |