From 13a87d48fe87ddd643d1fd264fbc7ec8e567d2d5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 23:59:16 +0100 Subject: [PATCH] Refactor tweens_push --- menu/menu_animation.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/menu/menu_animation.c b/menu/menu_animation.c index d1fbcfb7b6..2cb31058e9 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -27,33 +27,38 @@ void tweens_free(tween_t *tween) bool tweens_push(float duration, float target_value, float* subject, easingFunc easing, tween_cb cb, unsigned *numtweens) { - tween_t *tween = NULL, *temp_tweens = NULL; + size_t cap; + tween_t *temp_tweens = NULL; if (!driver.menu) return false; + + cap = *numtweens; temp_tweens = (tween_t*)realloc(driver.menu->tweens, - (*numtweens + 1) * sizeof(tween_t)); + (cap + 1) * sizeof(tween_t)); if (!temp_tweens) + { + tweens_free(driver.menu->tweens); return false; + } driver.menu->tweens = temp_tweens; - tween = (tween_t*)&driver.menu->tweens[*numtweens]; - if (!tween) + if (!driver.menu->tweens) return false; - tween->alive = 1; - tween->duration = duration; - tween->running_since = 0; - tween->initial_value = *subject; - tween->target_value = target_value; - tween->subject = subject; - tween->easing = easing; - tween->cb = cb; + driver.menu->tweens[cap].alive = 1; + driver.menu->tweens[cap].duration = duration; + driver.menu->tweens[cap].running_since = 0; + driver.menu->tweens[cap].initial_value = *subject; + driver.menu->tweens[cap].target_value = target_value; + driver.menu->tweens[cap].subject = subject; + driver.menu->tweens[cap].easing = easing; + driver.menu->tweens[cap].cb = cb; - *numtweens = *numtweens + 1; + *numtweens = cap + 1; return true; }