(dinput/xinput) Simplifications

This commit is contained in:
twinaphex 2019-06-21 09:00:59 +02:00
parent 2626282757
commit 20e8dfcba5
2 changed files with 66 additions and 61 deletions

View File

@ -217,8 +217,11 @@ static void dinput_poll(void *data)
if (di->mouse) if (di->mouse)
{ {
POINT point;
DIMOUSESTATE2 mouse_state; DIMOUSESTATE2 mouse_state;
POINT point = {0};
point.x = 0;
point.y = 0;
memset(&mouse_state, 0, sizeof(mouse_state)); memset(&mouse_state, 0, sizeof(mouse_state));
@ -257,13 +260,8 @@ static void dinput_poll(void *data)
di->joypad->poll(); di->joypad->poll();
} }
static bool dinput_keyboard_pressed(struct dinput_input *di, unsigned key) static bool dinput_mouse_button_pressed(
{ struct dinput_input *di, unsigned port, unsigned key)
unsigned sym = rarch_keysym_lut[(enum retro_key)key];
return di->state[sym] & 0x80;
}
static bool dinput_mbutton_pressed(struct dinput_input *di, unsigned port, unsigned key)
{ {
bool result; bool result;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -272,45 +270,43 @@ static bool dinput_mbutton_pressed(struct dinput_input *di, unsigned port, unsig
return false; return false;
/* the driver only supports one mouse */ /* the driver only supports one mouse */
if ( settings->uints.input_mouse_index[ port ] != 0 ) { if ( settings->uints.input_mouse_index[ port ] != 0 )
return false; return false;
}
switch ( key ) switch ( key )
{ {
case RETRO_DEVICE_ID_MOUSE_LEFT:
return di->mouse_l;
case RETRO_DEVICE_ID_MOUSE_RIGHT:
return di->mouse_r;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return di->mouse_m;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return di->mouse_b4;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return di->mouse_b5;
case RETRO_DEVICE_ID_MOUSE_LEFT: case RETRO_DEVICE_ID_MOUSE_WHEELUP:
return di->mouse_l; result = di->mouse_wu;
case RETRO_DEVICE_ID_MOUSE_RIGHT: di->mouse_wu = false;
return di->mouse_r; return result;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return di->mouse_m;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return di->mouse_b4;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return di->mouse_b5;
case RETRO_DEVICE_ID_MOUSE_WHEELUP: case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
result = di->mouse_wu; result = di->mouse_wd;
di->mouse_wu = false; di->mouse_wd = false;
return result; return result;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
result = di->mouse_wd; result = di->mouse_hwu;
di->mouse_wd = false; di->mouse_hwu = false;
return result; return result;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
result = di->mouse_hwu; result = di->mouse_hwd;
di->mouse_hwu = false; di->mouse_hwd = false;
return result; return result;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: }
result = di->mouse_hwd;
di->mouse_hwd = false;
return result;
}
return false; return false;
} }
@ -322,13 +318,17 @@ static bool dinput_is_pressed(struct dinput_input *di,
{ {
const struct retro_keybind *bind = &binds[id]; const struct retro_keybind *bind = &binds[id];
if ((bind->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind->key)) if (bind->key < RETROK_LAST)
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked) {
return true; unsigned sym = rarch_keysym_lut[(enum retro_key)bind->key];
if (di->state[sym] & 0x80)
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
return true;
}
if (binds && binds[id].valid) if (binds && binds[id].valid)
{ {
if (dinput_mbutton_pressed(di, port, bind->mbutton)) if (dinput_mouse_button_pressed(di, port, bind->mbutton))
return true; return true;
if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id)) if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id))
return true; return true;
@ -353,10 +353,18 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
if (!bind_minus->valid || !bind_plus->valid) if (!bind_minus->valid || !bind_plus->valid)
return 0; return 0;
if ((bind_minus->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind_minus->key)) if (bind_minus->key < RETROK_LAST)
pressed_minus = -0x7fff; {
if ((bind_plus->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind_plus->key)) unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key];
pressed_plus = 0x7fff; if (di->state[sym] & 0x80)
pressed_minus = -0x7fff;
}
if (bind_plus->key < RETROK_LAST)
{
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_plus->key];
if (di->state[sym] & 0x80)
pressed_plus = 0x7fff;
}
return pressed_plus + pressed_minus; return pressed_plus + pressed_minus;
} }
@ -591,7 +599,10 @@ static int16_t dinput_input_state(void *data,
return dinput_is_pressed(di, joypad_info, binds[port], port, id); return dinput_is_pressed(di, joypad_info, binds[port], port, id);
break; break;
case RETRO_DEVICE_KEYBOARD: case RETRO_DEVICE_KEYBOARD:
return (id < RETROK_LAST) && dinput_keyboard_pressed(di, id); {
unsigned sym = rarch_keysym_lut[(enum retro_key)id];
return (id < RETROK_LAST) && di->state[sym] & 0x80;
}
case RETRO_DEVICE_ANALOG: case RETRO_DEVICE_ANALOG:
if (binds[port]) if (binds[port])
{ {

View File

@ -139,14 +139,11 @@ static XINPUT_VIBRATION g_xinput_rumble_states[4];
static xinput_joypad_state g_xinput_states[4]; static xinput_joypad_state g_xinput_states[4];
static INLINE int pad_index_to_xuser_index(unsigned pad)
{
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
return g_xinput_pad_indexes[pad]; #define pad_index_to_xuser_index(pad) g_xinput_pad_indexes[(pad)]
#else #else
return pad < MAX_PADS && g_xinput_states[pad].connected ? pad : -1; #define pad_index_to_xuser_index(pad) ((pad) < MAX_PADS && g_xinput_states[(pad)].connected ? (pad) : -1)
#endif #endif
}
/* Generic "XInput" instead of "Xbox 360", because there are /* Generic "XInput" instead of "Xbox 360", because there are
* some other non-xbox third party PC controllers. * some other non-xbox third party PC controllers.
@ -445,7 +442,7 @@ static bool xinput_joypad_button(unsigned port_num, uint16_t joykey)
return false; return false;
} }
static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis) static int16_t xinput_joypad_axis(unsigned port_num, uint32_t joyaxis)
{ {
int xuser; int xuser;
int16_t val = 0; int16_t val = 0;
@ -504,13 +501,12 @@ static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
} }
if (is_neg && val > 0) if (is_neg && val > 0)
val = 0; return 0;
else if (is_pos && val < 0) else if (is_pos && val < 0)
val = 0; return 0;
/* Clamp to avoid overflow error. */ /* Clamp to avoid overflow error. */
if (val == -32768) else if (val == -32768)
val = -32767; return -32767;
return val; return val;
} }
@ -546,9 +542,7 @@ static void xinput_joypad_poll(void)
return; return;
} }
else else
{
g_xinput_states[i].connected = new_connected; g_xinput_states[i].connected = new_connected;
}
} }
#endif #endif
} }