diff options
author | Răzvan C. Rădulescu <razcore.art@gmail.com> | 2018-06-26 19:19:11 +0200 |
---|---|---|
committer | Răzvan C. Rădulescu <razcore.art@gmail.com> | 2018-06-27 10:17:00 +0200 |
commit | 07874292d0246e7d09dfc9aeb25c25e867eaa724 (patch) | |
tree | 32f90a94b6e98b29768126bf535c062f48dd12fc | |
parent | 5c914e2d5b5ac1e488c97089e1bc053585fce9a8 (diff) |
Check "done" state in original loop
My first attepmt I added a second loop to check if processing should
stop. This attempts to optimize by using the original loop (one loop).
Also resets `elapsed` time on finish of tween which fixes `tell()`.
-rw-r--r-- | scene/animation/tween.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 6fa9723239..81fdc32788 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -521,8 +521,8 @@ void Tween::_tween_process(float p_delta) { pending_update++; // if repeat and all interpolates was finished then reset all interpolates + bool all_finished = true; if (repeat) { - bool all_finished = true; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { @@ -538,9 +538,12 @@ void Tween::_tween_process(float p_delta) { reset_all(); } + all_finished = true; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { InterpolateData &data = E->get(); + all_finished = all_finished && data.finish; + if (!data.active || data.finish) continue; @@ -554,8 +557,8 @@ void Tween::_tween_process(float p_delta) { continue; else if (prev_delaying) { - emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); _apply_tween_value(data, data.initial_val); + emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); } if (data.elapsed > (data.delay + data.duration)) { @@ -608,29 +611,18 @@ void Tween::_tween_process(float p_delta) { if (data.finish) { _apply_tween_value(data, data.final_val); + data.elapsed = 0; emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); // not repeat mode, remove completed action if (!repeat) call_deferred("_remove", object, NodePath(Vector<StringName>(), data.key, false), true); - } + } else if (!repeat) + all_finished = all_finished && data.finish; } pending_update--; - if (!repeat) { - bool all_finished = true; - for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { - - InterpolateData &data = E->get(); - - if (data.finish == false) { - all_finished = false; - break; - } - } - - if (all_finished) - set_active(false); - } + if (all_finished) + set_active(false); } void Tween::set_tween_process_mode(TweenProcessMode p_mode) { |