Start cutting down on input_state - move all joypad driver code up to

higher-level retroarch.c
This commit is contained in:
twinaphex 2020-09-02 15:26:03 +02:00
parent f10832b0d3
commit 1c5f4e1dee
25 changed files with 199 additions and 374 deletions

View File

@ -1337,8 +1337,7 @@ static int16_t android_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if (binds[port][i].valid)
@ -1349,18 +1348,11 @@ static int16_t android_input_state(
}
return ret;
}
else
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (
button_is_pressed(
joypad, joypad_info, binds[port],
port, id)
|| ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], id)
)
return 1;
}
if (ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], id))
return 1;
}
break;
case RETRO_DEVICE_ANALOG:

View File

@ -392,13 +392,7 @@ static int16_t cocoa_input_state(
unsigned i;
/* Do a bitwise OR to combine both input
* states together */
int16_t ret = joypad->state(
joypad_info, binds[port], port)
#ifdef HAVE_MFI
| sec_joypad->state(
joypad_info, binds[port], port)
#endif
;
int16_t ret = 0;
if (!keyboard_mapping_blocked)
{
@ -412,24 +406,12 @@ static int16_t cocoa_input_state(
}
return ret;
}
else
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(
joypad,
joypad_info, binds[port], port, id))
if (id < RARCH_BIND_LIST_END)
if (apple_key_state[rarch_keysym_lut[binds[port][id].key]])
return 1;
#ifdef HAVE_MFI
else if (button_is_pressed(
sec_joypad,
joypad_info, binds[port], port, id))
return 1;
#endif
else if (id < RARCH_BIND_LIST_END)
if (apple_key_state[rarch_keysym_lut[binds[port][id].key]])
return 1;
}
}
break;
case RETRO_DEVICE_ANALOG:

View File

@ -47,26 +47,6 @@ static int16_t ctr_input_state(
unsigned idx,
unsigned id)
{
if (port >= MENU_ENUM_LABEL_VALUE_INPUT_MAX_USERS)
return 0;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
if (button_is_pressed(
joypad, joypad_info, binds[port], port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
}
return 0;
}

View File

@ -412,8 +412,7 @@ static int16_t dinput_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
if (settings->uints.input_mouse_index[port] == 0)
{
@ -444,30 +443,24 @@ static int16_t dinput_input_state(
}
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(
joypad,
joypad_info, binds[port], port, id))
return 1;
else if (binds[port][id].key < RETROK_LAST
&& (di->state[rarch_keysym_lut
[(enum retro_key)binds[port][id].key]] & 0x80)
&& ( (id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (
settings->uints.input_mouse_index[port] == 0
&& dinput_mouse_button_pressed(
di, port, binds[port][id].mbutton)
)
return 1;
}
if (binds[port][id].key < RETROK_LAST
&& (di->state[rarch_keysym_lut
[(enum retro_key)binds[port][id].key]] & 0x80)
&& ( (id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (
settings->uints.input_mouse_index[port] == 0
&& dinput_mouse_button_pressed(
di, port, binds[port][id].mbutton)
)
return 1;
}
}
}

View File

@ -75,8 +75,7 @@ static int16_t dos_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -91,20 +90,15 @@ static int16_t dos_input_state(
return ret;
}
else
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (
button_is_pressed(
joypad, joypad_info, binds[port],
port, id)
|| (id < RARCH_BIND_LIST_END
&& dos_key_state[DOS_KEYBOARD_PORT]
[rarch_keysym_lut[binds[port][id].key]])
)
return 1;
}
if (
(id < RARCH_BIND_LIST_END
&& dos_key_state[DOS_KEYBOARD_PORT]
[rarch_keysym_lut[binds[port][id].key]])
)
return 1;
}
break;
case RETRO_DEVICE_KEYBOARD:

View File

@ -78,16 +78,6 @@ static int16_t gx_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
#ifdef HW_RVL

View File

@ -92,8 +92,7 @@ static int16_t linuxraw_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -109,23 +108,15 @@ static int16_t linuxraw_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (
button_is_pressed(
joypad, joypad_info, binds[port],
port, id)
)
return 1;
else if ((linuxraw->state[rarch_keysym_lut
[(enum retro_key)binds[port][id].key]]
))
return 1;
}
if ((linuxraw->state[rarch_keysym_lut
[(enum retro_key)binds[port][id].key]]
))
return 1;
}
}
break;

View File

@ -43,22 +43,6 @@ static int16_t ps2_input_state(
unsigned idx,
unsigned id)
{
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
}
return 0;
}

View File

@ -109,16 +109,6 @@ static int16_t ps3_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
#if 0

View File

