mirror of
https://github.com/libretro/RetroArch
synced 2025-03-17 10:21:26 +00:00
Create input_joypad_analog_button
This commit is contained in:
parent
a7a03984f1
commit
9e7ca7cbbe
@ -644,10 +644,10 @@ static int16_t dinput_input_state(void *data,
|
||||
if (binds[port])
|
||||
{
|
||||
int16_t ret = dinput_pressed_analog(di, binds[port], idx, id);
|
||||
if (!ret)
|
||||
ret = input_joypad_analog(di->joypad, joypad_info,
|
||||
port, idx, id, binds[port]);
|
||||
return ret;
|
||||
if (ret)
|
||||
return ret;
|
||||
return input_joypad_analog(di->joypad, joypad_info,
|
||||
port, idx, id, binds[port]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -348,6 +348,11 @@ int16_t input_joypad_analog(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const struct retro_keybind *binds);
|
||||
|
||||
int16_t input_joypad_analog_button(const input_device_driver_t *drv,
|
||||
rarch_joypad_info_t *joypad_info,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const struct retro_keybind *binds);
|
||||
|
||||
/**
|
||||
* input_joypad_set_rumble:
|
||||
* @drv : Input device driver handle.
|
||||
|
47
retroarch.c
47
retroarch.c
@ -21761,10 +21761,13 @@ static void input_driver_poll(void)
|
||||
{
|
||||
if (ret & (1 << k))
|
||||
{
|
||||
int16_t val = input_joypad_analog(
|
||||
bool check = (k < RARCH_FIRST_CUSTOM_BIND)
|
||||
&& p_rarch->libretro_input_binds[i]->valid;
|
||||
int16_t val = (check)
|
||||
? input_joypad_analog_button(
|
||||
joypad_driver, &joypad_info[i], (unsigned)i,
|
||||
RETRO_DEVICE_INDEX_ANALOG_BUTTON, k,
|
||||
p_rarch->libretro_input_binds[i]);
|
||||
p_rarch->libretro_input_binds[i]) : 0;
|
||||
|
||||
BIT256_SET_PTR(p_new_state, k);
|
||||
|
||||
@ -24356,6 +24359,46 @@ bool input_joypad_set_rumble(const input_device_driver_t *drv,
|
||||
return drv->set_rumble(joy_idx, effect, strength);
|
||||
}
|
||||
|
||||
int16_t input_joypad_analog_button(const input_device_driver_t *drv,
|
||||
rarch_joypad_info_t *joypad_info,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const struct retro_keybind *binds)
|
||||
{
|
||||
int16_t res = 0;
|
||||
struct rarch_state *p_rarch = &rarch_st;
|
||||
settings_t *settings = p_rarch->configuration_settings;
|
||||
float input_analog_deadzone = settings->floats.input_analog_deadzone;
|
||||
const struct retro_keybind *bind = &binds[ ident ];
|
||||
uint32_t axis = (bind->joyaxis == AXIS_NONE)
|
||||
? joypad_info->auto_binds[ident].joyaxis
|
||||
: bind->joyaxis;
|
||||
|
||||
/* Analog button. */
|
||||
if (drv->axis)
|
||||
{
|
||||
float normal_mag = 0.0f;
|
||||
if (input_analog_deadzone)
|
||||
normal_mag = fabs((1.0f / 0x7fff) * drv->axis(
|
||||
joypad_info->joy_idx, axis));
|
||||
res = abs(input_joypad_axis(p_rarch, drv,
|
||||
joypad_info->joy_idx, axis, normal_mag));
|
||||
}
|
||||
|
||||
/* If the result is zero, it's got a digital button
|
||||
* attached to it instead */
|
||||
if (res == 0)
|
||||
{
|
||||
uint16_t key = (bind->joykey == NO_BTN)
|
||||
? joypad_info->auto_binds[ident].joykey
|
||||
: bind->joykey;
|
||||
|
||||
if (drv->button(joypad_info->joy_idx, key))
|
||||
res = 0x7fff;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_analog:
|
||||
* @drv : Input device driver handle.
|
||||
|
Loading…
x
Reference in New Issue
Block a user