From fb116af9cc4be6991949cdfd3c8b25cce96bfa2d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Oct 2014 05:23:49 +0200 Subject: [PATCH] Refactor update_tween - kivutar - verify if everything still works as expected --- frontend/menu/menu_animation.c | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/frontend/menu/menu_animation.c b/frontend/menu/menu_animation.c index f82e2d45c2..190d1f4b0c 100644 --- a/frontend/menu/menu_animation.c +++ b/frontend/menu/menu_animation.c @@ -58,27 +58,31 @@ void add_tween(float duration, float target_value, float* subject, static void update_tween(tween_t *tween, float dt, int *active_tweens) { - if (tween && tween->running_since < tween->duration) + if (!tween) + return; + + if (tween->running_since >= tween->duration) + return; + + tween->running_since += dt; + + if (tween->easing) + *tween->subject = tween->easing( + tween->running_since, + tween->initial_value, + tween->target_value - tween->initial_value, + tween->duration); + + if (tween->running_since >= tween->duration) { - tween->running_since += dt; + *tween->subject = tween->target_value; - if (tween->easing) - *tween->subject = tween->easing( - tween->running_since, - tween->initial_value, - tween->target_value - tween->initial_value, - tween->duration); - - if (tween->running_since >= tween->duration) - { - *tween->subject = tween->target_value; - - if (tween->callback) - tween->callback(); - } + if (tween->callback) + tween->callback(); } - *active_tweens += tween->running_since < tween->duration ? 1 : 0; + if (tween->running_since < tween->duration) + *active_tweens += 1; } void update_tweens(float dt)