menu_animation: use milliseconds as a unit

This commit is contained in:
natinusala 2019-02-14 11:58:27 +01:00
parent bfcc32b7be
commit f481c594e8
14 changed files with 86 additions and 103 deletions

View File

@ -167,8 +167,6 @@ typedef struct materialui_handle
float textures_arrow_alpha;
float categories_x_pos;
uint64_t frame_count;
char *box_message;
char menu_title[255];
@ -936,7 +934,6 @@ static void materialui_render_menu_list(
float sum = 0;
size_t entries_end = 0;
file_list_t *list = NULL;
uint64_t frame_count = mui->frame_count;
unsigned header_height =
menu_display_get_header_height();
@ -987,7 +984,7 @@ static void materialui_render_menu_list(
y,
width,
height,
frame_count / 20,
menu_animation_get_ticker_idx(),
font_hover_color,
entry_selected,
rich_label,
@ -1179,8 +1176,6 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
usable_width = width - (mui->margin * 2);
mui->frame_count++;
msg[0] = title_buf[0] = title_msg[0] = '\0';
switch (video_info->materialui_color_theme)
@ -1532,7 +1527,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
ticker.s = title_buf;
ticker.len = ticker_limit;
ticker.idx = mui->frame_count / 100;
ticker.idx = menu_animation_get_ticker_slow_idx();
ticker.str = mui->menu_title;
ticker.selected = true;
@ -1554,7 +1549,7 @@ static void materialui_frame(void *data, video_frame_info_t *video_info)
ticker.s = title_buf_msg_tmp;
ticker.len = ticker_limit;
ticker.idx = mui->frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.str = title_buf_msg;
ticker.selected = true;
@ -1810,7 +1805,7 @@ static void materialui_navigation_set(void *data, bool scroll)
if (!mui || !scroll)
return;
entry.duration = 10;
entry.duration = 166;
entry.target_value = scroll_pos;
entry.subject = &mui->scroll_y;
entry.easing_enum = EASING_IN_OUT_QUAD;

View File

@ -482,7 +482,6 @@ static void ozone_context_reset(void *data, bool is_threaded)
ozone_context_reset_horizontal_list(ozone);
/* State reset */
ozone->frame_count = 0;
ozone->fade_direction = false;
ozone->cursor_in_sidebar = false;
ozone->cursor_in_sidebar_old = false;
@ -862,7 +861,7 @@ static void ozone_draw_header(ozone_handle_t *ozone, video_frame_info_t *video_i
/* Title */
ticker.s = title;
ticker.len = (video_info->width - 128 - 47 - 130) / ozone->title_font_glyph_width;
ticker.idx = ozone->frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.str = ozone->title;
ticker.selected = true;
@ -1101,8 +1100,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
last_use_preferred_system_color_theme = settings->bools.menu_use_preferred_system_color_theme;
}
ozone->frame_count++;
menu_display_set_viewport(video_info->width, video_info->height);
/* Clear text */

View File

@ -27,9 +27,9 @@ typedef struct ozone_handle ozone_handle_t;
#include "../../menu_driver.h"
#include "../../../retroarch.h"
#define ANIMATION_PUSH_ENTRY_DURATION 10
#define ANIMATION_CURSOR_DURATION 8
#define ANIMATION_CURSOR_PULSE 30
#define ANIMATION_PUSH_ENTRY_DURATION 166
#define ANIMATION_CURSOR_DURATION 133
#define ANIMATION_CURSOR_PULSE 500
#define FONT_SIZE_FOOTER 18
#define FONT_SIZE_TITLE 36
@ -64,8 +64,6 @@ typedef struct ozone_handle ozone_handle_t;
struct ozone_handle
{
uint64_t frame_count;
struct
{
font_data_t *footer;

View File

@ -442,7 +442,7 @@ border_iterate:
/* Prepare text */
entry_rich_label = menu_entry_get_rich_label(&entry);
ticker.idx = ozone->frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.s = rich_label;
ticker.str = entry_rich_label;
ticker.selected = entry_selected && !ozone->cursor_in_sidebar;
@ -518,7 +518,7 @@ border_iterate:
y + ozone->dimensions.entry_height + 1 + 5 + FONT_SIZE_ENTRIES_SUBLABEL + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_sublabel, COLOR_TEXT_ALPHA(ozone->theme->text_sublabel_rgba, alpha_uint32), false);
/* Value */
ticker.idx = ozone->frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.s = entry_value_ticker;
ticker.str = entry_value;
ticker.selected = entry_selected && !ozone->cursor_in_sidebar;

View File

@ -226,7 +226,7 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
/* Text */
ticker.idx = ozone->frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.len = (entry_width - ozone->dimensions.sidebar_entry_icon_size - 35) / ozone->sidebar_font_glyph_width;
ticker.s = console_title;
ticker.selected = selected;

View File

@ -411,7 +411,6 @@ typedef struct
bool mouse_show;
unsigned last_width;
unsigned last_height;
unsigned frame_count;
bool bg_thickness;
bool border_thickness;
float scroll_y;
@ -1457,8 +1456,6 @@ static void rgui_frame(void *data, video_frame_info_t *video_info)
prepare_rgui_colors(rgui, settings);
}
}
rgui->frame_count++;
}
static void rgui_render(void *data, bool is_idle)
@ -1473,7 +1470,6 @@ static void rgui_render(void *data, bool is_idle)
bool msg_force = false;
settings_t *settings = config_get_ptr();
rgui_t *rgui = (rgui_t*)data;
uint64_t frame_count = rgui->frame_count;
static bool display_kb = false;
bool current_display_cb = false;
@ -1589,7 +1585,7 @@ static void rgui_render(void *data, bool is_idle)
/* We use a single ticker for all text animations,
* with the following configuration: */
ticker.idx = frame_count / RGUI_TERM_START_X(fb_width);
ticker.idx = menu_animation_get_ticker_idx();
ticker.type_enum = settings->uints.menu_ticker_type;
ticker.spacer = ticker_spacer;

