mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
(Dinput) Optimizations - create dinput_is_pressed
This commit is contained in:
parent
a14d54b3fd
commit
479a3ab9a3
@ -526,6 +526,35 @@ static int16_t dinput_pointer_state(struct dinput_input *di,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool dinput_is_pressed(struct dinput_input *di,
|
||||
settings_t *settings,
|
||||
rarch_joypad_info_t *joypad_info,
|
||||
const struct retro_keybind *binds,
|
||||
unsigned port, unsigned id)
|
||||
{
|
||||
const struct retro_keybind *bind = &binds[id];
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const uint64_t joykey = (binds[id].joykey != NO_BTN)
|
||||
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
|
||||
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
|
||||
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
|
||||
|
||||
if (settings->uints.input_mouse_index[port] == 0)
|
||||
if (dinput_mouse_button_pressed(
|
||||
di, port, binds[id].mbutton))
|
||||
return true;
|
||||
|
||||
if ((uint16_t)joykey != NO_BTN
|
||||
&& di->joypad->button(
|
||||
joypad_info->joy_idx, (uint16_t)joykey))
|
||||
return true;
|
||||
|
||||
if (((float)abs(di->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int16_t dinput_input_state(void *data,
|
||||
rarch_joypad_info_t *joypad_info,
|
||||
const struct retro_keybind **binds, unsigned port,
|
||||
@ -547,47 +576,37 @@ static int16_t dinput_input_state(void *data,
|
||||
{
|
||||
unsigned i;
|
||||
int16_t ret = 0;
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
if (input_dinput.keyboard_mapping_blocked)
|
||||
{
|
||||
if (binds[port][i].key < RETROK_LAST)
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
{
|
||||
if (di->state[rarch_keysym_lut[(enum retro_key)binds[port][i].key]] & 0x80)
|
||||
if ((i == RARCH_GAME_FOCUS_TOGGLE) || !input_dinput.keyboard_mapping_blocked)
|
||||
if (binds[port][i].valid)
|
||||
if (dinput_is_pressed(
|
||||
di, settings, joypad_info, binds[port], port, i))
|
||||
{
|
||||
ret |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (binds[port][i].valid)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
{
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const uint64_t joykey = (binds[port][i].joykey != NO_BTN)
|
||||
? binds[port][i].joykey : joypad_info->auto_binds[i].joykey;
|
||||
const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE)
|
||||
? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis;
|
||||
if ((binds[port][i].key < RETROK_LAST) &&
|
||||
di->state[rarch_keysym_lut[(enum retro_key)binds[port][i].key]] & 0x80)
|
||||
{
|
||||
ret |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (settings->uints.input_mouse_index[port] == 0)
|
||||
if (dinput_mouse_button_pressed(
|
||||
di, port, binds[port][i].mbutton))
|
||||
if (binds[port][i].valid)
|
||||
if (dinput_is_pressed(
|
||||
di, settings, joypad_info, binds[port], port, i))
|
||||
{
|
||||
ret |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((uint16_t)joykey != NO_BTN
|
||||
&& di->joypad->button(
|
||||
joypad_info->joy_idx, (uint16_t)joykey))
|
||||
{
|
||||
ret |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((float)abs(di->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
|
||||
{
|
||||
ret |= (1 << i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -603,22 +622,9 @@ static int16_t dinput_input_state(void *data,
|
||||
return 1;
|
||||
}
|
||||
if (binds[port][id].valid)
|
||||
{
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const uint64_t joykey = (binds[port][id].joykey != NO_BTN)
|
||||
? binds[port][id].joykey : joypad_info->auto_binds[id].joykey;
|
||||
const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE)
|
||||
? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis;
|
||||
|
||||
if (settings->uints.input_mouse_index[port] == 0)
|
||||
if (dinput_mouse_button_pressed(di, port, binds[port][id].mbutton))
|
||||
return 1;
|
||||
if ((uint16_t)joykey != NO_BTN
|
||||
&& di->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
|
||||
if (dinput_is_pressed(
|
||||
di, settings, joypad_info, binds[port], port, id))
|
||||
return 1;
|
||||
if (((float)abs(di->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user