From bca73b0a469756169cb49b2e4e30a5e930786f1c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Mar 2021 05:47:30 +0100 Subject: [PATCH] Create specialized versions of input_state_mask --- retroarch.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/retroarch.c b/retroarch.c index 22a0c8860d..38282c81c8 100644 --- a/retroarch.c +++ b/retroarch.c @@ -436,6 +436,86 @@ void *video_driver_get_ptr(bool force_nonthreaded_data) return VIDEO_DRIVER_GET_PTR_INTERNAL(p_rarch, force_nonthreaded_data); } +static int16_t input_state_joypad( + input_driver_t *current_input, + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) +{ + if (binds[port][id].valid) + { + if (button_is_pressed( + joypad, + joypad_info, binds[port], port, id)) + return 1; +#ifdef HAVE_MFI + else if (sec_joypad && + button_is_pressed( + sec_joypad, + joypad_info, binds[port], port, id)) + return 1; +#endif + } + + if (current_input->input_state) + return current_input->input_state( + data, + joypad, + sec_joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, + device, + idx, + id); + return 0; +} + +static int16_t input_state_joypad_mask( + input_driver_t *current_input, + void *data, + const input_device_driver_t *joypad, + const input_device_driver_t *sec_joypad, + rarch_joypad_info_t *joypad_info, + const struct retro_keybind **binds, + bool keyboard_mapping_blocked, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) +{ + /* Do a bitwise OR to combine input states together */ + int16_t ret = joypad->state( + joypad_info, binds[port], port); +#ifdef HAVE_MFI + if (sec_joypad) + ret |= sec_joypad->state( + joypad_info, binds[port], port); +#endif + + if (current_input->input_state) + ret |= current_input->input_state( + data, + joypad, + sec_joypad, + joypad_info, + binds, + keyboard_mapping_blocked, + port, + device, + idx, + id); + return ret; +} + static int16_t input_state_wrap( input_driver_t *current_input, void *data, @@ -22330,7 +22410,7 @@ static void input_driver_poll(void) joypad_info[i].auto_binds = input_autoconf_binds[joypad_info[i].joy_idx]; if (p_rarch->libretro_input_binds[i][RARCH_TURBO_ENABLE].valid) p_rarch->input_driver_turbo_btns.frame_enable[i] = - input_state_wrap( + input_state_joypad( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad, @@ -22384,7 +22464,7 @@ static void input_driver_poll(void) if (joypad_driver) { unsigned k, j; - int16_t ret = input_state_wrap( + int16_t ret = input_state_joypad_mask( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad, @@ -24747,7 +24827,7 @@ static void input_keys_pressed( if (CHECK_INPUT_DRIVER_BLOCK_HOTKEY(binds_norm, binds_auto)) { - if ( input_state_wrap( + if ( input_state_joypad( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad, @@ -24783,7 +24863,7 @@ static void input_keys_pressed( if (CHECK_INPUT_DRIVER_BLOCK_HOTKEY( focus_normal, focus_binds_auto)) { - if (input_state_wrap( + if (input_state_joypad( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad, @@ -24811,7 +24891,7 @@ static void input_keys_pressed( } else { - int16_t ret = input_state_wrap( + int16_t ret = input_state_joypad_mask( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad, @@ -24851,7 +24931,7 @@ static void input_keys_pressed( for (i = RARCH_FIRST_META_KEY; i < RARCH_BIND_LIST_END; i++) { bool bit_pressed = binds[port][i].valid - && input_state_wrap( + && input_state_joypad( p_rarch->current_input, p_rarch->current_input_data, p_rarch->joypad,