@ -49,23 +49,6 @@ static int16_t ps4_input_state(
unsigned idx,
unsigned id)
{
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
}
return 0;
}

View File

@ -234,8 +234,7 @@ static int16_t ps3_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -249,18 +248,12 @@ static int16_t ps3_input_state(
return ret;
}
else
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
else if (psl1ght_keyboard_port_input_pressed(
ps3, binds[port][id].key))
return 1;
}
if (psl1ght_keyboard_port_input_pressed(
ps3, binds[port][id].key))
return 1;
}
break;
case RETRO_DEVICE_ANALOG:

View File

@ -260,16 +260,6 @@ static int16_t psp_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
#ifdef VITA

View File

@ -789,8 +789,7 @@ static int16_t qnx_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
if (!keyboard_mapping_blocked)
{
@ -806,22 +805,17 @@ static int16_t qnx_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad,
joypad_info, binds[port], port, id))
return 1;
else if (
((id == RARCH_GAME_FOCUS_TOGGLE) ||
!keyboard_mapping_blocked) &&
qnx_keyboard_pressed(qnx, key)
)
return 1;
}
if (
((id == RARCH_GAME_FOCUS_TOGGLE) ||
!keyboard_mapping_blocked) &&
qnx_keyboard_pressed(qnx, key)
)
return 1;
}
}
break;

View File

@ -437,6 +437,24 @@ static int16_t rwebinput_is_pressed(
return 0;
}
static int16_t rwebinput_is_pressed_no_joypad(
rwebinput_input_t *rwebinput,
const struct retro_keybind *binds,
unsigned port, unsigned id,
bool keyboard_mapping_blocked)
{
const struct retro_keybind *bind = &binds[id];
int key = bind->key;
if ((key < RETROK_LAST) && rwebinput_key_pressed(rwebinput, key))
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !keyboard_mapping_blocked)
return 1;
if (port == 0 && !!rwebinput_mouse_state(&rwebinput->mouse,
bind->mbutton, false))
return 1;
return 0;
}
static int16_t rwebinput_input_state(
void *data,
const input_device_driver_t *joypad,
@ -462,9 +480,8 @@ static int16_t rwebinput_input_state(
{
if (binds[port][i].valid)
{
if (rwebinput_is_pressed(
rwebinput, joypad,
joypad_info, binds[port], port, i,
if (rwebinput_is_pressed_no_joypad(
rwebinput, binds[port], port, i,
keyboard_mapping_blocked))
ret |= (1 << i);
}
@ -472,18 +489,16 @@ static int16_t rwebinput_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (rwebinput_is_pressed(rwebinput, joypad,
joypad_info, binds[port],
port, id,
keyboard_mapping_blocked))
return 1;
}
if (rwebinput_is_pressed_no_joypad(rwebinput,
binds[port],
port, id,
keyboard_mapping_blocked))
return 1;
}
}
break;

View File

@ -99,8 +99,7 @@ static int16_t sdl_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -111,19 +110,12 @@ static int16_t sdl_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad,
joypad_info, binds[port], port, id))
return 1;
else if (sdl_key_pressed(binds[port][id].key))
return 1;
}
}
if (binds[port][id].valid)
if (sdl_key_pressed(binds[port][id].key))
return 1;
}
break;
case RETRO_DEVICE_ANALOG:

View File

@ -297,16 +297,6 @@ static int16_t switch_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
#ifdef HAVE_LIBNX

View File

@ -1003,8 +1003,7 @@ static int16_t udev_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -1029,26 +1028,21 @@ static int16_t udev_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad,
joypad_info, binds[port], port, id))
return 1;
else if (
(binds[port][id].key < RETROK_LAST) &&
udev_keyboard_pressed(udev, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (udev_mouse_button_pressed(udev, port,
binds[port][id].mbutton))
return 1;
}
if (
(binds[port][id].key < RETROK_LAST) &&
udev_keyboard_pressed(udev, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (udev_mouse_button_pressed(udev, port,
binds[port][id].mbutton))
return 1;
}
}
break;

View File

@ -86,8 +86,7 @@ static int16_t uwp_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
if (!keyboard_mapping_blocked)
{
@ -116,25 +115,20 @@ static int16_t uwp_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad, joypad_info,
binds[port], port, id))
return 1;
else if ((binds[port][id].key < RETROK_LAST)
&& uwp_keyboard_pressed(binds[port][id].key)
&& ((id == RARCH_GAME_FOCUS_TOGGLE) ||
!keyboard_mapping_blocked)
)
return 1;
else if (uwp_mouse_state(port,
binds[port][id].mbutton, false))
return 1;
}
if ((binds[port][id].key < RETROK_LAST)
&& uwp_keyboard_pressed(binds[port][id].key)
&& ((id == RARCH_GAME_FOCUS_TOGGLE) ||
!keyboard_mapping_blocked)
)
return 1;
else if (uwp_mouse_state(port,
binds[port][id].mbutton, false))
return 1;
}
}
break;

