(dinput.c) Cleanups

This commit is contained in:
twinaphex 2019-06-23 03:14:21 +02:00
parent 51365ed387
commit d4ed0358a7

View File

@ -316,19 +316,16 @@ static bool dinput_is_pressed(struct dinput_input *di,
const struct retro_keybind *binds,
unsigned port, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
if (bind->key < RETROK_LAST)
if (binds[id].key < RETROK_LAST)
{
unsigned sym = rarch_keysym_lut[(enum retro_key)bind->key];
if (di->state[sym] & 0x80)
if (di->state[rarch_keysym_lut[(enum retro_key)binds[id].key]] & 0x80)
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
return true;
}
if (binds && binds[id].valid)
{
if (dinput_mouse_button_pressed(di, port, bind->mbutton))
if (dinput_mouse_button_pressed(di, port, binds[id].mbutton))
return true;
if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id))
return true;
@ -342,8 +339,10 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
unsigned idx, unsigned id)
{
const struct retro_keybind *bind_minus, *bind_plus;
int16_t pressed_minus = 0, pressed_plus = 0;
unsigned id_minus = 0, id_plus = 0;
int16_t pressed_minus = 0;
int16_t pressed_plus = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus);
@ -355,24 +354,23 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
if (bind_minus->key < RETROK_LAST)
{
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key];
if (di->state[sym] & 0x80)
if (di->state[rarch_keysym_lut[(enum retro_key)bind_minus->key]] & 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)
if (di->state[rarch_keysym_lut[(enum retro_key)bind_plus->key]] & 0x80)
pressed_plus = 0x7fff;
}
return pressed_plus + pressed_minus;
}
static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned idx, unsigned id )
static int16_t dinput_lightgun_aiming_state(
struct dinput_input *di, unsigned idx, unsigned id)
{
const int edge_detect = 32700;
struct video_viewport vp;
const int edge_detect = 32700;
bool inside = false;
int x = 0;
int y = 0;
@ -381,7 +379,6 @@ static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned i
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;
unsigned num = 0;
struct pointer_status* check_pos = di->pointer_head.next;
vp.x = 0;
@ -415,7 +412,11 @@ static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned i
return 0;
}
inside = (res_x >= -edge_detect) && (res_y >= -edge_detect) && (res_x <= edge_detect) && (res_y <= edge_detect);
inside =
(res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch (id)
{
@ -432,7 +433,8 @@ static int16_t dinput_lightgun_aiming_state( struct dinput_input *di, unsigned i
return 0;
}
static int16_t dinput_mouse_state(struct dinput_input *di, unsigned port, unsigned id)
static int16_t dinput_mouse_state(struct dinput_input *di,
unsigned port, unsigned id)
{
int16_t state = 0;
@ -442,9 +444,8 @@ static int16_t dinput_mouse_state(struct dinput_input *di, unsigned port, unsign
return false;
/* the driver only supports one mouse */
if ( settings->uints.input_mouse_index[ port ] != 0 ) {
if (settings->uints.input_mouse_index[ port ] != 0)
return 0;
}
switch (id)
{
@ -487,7 +488,8 @@ static int16_t dinput_mouse_state(struct dinput_input *di, unsigned port, unsign
return 0;
}
static int16_t dinput_mouse_state_screen(struct dinput_input *di, unsigned port, unsigned id)
static int16_t dinput_mouse_state_screen(
struct dinput_input *di, unsigned port, unsigned id)
{
settings_t *settings = config_get_ptr();
@ -495,9 +497,8 @@ static int16_t dinput_mouse_state_screen(struct dinput_input *di, unsigned port,
return false;
/* the driver only supports one mouse */
if ( settings->uints.input_mouse_index[ port ] != 0 ) {
if (settings->uints.input_mouse_index[ port ] != 0)
return 0;
}
switch (id)
{
@ -599,10 +600,8 @@ static int16_t dinput_input_state(void *data,
return dinput_is_pressed(di, joypad_info, binds[port], port, id);
break;
case RETRO_DEVICE_KEYBOARD:
{
unsigned sym = rarch_keysym_lut[(enum retro_key)id];
return (id < RETROK_LAST) && di->state[sym] & 0x80;
}
return (id < RETROK_LAST) && di->state[
rarch_keysym_lut[(enum retro_key)id]] & 0x80;
case RETRO_DEVICE_ANALOG:
if (binds[port])
{
@ -633,7 +632,6 @@ static int16_t dinput_input_state(void *data,
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return dinput_lightgun_aiming_state(di, idx, id);
/*buttons*/
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return dinput_is_pressed(di, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
@ -692,7 +690,7 @@ static int16_t dinput_input_state(void *data,
#endif
/* Stores x/y in client coordinates. */
static void dinput_pointer_store_pos(
static void dinput_pointer_store_position(
struct pointer_status *pointer, WPARAM lParam)
{
POINT point;
@ -791,7 +789,7 @@ bool dinput_handle_message(void *data, UINT message, WPARAM wParam, LPARAM lPara
}
new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam);
dinput_pointer_store_pos(new_pointer, lParam);
dinput_pointer_store_position(new_pointer, lParam);
dinput_add_pointer(di, new_pointer);
return true;
}
@ -806,7 +804,7 @@ bool dinput_handle_message(void *data, UINT message, WPARAM wParam, LPARAM lPara
int pointer_id = GET_POINTERID_WPARAM(wParam);
struct pointer_status *pointer = dinput_find_pointer(di, pointer_id);
if (pointer)
dinput_pointer_store_pos(pointer, lParam);
dinput_pointer_store_position(pointer, lParam);
return true;
}
case WM_DEVICECHANGE: