From 02dfda3ad32407ee8f94c20d7ef047344af11d06 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 9 Jan 2017 16:39:09 +0100 Subject: [PATCH] Create menu_animation_update --- menu/drivers/materialui.c | 2 +- menu/drivers/xmb.c | 2 +- menu/menu_animation.c | 114 +++++++++++++++++--------------------- menu/menu_animation.h | 3 +- 4 files changed, 56 insertions(+), 65 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 8031d14b5c..872c3be471 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -518,7 +518,7 @@ static void mui_render(void *data) delta.current = delta_time; if (menu_animation_ctl(MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET, &delta)) - menu_animation_ctl(MENU_ANIMATION_CTL_UPDATE, &delta.ideal); + menu_animation_update(delta.ideal); menu_display_set_width(width); menu_display_set_height(height); diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 28cf76bf74..ea5d427883 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2356,7 +2356,7 @@ static void xmb_render(void *data) delta.current = delta_time; if (menu_animation_ctl(MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET, &delta)) - menu_animation_ctl(MENU_ANIMATION_CTL_UPDATE, &delta.ideal); + menu_animation_update(delta.ideal); if (settings->menu.pointer.enable || settings->menu.mouse.enable) { diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 175ac1998f..70636f12d2 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -52,6 +52,12 @@ struct menu_animation typedef struct menu_animation menu_animation_t; +static menu_animation_t anim; +static retro_time_t cur_time = 0; +static retro_time_t old_time = 0; +static float delta_time = 0.0f; +static bool animation_is_active = false; + /* from https://github.com/kikito/tween.lua/blob/master/tween.lua */ static float easing_linear(float t, float b, float c, float d) @@ -280,40 +286,6 @@ static float easing_out_in_bounce(float t, float b, float c, float d) return easing_in_bounce((t * 2) - d, b + c / 2, c / 2, d); } -static int menu_animation_iterate(menu_animation_t *anim, - unsigned idx, float dt, unsigned *active_tweens) -{ - struct tween *tween = &anim->list[idx]; - - if (!tween || !tween->alive) - return -1; - - tween->running_since += dt; - - *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; - tween->alive = false; - - if (idx < anim->first_dead) - anim->first_dead = idx; - - if (tween->cb) - tween->cb(); - } - - if (tween->running_since < tween->duration) - *active_tweens += 1; - - return 0; -} - static void menu_animation_ticker_generic(uint64_t idx, size_t max_width, size_t *offset, size_t *width) { @@ -509,15 +481,55 @@ static bool menu_animation_push(menu_animation_t *anim, menu_animation_ctx_entry return true; } +bool menu_animation_update(float delta_time) +{ + unsigned i; + unsigned active_tweens = 0; + + for(i = 0; i < anim.size; i++) + { + struct tween *tween = &anim.list[i]; + if (!tween || !tween->alive) + continue; + + tween->running_since += delta_time; + + *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; + tween->alive = false; + + if (i < anim.first_dead) + anim.first_dead = i; + + if (tween->cb) + tween->cb(); + } + + if (tween->running_since < tween->duration) + active_tweens += 1; + } + + if (!active_tweens) + { + anim.size = 0; + anim.first_dead = 0; + return false; + } + + animation_is_active = true; + + return true; +} bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data) { - static menu_animation_t anim; - static retro_time_t cur_time = 0; - static retro_time_t old_time = 0; - static float delta_time = 0.0f; - static bool animation_is_active = false; - switch (state) { case MENU_ANIMATION_CTL_DEINIT: @@ -576,28 +588,6 @@ bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data) } } break; - case MENU_ANIMATION_CTL_UPDATE: - { - unsigned i; - unsigned active_tweens = 0; - float *dt = (float*)data; - - if (!dt) - return false; - - for(i = 0; i < anim.size; i++) - menu_animation_iterate(&anim, i, *dt, &active_tweens); - - if (!active_tweens) - { - anim.size = 0; - anim.first_dead = 0; - return false; - } - - animation_is_active = true; - } - break; case MENU_ANIMATION_CTL_KILL_BY_TAG: { unsigned i; diff --git a/menu/menu_animation.h b/menu/menu_animation.h index 71daa5219a..631e569f8e 100644 --- a/menu/menu_animation.h +++ b/menu/menu_animation.h @@ -37,7 +37,6 @@ enum menu_animation_ctl_state MENU_ANIMATION_CTL_SET_ACTIVE, MENU_ANIMATION_CTL_DELTA_TIME, MENU_ANIMATION_CTL_UPDATE_TIME, - MENU_ANIMATION_CTL_UPDATE, MENU_ANIMATION_CTL_KILL_BY_TAG, MENU_ANIMATION_CTL_KILL_BY_SUBJECT, MENU_ANIMATION_CTL_TICKER, @@ -127,6 +126,8 @@ typedef struct menu_animation_ctx_ticker bool selected; } menu_animation_ctx_ticker_t; +bool menu_animation_update(float delta_time); + bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data); RETRO_END_DECLS