View File

@ -167,8 +167,7 @@ static int16_t input_wl_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
@ -182,21 +181,13 @@ static int16_t input_wl_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad,
joypad_info, binds[port],
port, id))
return 1;
else if (BIT_GET(wl->key_state,
rarch_keysym_lut[binds[port][id].key]))
return 1;
}
}
if (binds[port][id].valid)
if (BIT_GET(wl->key_state,
rarch_keysym_lut[binds[port][id].key]))
return 1;
}
break;
case RETRO_DEVICE_ANALOG:

View File

@ -108,21 +108,12 @@ static int16_t wiiu_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
return button_is_pressed(
joypad,
joypad_info, binds[port], port, id);
case RETRO_DEVICE_ANALOG:
break;
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST && keyboard_state[id] && (keyboard_channel > 0))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
/* TODO: Emulate a relative mouse.

View File

@ -624,8 +624,7 @@ static int16_t winraw_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
if (mouse)
{
@ -655,27 +654,21 @@ static int16_t winraw_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(
joypad,
joypad_info, binds[port], port, id))
return 1;
else if (
(binds[port][id].key < RETROK_LAST)
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][id].mbutton))
return 1;
}
if (
(binds[port][id].key < RETROK_LAST)
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][id].mbutton))
return 1;
}
}
break;

View File

@ -127,8 +127,7 @@ static int16_t x_input_state(
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = joypad->state(
joypad_info, binds[port], port);
int16_t ret = 0;
if (settings->uints.input_mouse_index[port] == 0)
{
@ -157,28 +156,23 @@ static int16_t x_input_state(
return ret;
}
else
if (id < RARCH_BIND_LIST_END)
{
if (id < RARCH_BIND_LIST_END)
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (button_is_pressed(joypad,
joypad_info, binds[port], port, id))
return 1;
else if (
((binds[port][id].key < RETROK_LAST) &&
x_keyboard_pressed(x11, binds[port][id].key))
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
if (
((binds[port][id].key < RETROK_LAST) &&
x_keyboard_pressed(x11, binds[port][id].key))
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (settings->uints.input_mouse_index[port] == 0)
{
if (x_mouse_button_pressed(x11, port,
binds[port][id].mbutton))
return 1;
else if (settings->uints.input_mouse_index[port] == 0)
{
if (x_mouse_button_pressed(x11, port,
binds[port][id].mbutton))
return 1;
}
}
}
}

View File

@ -52,26 +52,6 @@ static int16_t xdk_input_state(
unsigned index,
unsigned id)
{
if (port >= DEFAULT_MAX_PADS)
return 0;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
return joypad->state(
joypad_info, binds[port], port);
if (binds[port][id].valid)
if (
button_is_pressed(joypad, joypad_info, binds[port],
port, id))
return 1;
break;
case RETRO_DEVICE_ANALOG:
break;
}
return 0;
}

View File

@ -27,6 +27,8 @@
#include "../input_driver.h"
/* TODO/FIXME - add joypad driver */
/* TODO/FIXME -
* fix game focus toggle */
@ -80,6 +82,7 @@ static int16_t xenon360_input_state(
switch (device)
{
case RETRO_DEVICE_JOYPAD:
#if 0
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
@ -96,14 +99,13 @@ static int16_t xenon360_input_state(
return ret;
}
else
if (binds[port][id].valid)
{
if (binds[port][id].valid)
{
if (state[port] & binds[port][id].joykey)
return 1;
}
if (state[port] & binds[port][id].joykey)
return 1;
}
#endif
break;
default:
break;

View File

@ -3623,7 +3623,40 @@ static int16_t input_state_wrap(
unsigned id)
{
input_driver_t *current_input = p_rarch->current_input;
int16_t ret = current_input->input_state(
int16_t ret = 0;
/* Do a bitwise OR to combine input states together */
if (device == RETRO_DEVICE_JOYPAD)
{
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
ret |= joypad->state(
joypad_info, binds[port], port);
if (sec_joypad)
ret |= sec_joypad->state(
joypad_info, binds[port], port);
}
else
{
/* Do a bitwise OR to combine both input
* states together */
if (binds[port][id].valid)
{
if (button_is_pressed(
joypad,
joypad_info, binds[port], port, id))
return 1;
else if (sec_joypad &&
button_is_pressed(
sec_joypad,
joypad_info, binds[port], port, id))
return 1;
}
}
}
ret |= current_input->input_state(
data,
joypad,
sec_joypad,