View File

@ -69,7 +69,7 @@
#define STRIPES_RIBBON_VERTICES 2*STRIPES_RIBBON_COLS*STRIPES_RIBBON_ROWS-2*STRIPES_RIBBON_COLS
#ifndef STRIPES_DELAY
#define STRIPES_DELAY 10
#define STRIPES_DELAY 166
#endif
#define BATTERY_LEVEL_CHECK_INTERVAL (30 * 1000000)
@ -249,8 +249,6 @@ typedef struct stripes_handle
float categories_active_alpha;
float categories_active_width;
uint64_t frame_count;
char title_name[255];
char *box_message;
char *thumbnail_system;
@ -2323,7 +2321,6 @@ static int stripes_draw_item(
float *color,
const char *thumb_ident,
const char *left_thumb_ident,
uint64_t frame_count,
size_t i,
size_t current,
unsigned width,
@ -2455,7 +2452,7 @@ static int stripes_draw_item(
ticker.s = tmp;
ticker.len = ticker_limit;
ticker.idx = frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.str = ticker_str;
ticker.selected = (i == current);
@ -2491,7 +2488,7 @@ static int stripes_draw_item(
ticker.s = tmp;
ticker.len = 35 * stripes_scale_mod[7];
ticker.idx = frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.selected = (i == current);
if (!string_is_empty(entry->value))
@ -2592,7 +2589,6 @@ static void stripes_draw_items(
menu_display_ctx_rotate_draw_t rotate_draw;
stripes_node_t *core_node = NULL;
size_t end = 0;
uint64_t frame_count = stripes ? stripes->frame_count : 0;
const char *thumb_ident = stripes_thumbnails_ident('R');
const char *left_thumb_ident= stripes_thumbnails_ident('L');
@ -2645,7 +2641,6 @@ static void stripes_draw_items(
&mymat,
stripes, core_node,
list, color, thumb_ident, left_thumb_ident,
frame_count,
i, current,
width, height);
menu_entry_free(&entry);
@ -2828,8 +2823,6 @@ static void stripes_frame(void *data, video_frame_info_t *video_info)
scale_factor = (settings->uints.menu_xmb_scale_factor * (float)width) / (1920.0 * 100);
pseudo_font_length = stripes->icon_spacing_horizontal * 4 - stripes->icon_size / 4;
stripes->frame_count++;
msg[0] = '\0';
title_msg[0] = '\0';
title_truncated[0] = '\0';

View File

@ -71,7 +71,7 @@
#define XMB_RIBBON_VERTICES 2*XMB_RIBBON_COLS*XMB_RIBBON_ROWS-2*XMB_RIBBON_COLS
#ifndef XMB_DELAY
#define XMB_DELAY 10
#define XMB_DELAY 166
#endif
#define BATTERY_LEVEL_CHECK_INTERVAL (30 * 1000000)
@ -304,8 +304,6 @@ typedef struct xmb_handle
float categories_active_zoom;
float categories_active_alpha;
uint64_t frame_count;
char title_name[255];
char *box_message;
char *thumbnail_system;
@ -2796,7 +2794,6 @@ static int xmb_draw_item(
float *color,
const char *thumb_ident,
const char *left_thumb_ident,
uint64_t frame_count,
size_t i,
size_t current,
unsigned width,
@ -2931,7 +2928,7 @@ static int xmb_draw_item(
ticker.s = tmp;
ticker.len = ticker_limit;
ticker.idx = frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.str = ticker_str;
ticker.selected = (i == current);
@ -2967,7 +2964,7 @@ static int xmb_draw_item(
ticker.s = tmp;
ticker.len = 35 * scale_mod[7];
ticker.idx = frame_count / 20;
ticker.idx = menu_animation_get_ticker_idx();
ticker.selected = (i == current);
if (!string_is_empty(entry->value))
@ -3078,7 +3075,6 @@ static void xmb_draw_items(
menu_display_ctx_rotate_draw_t rotate_draw;
xmb_node_t *core_node = NULL;
size_t end = 0;
uint64_t frame_count = xmb->frame_count;
const char *thumb_ident = xmb_thumbnails_ident('R');
const char *left_thumb_ident= xmb_thumbnails_ident('L');
@ -3131,7 +3127,6 @@ static void xmb_draw_items(
&mymat,
xmb, core_node,
list, color, thumb_ident, left_thumb_ident,
frame_count,
i, current,
width, height);
menu_entry_free(&entry);
@ -3398,8 +3393,6 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
scale_factor = (settings->uints.menu_xmb_scale_factor * (float)width) / (1920.0 * 100);
pseudo_font_length = xmb->icon_spacing_horizontal * 4 - xmb->icon_size / 4;
xmb->frame_count++;
msg[0] = '\0';
title_msg[0] = '\0';
title_truncated[0] = '\0';

View File

@ -69,7 +69,6 @@ HXUIOBJ m_back;
HXUIOBJ root_menu;
HXUIOBJ current_menu;
static msg_queue_t *xui_msg_queue = NULL;
static uint64_t xui_frame_count = 0;
class CRetroArch : public CXuiModule
{
@ -366,8 +365,6 @@ static void xui_free(void *data)
(void)data;
app.Uninit();
xui_frame_count = 0;
if (xui_msg_queue)
msg_queue_free(xui_msg_queue);
}
@ -422,8 +419,6 @@ static void xui_frame(void *data, video_frame_info_t *video_info)
if (!d3d)
return;
xui_frame_count++;
menu_display_set_viewport(video_info->width, video_info->height);
app.RunFrame();
@ -544,7 +539,6 @@ static void xui_render(void *data, bool is_idle)
const char *dir = NULL;
const char *label = NULL;
unsigned menu_type = 0;
uint64_t frame_count = xui_frame_count;
bool msg_force = menu_display_get_msg_force();
settings_t *settings = config_get_ptr();
@ -577,7 +571,7 @@ static void xui_render(void *data, bool is_idle)
ticker.s = title;
ticker.len = RXUI_TERM_WIDTH(fb_width) - 3;
ticker.idx = (unsigned int)frame_count / 15;
ticker.idx = menu_animation_get_ticker_idx();
ticker.str = title;
ticker.selected = true;

View File

@ -34,8 +34,6 @@
#include "../configuration.h"
#include "../performance_counters.h"
#define IDEAL_DELTA_TIME (1.0 / 60.0 * 1000000.0)
struct tween
{
float duration;
@ -62,9 +60,14 @@ struct menu_animation
typedef struct menu_animation menu_animation_t;
#define TICKER_SPEED 333
#define TICKER_SLOW_SPEED 1600
static menu_animation_t anim;
static retro_time_t cur_time = 0;
static retro_time_t old_time = 0;
static uint64_t ticker_idx = 0; /* updated every TICKER_SPEED ms */
static uint64_t ticker_slow_idx = 0; /* updated every TICKER_SLOW_SPEED ms */
static float delta_time = 0.0f;
static bool animation_is_active = false;
static bool ticker_is_active = false;
@ -554,9 +557,48 @@ bool menu_animation_push(menu_animation_ctx_entry_t *entry)
return true;
}
bool menu_animation_update(float anim_delta_time)
static void menu_animation_update_time(bool timedate_enable)
{
static retro_time_t
last_clock_update = 0;
static retro_time_t
last_ticker_update = 0;
static retro_time_t
last_ticker_slow_update = 0;
cur_time = cpu_features_get_time_usec() / 1000;
delta_time = old_time == 0 ? 0 : cur_time - old_time;
old_time = cur_time;
if (((cur_time - last_clock_update) > 1000)
&& timedate_enable)
{
animation_is_active = true;
last_clock_update = cur_time;
}
if (ticker_is_active
&& cur_time - last_ticker_update >= TICKER_SPEED)
{
ticker_idx++;
last_ticker_update = cur_time;
}
if (ticker_is_active
&& cur_time - last_ticker_slow_update >= TICKER_SLOW_SPEED)
{
ticker_slow_idx++;
last_ticker_slow_update = cur_time;
}
}
bool menu_animation_update(void)
{
unsigned i;
settings_t *settings = config_get_ptr();
menu_animation_update_time(settings->bools.menu_timedate_enable);
anim.in_update = true;
anim.pending_deletes = false;
@ -564,7 +606,7 @@ bool menu_animation_update(float anim_delta_time)
for(i = 0; i < da_count(anim.list); i++)
{
struct tween *tween = da_getptr(anim.list, i);
tween->running_since += anim_delta_time;
tween->running_since += delta_time;
*tween->subject = tween->easing(
tween->running_since,
@ -715,29 +757,6 @@ bool menu_animation_ticker(const menu_animation_ctx_ticker_t *ticker)
return true;
}
void menu_animation_update_time(bool timedate_enable)
{
static retro_time_t
last_clock_update = 0;
cur_time = cpu_features_get_time_usec();
delta_time = cur_time - old_time;
if (delta_time >= IDEAL_DELTA_TIME* 4)
delta_time = IDEAL_DELTA_TIME * 4;
if (delta_time <= IDEAL_DELTA_TIME / 4)
delta_time = IDEAL_DELTA_TIME / 4;
old_time = cur_time;
if (((cur_time - last_clock_update) > 1000000)
&& timedate_enable)
{
animation_is_active = true;
last_clock_update = cur_time;
}
}
bool menu_animation_is_active(void)
{
return animation_is_active || ticker_is_active;
@ -802,10 +821,9 @@ void menu_animation_kill_by_subject(menu_animation_ctx_subject_t *subject)
}
}
void menu_animation_get_time(menu_animation_ctx_delta_t *delta)
float menu_animation_get_delta_time(void)
{
delta->current = delta_time;
delta->ideal = delta_time / IDEAL_DELTA_TIME;
return delta_time;
}
bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data)
@ -872,3 +890,13 @@ void menu_timer_kill(menu_timer_t *timer)
menu_animation_ctx_tag tag = (uintptr_t) timer;
menu_animation_kill_by_tag(&tag);
}
uint64_t menu_animation_get_ticker_idx(void)
{
return ticker_idx;
}
uint64_t menu_animation_get_ticker_slow_idx(void)
{
return ticker_slow_idx;
}

View File

@ -94,12 +94,6 @@ enum menu_animation_ticker_type
TICKER_TYPE_LAST
};
typedef struct menu_animation_ctx_delta
{
float current;
float ideal;
} menu_animation_ctx_delta_t;
typedef uintptr_t menu_animation_ctx_tag;
typedef struct menu_animation_ctx_subject
@ -153,13 +147,11 @@ void menu_animation_init(void);
void menu_animation_free(void);
bool menu_animation_update(float delta_time);
void menu_animation_get_time(menu_animation_ctx_delta_t *delta);
bool menu_animation_update(void);
bool menu_animation_ticker(const menu_animation_ctx_ticker_t *ticker);
void menu_animation_update_time(bool timedate_enable);
float menu_animation_get_delta_time(void);
bool menu_animation_is_active(void);
@ -173,6 +165,10 @@ void menu_animation_push_delayed(unsigned delay, menu_animation_ctx_entry_t *ent
bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data);
uint64_t menu_animation_get_ticker_idx(void);
uint64_t menu_animation_get_ticker_slow_idx(void);
RETRO_END_DECLS
#endif

View File

@ -1955,9 +1955,6 @@ bool menu_driver_render(bool is_idle, bool rarch_is_inited,
if (BIT64_GET(menu_driver_data->state, MENU_STATE_BLIT))
{
settings_t *settings = config_get_ptr();
menu_animation_update_time(settings->bools.menu_timedate_enable);
if (menu_driver_ctx->render)
menu_driver_ctx->render(menu_userdata, is_idle);
}

View File

@ -162,7 +162,6 @@ void menu_event_kb_set(bool down, enum retro_key key)
*/
unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input)
{
menu_animation_ctx_delta_t delta;
/* Used for key repeat */
static float delay_timer = 0.0f;
static float delay_count = 0.0f;
@ -198,7 +197,7 @@ unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input)
* for old_input_state. */
first_held = true;
delay_timer = initial_held ? 12 : 6;
delay_timer = initial_held ? 200 : 100;
delay_count = 0;
}
@ -235,8 +234,7 @@ unsigned menu_event(input_bits_t *p_input, input_bits_t *p_trigger_input)
menu_driver_ctl(MENU_NAVIGATION_CTL_SET_SCROLL_ACCEL,
&new_scroll_accel);
menu_animation_get_time(&delta);
delay_count += delta.ideal;
delay_count += menu_animation_get_delta_time();
if (menu_input_dialog_get_display_kb())
{

View File

@ -2732,7 +2732,6 @@ static enum runloop_state runloop_check_state(
bool rarch_is_initialized = rarch_ctl(RARCH_CTL_IS_INITED, NULL);
bool fs_toggle_triggered = false;
#ifdef HAVE_MENU
menu_animation_ctx_delta_t delta;
bool menu_driver_binding_state = menu_driver_is_binding_state();
bool menu_is_alive = menu_driver_is_alive();
unsigned menu_toggle_gamepad_combo = settings->uints.input_menu_toggle_gamepad_combo;
@ -2920,8 +2919,7 @@ static enum runloop_state runloop_check_state(
}
#if defined(HAVE_MENU)
menu_animation_get_time(&delta);
menu_animation_update(delta.ideal);
menu_animation_update();
if (menu_is_alive)
{