Revert "(dinput/xinput) Simplifications"
This reverts commit 20e8dfcba5
.
This commit is contained in:
parent
44eee1cf42
commit
cec67e412e
|
@ -270,10 +270,10 @@ static bool dinput_mouse_button_pressed(
|
||||||
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:
|
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||||
return di->mouse_l;
|
return di->mouse_l;
|
||||||
|
@ -316,28 +316,22 @@ static bool dinput_is_pressed(struct dinput_input *di,
|
||||||
const struct retro_keybind *binds,
|
const struct retro_keybind *binds,
|
||||||
unsigned port, unsigned id)
|
unsigned port, unsigned id)
|
||||||
{
|
{
|
||||||
if (binds[id].key < RETROK_LAST)
|
const struct retro_keybind *bind = &binds[id];
|
||||||
|
|
||||||
|
if (bind->key < RETROK_LAST)
|
||||||
{
|
{
|
||||||
if (di->state[rarch_keysym_lut[(enum retro_key)binds[id].key]] & 0x80)
|
unsigned sym = rarch_keysym_lut[(enum retro_key)bind->key];
|
||||||
|
if (di->state[sym] & 0x80)
|
||||||
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
|
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binds && binds[id].valid)
|
if (binds && binds[id].valid)
|
||||||
{
|
{
|
||||||
/* Auto-binds are per joypad, not per user. */
|
if (dinput_mouse_button_pressed(di, port, bind->mbutton))
|
||||||
const uint16_t joykey = (binds[id].joykey != NO_BTN)
|
return true;
|
||||||
? binds[id].joykey : joypad_info.auto_binds[id].joykey;
|
if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id))
|
||||||
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
|
return true;
|
||||||
? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis;
|
|
||||||
|
|
||||||
if (dinput_mouse_button_pressed(di, port, binds[id].mbutton))
|
|
||||||
return true;
|
|
||||||
if (joykey != NO_BTN
|
|
||||||
&& di->joypad->button(joypad_info.joy_idx, joykey))
|
|
||||||
return true;
|
|
||||||
if (((float)abs(di->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -348,10 +342,8 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
|
||||||
unsigned idx, unsigned id)
|
unsigned idx, unsigned id)
|
||||||
{
|
{
|
||||||
const struct retro_keybind *bind_minus, *bind_plus;
|
const struct retro_keybind *bind_minus, *bind_plus;
|
||||||
int16_t pressed_minus = 0;
|
int16_t pressed_minus = 0, pressed_plus = 0;
|
||||||
int16_t pressed_plus = 0;
|
unsigned id_minus = 0, id_plus = 0;
|
||||||
unsigned id_minus = 0;
|
|
||||||
unsigned id_plus = 0;
|
|
||||||
|
|
||||||
input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus);
|
input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus);
|
||||||
|
|
||||||
|
@ -363,87 +355,84 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
|
||||||
|
|
||||||
if (bind_minus->key < RETROK_LAST)
|
if (bind_minus->key < RETROK_LAST)
|
||||||
{
|
{
|
||||||
if (di->state[rarch_keysym_lut[(enum retro_key)bind_minus->key]] & 0x80)
|
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key];
|
||||||
|
if (di->state[sym] & 0x80)
|
||||||
pressed_minus = -0x7fff;
|
pressed_minus = -0x7fff;
|
||||||
}
|
}
|
||||||
if (bind_plus->key < RETROK_LAST)
|
if (bind_plus->key < RETROK_LAST)
|
||||||
{
|
{
|
||||||
if (di->state[rarch_keysym_lut[(enum retro_key)bind_plus->key]] & 0x80)
|
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_plus->key];
|
||||||
|
if (di->state[sym] & 0x80)
|
||||||
pressed_plus = 0x7fff;
|
pressed_plus = 0x7fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pressed_plus + pressed_minus;
|
return pressed_plus + pressed_minus;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t dinput_lightgun_aiming_state(
|
static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned idx, unsigned id )
|
||||||
struct dinput_input *di, unsigned idx, unsigned id)
|
|
||||||
{
|
{
|
||||||
struct video_viewport vp;
|
const int edge_detect = 32700;
|
||||||
const int edge_detect = 32700;
|
struct video_viewport vp;
|
||||||
bool inside = false;
|
bool inside = false;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int16_t res_x = 0;
|
int16_t res_x = 0;
|
||||||
int16_t res_y = 0;
|
int16_t res_y = 0;
|
||||||
int16_t res_screen_x = 0;
|
int16_t res_screen_x = 0;
|
||||||
int16_t res_screen_y = 0;
|
int16_t res_screen_y = 0;
|
||||||
unsigned num = 0;
|
unsigned num = 0;
|
||||||
struct pointer_status* check_pos = di->pointer_head.next;
|
|
||||||
|
|
||||||
vp.x = 0;
|
struct pointer_status* check_pos = di->pointer_head.next;
|
||||||
vp.y = 0;
|
|
||||||
vp.width = 0;
|
|
||||||
vp.height = 0;
|
|
||||||
vp.full_width = 0;
|
|
||||||
vp.full_height = 0;
|
|
||||||
|
|
||||||
while (check_pos && num < idx)
|
vp.x = 0;
|
||||||
{
|
vp.y = 0;
|
||||||
num++;
|
vp.width = 0;
|
||||||
check_pos = check_pos->next;
|
vp.height = 0;
|
||||||
}
|
vp.full_width = 0;
|
||||||
|
vp.full_height = 0;
|
||||||
|
|
||||||
if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */
|
while ( check_pos && num < idx )
|
||||||
return 0;
|
{
|
||||||
|
num++;
|
||||||
|
check_pos = check_pos->next;
|
||||||
|
}
|
||||||
|
|
||||||
x = di->mouse_x;
|
if ( !check_pos && idx > 0 ) /* idx = 0 has mouse fallback. */
|
||||||
y = di->mouse_y;
|
return 0;
|
||||||
|
|
||||||
if (check_pos)
|
x = di->mouse_x;
|
||||||
{
|
y = di->mouse_y;
|
||||||
x = check_pos->pointer_x;
|
|
||||||
y = check_pos->pointer_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(video_driver_translate_coord_viewport_wrap(
|
if ( check_pos )
|
||||||
&vp, x, y, &res_x, &res_y, &res_screen_x, &res_screen_y)))
|
{
|
||||||
{
|
x = check_pos->pointer_x;
|
||||||
return 0;
|
y = check_pos->pointer_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
inside =
|
if ( !( video_driver_translate_coord_viewport_wrap(
|
||||||
(res_x >= -edge_detect)
|
&vp, x, y, &res_x, &res_y, &res_screen_x, &res_screen_y ) ) )
|
||||||
&& (res_y >= -edge_detect)
|
{
|
||||||
&& (res_x <= edge_detect)
|
return 0;
|
||||||
&& (res_y <= edge_detect);
|
}
|
||||||
|
|
||||||
switch (id)
|
inside = (res_x >= -edge_detect) && (res_y >= -edge_detect) && (res_x <= edge_detect) && (res_y <= edge_detect);
|
||||||
{
|
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
|
||||||
return inside ? res_x : 0;
|
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
|
||||||
return inside ? res_y : 0;
|
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
|
||||||
return !inside;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
switch ( id )
|
||||||
|
{
|
||||||
|
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||||
|
return inside ? res_x : 0;
|
||||||
|
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||||
|
return inside ? res_y : 0;
|
||||||
|
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||||
|
return !inside;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t dinput_mouse_state(struct dinput_input *di,
|
static int16_t dinput_mouse_state(struct dinput_input *di, unsigned port, unsigned id)
|
||||||
unsigned port, unsigned id)
|
|
||||||
{
|
{
|
||||||
int16_t state = 0;
|
int16_t state = 0;
|
||||||
|
|
||||||
|
@ -453,8 +442,9 @@ static int16_t dinput_mouse_state(struct dinput_input *di,
|
||||||
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 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
|
@ -497,8 +487,7 @@ static int16_t dinput_mouse_state(struct dinput_input *di,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t dinput_mouse_state_screen(
|
static int16_t dinput_mouse_state_screen(struct dinput_input *di, unsigned port, unsigned id)
|
||||||
struct dinput_input *di, unsigned port, unsigned id)
|
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
|
@ -506,8 +495,9 @@ static int16_t dinput_mouse_state_screen(
|
||||||
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 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
|
@ -599,31 +589,20 @@ static int16_t dinput_input_state(void *data,
|
||||||
const struct retro_keybind **binds, unsigned port,
|
const struct retro_keybind **binds, unsigned port,
|
||||||
unsigned device, unsigned idx, unsigned id)
|
unsigned device, unsigned idx, unsigned id)
|
||||||
{
|
{
|
||||||
int16_t ret = 0;
|
int16_t ret;
|
||||||
struct dinput_input *di = (struct dinput_input*)data;
|
struct dinput_input *di = (struct dinput_input*)data;
|
||||||
|
|
||||||
switch (device)
|
switch (device)
|
||||||
{
|
{
|
||||||
case RETRO_DEVICE_JOYPAD:
|
case RETRO_DEVICE_JOYPAD:
|
||||||
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
|
if (id < RARCH_BIND_LIST_END)
|
||||||
{
|
return dinput_is_pressed(di, joypad_info, binds[port], port, id);
|
||||||
unsigned i;
|
break;
|
||||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
|
||||||
{
|
|
||||||
if (dinput_is_pressed(di, joypad_info, binds[port], port,
|
|
||||||
i))
|
|
||||||
ret |= (1 << i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (id < RARCH_BIND_LIST_END)
|
|
||||||
ret = dinput_is_pressed(di, joypad_info, binds[port], port, id);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
case RETRO_DEVICE_KEYBOARD:
|
case RETRO_DEVICE_KEYBOARD:
|
||||||
return (id < RETROK_LAST) && di->state[
|
{
|
||||||
rarch_keysym_lut[(enum retro_key)id]] & 0x80;
|
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])
|
||||||
{
|
{
|
||||||
|
@ -647,13 +626,14 @@ static int16_t dinput_input_state(void *data,
|
||||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||||
|
|
||||||
case RETRO_DEVICE_LIGHTGUN:
|
case RETRO_DEVICE_LIGHTGUN:
|
||||||
switch (id)
|
switch ( id )
|
||||||
{
|
{
|
||||||
/*aiming*/
|
/*aiming*/
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||||
return dinput_lightgun_aiming_state(di, idx, id);
|
return dinput_lightgun_aiming_state( di, idx, id );
|
||||||
|
|
||||||
/*buttons*/
|
/*buttons*/
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||||
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
|
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
|
||||||
|
@ -712,13 +692,13 @@ static int16_t dinput_input_state(void *data,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Stores x/y in client coordinates. */
|
/* Stores x/y in client coordinates. */
|
||||||
static void dinput_pointer_store_position(
|
static void dinput_pointer_store_pos(
|
||||||
struct pointer_status *pointer, WPARAM lParam)
|
struct pointer_status *pointer, WPARAM lParam)
|
||||||
{
|
{
|
||||||
POINT point;
|
POINT point;
|
||||||
|
|
||||||
point.x = GET_X_LPARAM(lParam);
|
point.x = GET_X_LPARAM(lParam);
|
||||||
point.y = GET_Y_LPARAM(lParam);
|
point.y = GET_Y_LPARAM(lParam);
|
||||||
ScreenToClient((HWND)video_driver_window_get(), &point);
|
ScreenToClient((HWND)video_driver_window_get(), &point);
|
||||||
pointer->pointer_x = point.x;
|
pointer->pointer_x = point.x;
|
||||||
pointer->pointer_y = point.y;
|
pointer->pointer_y = point.y;
|
||||||
|
@ -811,7 +791,7 @@ bool dinput_handle_message(void *data, UINT message, WPARAM wParam, LPARAM lPara
|
||||||
}
|
}
|
||||||
|
|
||||||
new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam);
|
new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam);
|
||||||
dinput_pointer_store_position(new_pointer, lParam);
|
dinput_pointer_store_pos(new_pointer, lParam);
|
||||||
dinput_add_pointer(di, new_pointer);
|
dinput_add_pointer(di, new_pointer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -826,7 +806,7 @@ bool dinput_handle_message(void *data, UINT message, WPARAM wParam, LPARAM lPara
|
||||||
int pointer_id = GET_POINTERID_WPARAM(wParam);
|
int pointer_id = GET_POINTERID_WPARAM(wParam);
|
||||||
struct pointer_status *pointer = dinput_find_pointer(di, pointer_id);
|
struct pointer_status *pointer = dinput_find_pointer(di, pointer_id);
|
||||||
if (pointer)
|
if (pointer)
|
||||||
dinput_pointer_store_position(pointer, lParam);
|
dinput_pointer_store_pos(pointer, lParam);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case WM_DEVICECHANGE:
|
case WM_DEVICECHANGE:
|
||||||
|
|
|
@ -139,11 +139,14 @@ 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
|
||||||
#define pad_index_to_xuser_index(pad) g_xinput_pad_indexes[(pad)]
|
return g_xinput_pad_indexes[pad];
|
||||||
#else
|
#else
|
||||||
#define pad_index_to_xuser_index(pad) ((pad) < MAX_PADS && g_xinput_states[(pad)].connected ? (pad) : -1)
|
return 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.
|
||||||
|
@ -449,7 +452,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;
|
||||||
|
@ -508,12 +511,13 @@ static int16_t xinput_joypad_axis(unsigned port_num, uint32_t joyaxis)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_neg && val > 0)
|
if (is_neg && val > 0)
|
||||||
return 0;
|
val = 0;
|
||||||
else if (is_pos && val < 0)
|
else if (is_pos && val < 0)
|
||||||
return 0;
|
val = 0;
|
||||||
|
|
||||||
/* Clamp to avoid overflow error. */
|
/* Clamp to avoid overflow error. */
|
||||||
else if (val == -32768)
|
if (val == -32768)
|
||||||
return -32767;
|
val = -32767;
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +553,9 @@ 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue