From 2886932968bd9be2d6ee7328ef4ca1e40d1c9ae6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 8 Nov 2021 20:04:55 +0100 Subject: [PATCH] Move menu global state code from global_t to menu_st --- menu/menu_driver.h | 8 ++++++ menu/menu_setting.c | 42 ++++++++++++--------------- retroarch.c | 70 +++++++++++++++++++++------------------------ retroarch_types.h | 13 --------- 4 files changed, 60 insertions(+), 73 deletions(-) diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 1067ee7b7c..896bbd0b50 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -433,6 +433,12 @@ struct menu_state retro_time_t input_last_time_us; menu_input_t input_state; /* retro_time_t alignment */ + retro_time_t prev_start_time; + retro_time_t noop_press_time; + retro_time_t noop_start_time; + retro_time_t action_start_time; + retro_time_t action_press_time; + struct menu_bind_state input_binds; /* uint64_t alignment */ menu_handle_t *driver_data; @@ -466,6 +472,8 @@ struct menu_state /* int16_t alignment */ menu_input_pointer_hw_state_t input_pointer_hw_state; + enum menu_action prev_action; + /* When generating a menu list in menu_displaylist_build_list(), * the entry with a label matching 'pending_selection' will * be selected automatically */ diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 880ff10690..1eee1503b1 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -727,29 +727,25 @@ static void setting_get_string_representation_uint_as_enum( static float recalc_step_based_on_length_of_action(rarch_setting_t *setting) { - float step = setting->step; - global_t *global = global_get_ptr(); - - if (global) - { - retro_time_t action_press_time = global->menu.action_press_time; - if (action_press_time > _21_SECONDS) - step = setting->step * 1000000.0f; - else if (action_press_time > _18_SECONDS) - step = setting->step * 100000.0f; - else if (action_press_time > _15_SECONDS) - step = setting->step * 10000.0f; - else if (action_press_time > _12_SECONDS) - step = setting->step * 1000.0f; - else if (action_press_time > _9_SECONDS) - step = setting->step * 100.0f; - else if (action_press_time > _6_SECONDS) - step = setting->step * 10.0f; - else if (action_press_time > _3_SECONDS) - step = setting->step * 5.0f; - else - step = setting->step; - } + float step = setting->step; + struct menu_state *menu_st = menu_state_get_ptr(); + retro_time_t action_press_time = menu_st->action_press_time; + if (action_press_time > _21_SECONDS) + step = setting->step * 1000000.0f; + else if (action_press_time > _18_SECONDS) + step = setting->step * 100000.0f; + else if (action_press_time > _15_SECONDS) + step = setting->step * 10000.0f; + else if (action_press_time > _12_SECONDS) + step = setting->step * 1000.0f; + else if (action_press_time > _9_SECONDS) + step = setting->step * 100.0f; + else if (action_press_time > _6_SECONDS) + step = setting->step * 10.0f; + else if (action_press_time > _3_SECONDS) + step = setting->step * 5.0f; + else + step = setting->step; return step < setting->step ? setting->step : step; } diff --git a/retroarch.c b/retroarch.c index a096f0d5ba..de12373a9b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -14829,7 +14829,6 @@ static enum runloop_state_enum runloop_check_state( struct menu_state *menu_st = menu_state_get_ptr(); bool focused = false; input_bits_t trigger_input = current_bits; - global_t *global = global_get_ptr(); unsigned screensaver_timeout = settings->uints.menu_screensaver_timeout; /* Get current time */ @@ -14846,45 +14845,42 @@ static enum runloop_state_enum runloop_check_state( focused = focused && !p_rarch->main_ui_companion_is_on_foreground; - if (global) + if (action == old_action) { - if (action == old_action) - { - retro_time_t press_time = current_time; + retro_time_t press_time = current_time; - if (action == MENU_ACTION_NOOP) - global->menu.noop_press_time = press_time - global->menu.noop_start_time; - else - global->menu.action_press_time = press_time - global->menu.action_start_time; - } - else - { - if (action == MENU_ACTION_NOOP) - { - global->menu.noop_start_time = current_time; - global->menu.noop_press_time = 0; + if (action == MENU_ACTION_NOOP) + menu_st->noop_press_time = press_time - menu_st->noop_start_time; + else + menu_st->action_press_time = press_time - menu_st->action_start_time; + } + else + { + if (action == MENU_ACTION_NOOP) + { + menu_st->noop_start_time = current_time; + menu_st->noop_press_time = 0; - if (global->menu_prev_action == old_action) - global->menu.action_start_time = global->menu.prev_start_time; - else - global->menu.action_start_time = current_time; - } - else - { - if ( global->menu_prev_action == action && - global->menu.noop_press_time < 200000) /* 250ms */ - { - global->menu.action_start_time = global->menu.prev_start_time; - global->menu.action_press_time = current_time - global->menu.action_start_time; - } - else - { - global->menu.prev_start_time = current_time; - global->menu_prev_action = action; - global->menu.action_press_time = 0; - } - } - } + if (menu_st->prev_action == old_action) + menu_st->action_start_time = menu_st->prev_start_time; + else + menu_st->action_start_time = current_time; + } + else + { + if ( menu_st->prev_action == action && + menu_st->noop_press_time < 200000) /* 250ms */ + { + menu_st->action_start_time = menu_st->prev_start_time; + menu_st->action_press_time = current_time - menu_st->action_start_time; + } + else + { + menu_st->prev_start_time = current_time; + menu_st->prev_action = action; + menu_st->action_press_time = 0; + } + } } /* Check whether menu screensaver should be enabled */ diff --git a/retroarch_types.h b/retroarch_types.h index b98cf8be0d..6b14156ca1 100644 --- a/retroarch_types.h +++ b/retroarch_types.h @@ -332,16 +332,6 @@ typedef struct rarch_resolution typedef struct global { -#ifdef HAVE_MENU - struct - { - retro_time_t prev_start_time; - retro_time_t noop_press_time; - retro_time_t noop_start_time; - retro_time_t action_start_time; - retro_time_t action_press_time; - } menu; -#endif struct { char *remapfile; @@ -399,9 +389,6 @@ typedef struct global bool old_libretro_device_set; bool remapping_cache_active; /* Settings and/or global states specific to menus */ -#ifdef HAVE_MENU - enum menu_action menu_prev_action; -#endif bool launched_from_cli; bool cli_load_menu_on_error; } global_t;