Merge pull request #69722 from TokageItLab/more-refactor-immediate-anim

More refactor AnimationPlayer process for Method track which change animation with Immediate mode
This commit is contained in:
Rémi Verschelde 2022-12-07 15:13:55 +01:00
commit a7937fe54c
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 22 additions and 31 deletions

View File

@ -1044,14 +1044,15 @@ 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. 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; cd.pos = next_pos;
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); _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) { // End detection.
if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) {
if (prev_from != playback.current.from) {
return; // Animation has been changed in the process (may be caused by method track), abort process. return; // Animation has been changed in the process (may be caused by method track), abort process.
} }
if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) {
if (&cd == &playback.current) {
if (!backwards && prev_pos <= len && next_pos == len) { if (!backwards && prev_pos <= len && next_pos == len) {
// Playback finished. // Playback finished.
end_reached = true; end_reached = true;
@ -1064,7 +1065,6 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta,
} }
} }
} }
}
void AnimationPlayer::_animation_process2(double p_delta, bool p_started) { void AnimationPlayer::_animation_process2(double p_delta, bool p_started) {
Playback &c = playback; Playback &c = playback;
@ -1130,8 +1130,6 @@ void AnimationPlayer::_animation_update_transforms() {
} }
} }
cache_update_size = 0;
for (int i = 0; i < cache_update_prop_size; i++) { for (int i = 0; i < cache_update_prop_size; i++) {
TrackNodeCache::PropertyAnim *pa = cache_update_prop[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++) { for (int i = 0; i < cache_update_bezier_size; i++) {
TrackNodeCache::BezierAnim *ba = cache_update_bezier[i]; TrackNodeCache::BezierAnim *ba = cache_update_bezier[i];
ERR_CONTINUE(ba->accum_pass != accum_pass); ERR_CONTINUE(ba->accum_pass != accum_pass);
ba->object->set_indexed(ba->bezier_property, ba->bezier_accum); ba->object->set_indexed(ba->bezier_property, ba->bezier_accum);
} }
cache_update_bezier_size = 0;
} }
void AnimationPlayer::_animation_process(double p_delta) { void AnimationPlayer::_animation_process(double p_delta) {
if (playback.current.from) { if (playback.current.from) {
end_reached = false; end_reached = false;
end_notify = 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. 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) { if (playback.started) {
playback.started = false; playback.started = false;
} }
_animation_process2(p_delta, started);
if (is_just_played) {
cache_update_size = 0; cache_update_size = 0;
cache_update_prop_size = 0; cache_update_prop_size = 0;
cache_update_bezier_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(); _animation_update_transforms();
if (end_reached) { if (end_reached) {
@ -1675,7 +1668,6 @@ void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, floa
c.assigned = name; c.assigned = name;
c.seeked = false; c.seeked = false;
c.started = true; c.started = true;
is_just_played = true;
if (!end_reached) { if (!end_reached) {
queued.clear(); queued.clear();

View File

@ -255,7 +255,6 @@ private:
List<StringName> queued; List<StringName> queued;
bool is_just_played = false;
bool end_reached = false; bool end_reached = false;
bool end_notify = false; bool end_notify = false;