Refactor input_keys_pressed

This commit is contained in:
twinaphex 2020-02-27 08:08:38 +01:00
parent 26b3ccf2e5
commit fb223ac377

View File

@ -15928,10 +15928,10 @@ void menu_input_post_iterate(int *ret, unsigned action)
* Returns: Input sample containing a mask of all pressed keys.
*/
static void input_menu_keys_pressed(input_bits_t *p_new_state,
rarch_joypad_info_t *joypad_info,
bool display_kb)
{
unsigned i, port;
rarch_joypad_info_t joypad_info;
const struct retro_keybind *binds[MAX_USERS] = {NULL};
settings_t *settings = configuration_settings;
uint8_t max_users = (uint8_t)input_driver_max_users;
@ -15939,9 +15939,6 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
settings->bools.input_all_users_control_menu
? max_users : 1;
joypad_info.joy_idx = 0;
joypad_info.auto_binds = NULL;
for (i = 0; i < max_users; i++)
{
struct retro_keybind *auto_binds = input_autoconf_binds[i];
@ -15957,16 +15954,16 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
const struct retro_keybind *binds_norm = &input_config_binds[port][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *binds_auto = &input_autoconf_binds[port][RARCH_ENABLE_HOTKEY];
joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
joypad_info.axis_threshold = input_driver_axis_threshold;
joypad_info->joy_idx = settings->uints.input_joypad_map[port];
joypad_info->auto_binds = input_autoconf_binds[joypad_info->joy_idx];
joypad_info->axis_threshold = input_driver_axis_threshold;
if (check_input_driver_block_hotkey(binds_norm, binds_auto))
{
const struct retro_keybind *htkey = &input_config_binds[port][RARCH_ENABLE_HOTKEY];
if (htkey->valid
&& current_input->input_state(current_input_data, &joypad_info,
&& current_input->input_state(current_input_data, joypad_info,
&binds[0], port, RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY))
{
input_driver_block_libretro_input = true;
@ -15985,11 +15982,11 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
/* Check the libretro input first */
for (port = 0; port < port_max; port++)
{
joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
joypad_info.axis_threshold = input_driver_axis_threshold;
joypad_info->joy_idx = settings->uints.input_joypad_map[port];
joypad_info->auto_binds = input_autoconf_binds[joypad_info->joy_idx];
joypad_info->axis_threshold = input_driver_axis_threshold;
ret[port] = current_input->input_state(current_input_data,
&joypad_info, &binds[0], port, RETRO_DEVICE_JOYPAD, 0,
joypad_info, &binds[0], port, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_MASK);
}
@ -16027,11 +16024,11 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
const struct retro_keybind *mtkey = &input_config_binds[port][i];
if (!mtkey->valid)
continue;
joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
joypad_info.axis_threshold = input_driver_axis_threshold;
joypad_info->joy_idx = settings->uints.input_joypad_map[port];
joypad_info->auto_binds = input_autoconf_binds[joypad_info->joy_idx];
joypad_info->axis_threshold = input_driver_axis_threshold;
if (current_input->input_state(current_input_data, &joypad_info,
if (current_input->input_state(current_input_data, joypad_info,
&binds[0], port, RETRO_DEVICE_JOYPAD, 0, i))
{
bit_pressed = true;
@ -16097,7 +16094,7 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
for (i = 0; i < ARRAY_SIZE(ids); i++)
{
if (current_input->input_state(current_input_data,
&joypad_info, binds, 0,
joypad_info, binds, 0,
RETRO_DEVICE_KEYBOARD, 0, ids[i][0]))
BIT256_SET_PTR(p_new_state, ids[i][1]);
}
@ -16112,63 +16109,58 @@ static void input_menu_keys_pressed(input_bits_t *p_new_state,
*
* Returns: Input sample containing a mask of all pressed keys.
*/
static void input_keys_pressed(input_bits_t *p_new_state)
static void input_keys_pressed(input_bits_t *p_new_state,
rarch_joypad_info_t *joypad_info)
{
rarch_joypad_info_t joypad_info;
unsigned i, port = 0;
settings_t *settings = configuration_settings;
const struct retro_keybind *binds = input_config_binds[0];
unsigned i, port = 0;
settings_t *settings = configuration_settings;
const struct retro_keybind *binds = input_config_binds[0];
const struct retro_keybind *binds_norm = &input_config_binds[port][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *binds_auto = &input_autoconf_binds[port][RARCH_ENABLE_HOTKEY];
joypad_info.joy_idx = 0;
joypad_info.auto_binds = NULL;
joypad_info->joy_idx = settings->uints.input_joypad_map[port];
joypad_info->auto_binds = input_autoconf_binds[joypad_info->joy_idx];
joypad_info->axis_threshold = input_driver_axis_threshold;
if (check_input_driver_block_hotkey(binds_norm, binds_auto))
{
const struct retro_keybind *binds_norm = &input_config_binds[port][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *binds_auto = &input_autoconf_binds[port][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *enable_hotkey =
&input_config_binds[port][RARCH_ENABLE_HOTKEY];
joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
joypad_info.axis_threshold = input_driver_axis_threshold;
if ( enable_hotkey && enable_hotkey->valid
&& current_input->input_state(
current_input_data, joypad_info,
&binds, port,
RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY))
input_driver_block_libretro_input = true;
else
input_driver_block_hotkey = true;
}
if (check_input_driver_block_hotkey(binds_norm, binds_auto))
if (binds[RARCH_GAME_FOCUS_TOGGLE].valid)
{
const struct retro_keybind *focus_binds_auto =
&input_autoconf_binds[port][RARCH_GAME_FOCUS_TOGGLE];
const struct retro_keybind *focus_normal =
&binds[RARCH_GAME_FOCUS_TOGGLE];
/* Allows rarch_focus_toggle hotkey to still work
* even though every hotkey is blocked */
if (check_input_driver_block_hotkey(
focus_normal, focus_binds_auto))
{
const struct retro_keybind *enable_hotkey =
&input_config_binds[port][RARCH_ENABLE_HOTKEY];
if ( enable_hotkey && enable_hotkey->valid
&& current_input->input_state(
current_input_data, &joypad_info,
if (current_input->input_state(current_input_data,
joypad_info,
&binds, port,
RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY))
input_driver_block_libretro_input = true;
else
input_driver_block_hotkey = true;
}
if (binds[RARCH_GAME_FOCUS_TOGGLE].valid)
{
const struct retro_keybind *focus_binds_auto =
&input_autoconf_binds[port][RARCH_GAME_FOCUS_TOGGLE];
const struct retro_keybind *focus_normal =
&binds[RARCH_GAME_FOCUS_TOGGLE];
/* Allows rarch_focus_toggle hotkey to still work
* even though every hotkey is blocked */
if (check_input_driver_block_hotkey(
focus_normal, focus_binds_auto))
{
if (current_input->input_state(current_input_data, &joypad_info,
&binds, port,
RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE))
input_driver_block_hotkey = false;
}
RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE))
input_driver_block_hotkey = false;
}
}
/* Check the libretro input first */
{
int16_t ret = current_input->input_state(current_input_data,
&joypad_info, &binds, 0, RETRO_DEVICE_JOYPAD, 0,
joypad_info, &binds, 0, RETRO_DEVICE_JOYPAD, 0,
RETRO_DEVICE_ID_JOYPAD_MASK);
for (i = 0; i < RARCH_FIRST_META_KEY; i++)
{
@ -16185,7 +16177,7 @@ static void input_keys_pressed(input_bits_t *p_new_state)
for (i = RARCH_FIRST_META_KEY; i < RARCH_BIND_LIST_END; i++)
{
bool bit_pressed = !input_driver_block_hotkey && binds[i].valid
&& current_input->input_state(current_input_data, &joypad_info,
&& current_input->input_state(current_input_data, joypad_info,
&binds, 0, RETRO_DEVICE_JOYPAD, 0, i);
if ( bit_pressed
|| BIT64_GET(lifecycle_state, i)
@ -27211,6 +27203,7 @@ static void update_fastforwarding_state(void)
static enum runloop_state runloop_check_state(retro_time_t current_time)
{
input_bits_t current_bits;
rarch_joypad_info_t joypad_info;
#ifdef HAVE_MENU
static input_bits_t last_input = {{0}};
#endif
@ -27252,12 +27245,15 @@ static enum runloop_state runloop_check_state(retro_time_t current_time)
if (current_input->keyboard_mapping_blocked)
input_driver_block_hotkey = true;
joypad_info.joy_idx = 0;
joypad_info.auto_binds = NULL;
#ifdef HAVE_MENU
if (menu_is_alive && !(settings->bools.menu_unified_controls && !display_kb))
input_menu_keys_pressed(&current_bits, display_kb);
input_menu_keys_pressed(&current_bits, &joypad_info, display_kb);
else
#endif
input_keys_pressed(&current_bits);
input_keys_pressed(&current_bits, &joypad_info);
#ifdef HAVE_MENU
last_input = current_bits;