Merge pull request #5697 from hiddenasbestos/analog_buttons

Analog buttons
This commit is contained in:
Twinaphex 2017-11-18 10:14:35 +01:00 committed by GitHub
commit 13a0da1f25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 47 deletions

View File

@ -1609,8 +1609,52 @@ int16_t input_joypad_analog(const input_device_driver_t *drv,
unsigned port, unsigned idx, unsigned ident,
const struct retro_keybind *binds)
{
int16_t res;
if ( idx == RETRO_DEVICE_INDEX_ANALOG_BUTTON )
{
/* A RETRO_DEVICE_JOYPAD button? */
if ( ident < RARCH_FIRST_CUSTOM_BIND )
{
uint32_t axis = 0;
const struct retro_keybind *bind = NULL;
bind = &binds[ ident ];
if (!bind->valid)
return 0;
axis = bind->joyaxis;
if ( axis == AXIS_NONE )
axis = joypad_info.auto_binds[ ident ].joyaxis;
/* Analog button. */
res = abs( drv->axis( joypad_info.joy_idx, axis ) );
/* If the result is zero, it's got a digital button attached to it */
if ( res == 0 )
{
uint64_t key = bind->joykey;
if ( key == NO_BTN )
key = joypad_info.auto_binds[ ident ].joykey;
if ( drv->button(joypad_info.joy_idx, (uint16_t)key))
res = 0x7fff;
}
}
else
{
/* not a suitable button */
res = 0;
}
}
else
{
/* Analog sticks. Either RETRO_DEVICE_INDEX_ANALOG_LEFT
* or RETRO_DEVICE_INDEX_ANALOG_RIGHT */
uint32_t axis_minus, axis_plus;
int16_t pressed_minus, pressed_plus, res;
int16_t pressed_minus, pressed_plus;
unsigned ident_minus = 0;
unsigned ident_plus = 0;
const struct retro_keybind *bind_minus = NULL;
@ -1652,8 +1696,10 @@ int16_t input_joypad_analog(const input_device_driver_t *drv,
digital_left = -0x7fff;
if (drv->button(joypad_info.joy_idx, (uint16_t)key_plus))
digital_right = 0x7fff;
return digital_right + digital_left;
}
}
return res;
}

View File

@ -520,6 +520,7 @@ static INLINE bool input_joypad_pressed(
* E.g.:
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
* - RETRO_DEVICE_INDEX_ANALOG_BUTTON
* @ident : Analog key identifier.
* E.g.:
* - RETRO_DEVICE_ID_ANALOG_X

View File

@ -131,11 +131,12 @@ extern "C" {
#define RETRO_DEVICE_LIGHTGUN 4
/* The ANALOG device is an extension to JOYPAD (RetroPad).
* Similar to DualShock it adds two analog sticks.
* This is treated as a separate device type as it returns values in the
* full analog range of [-0x8000, 0x7fff]. Positive X axis is right.
* Positive Y axis is down.
* Only use ANALOG type when polling for analog values of the axes.
* Similar to DualShock2 it adds two analog sticks and all buttons can
* be analog. This is treated as a separate device type as it returns
* axis values in the full analog range of [-0x8000, 0x7fff].
* Positive X axis is right. Positive Y axis is down.
* Buttons are returned in the range [0, 0x7fff].
* Only use ANALOG type when polling for analog values.
*/
#define RETRO_DEVICE_ANALOG 5
@ -174,7 +175,8 @@ extern "C" {
/* Buttons for the RetroPad (JOYPAD).
* The placement of these is equivalent to placements on the
* Super Nintendo controller.
* L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */
* L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
* Also used as id values for RETRO_DEVICE_INDEX_ANALOG_BUTTON */
#define RETRO_DEVICE_ID_JOYPAD_B 0
#define RETRO_DEVICE_ID_JOYPAD_Y 1
#define RETRO_DEVICE_ID_JOYPAD_SELECT 2
@ -195,6 +197,7 @@ extern "C" {
/* Index / Id values for ANALOG device. */
#define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
#define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
#define RETRO_DEVICE_INDEX_ANALOG_BUTTON 2
#define RETRO_DEVICE_ID_ANALOG_X 0
#define RETRO_DEVICE_ID_ANALOG_Y 1