mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 05:43:34 +00:00
Turn input_joypad_is_pressed into static inline function
This commit is contained in:
parent
7685f93d00
commit
efdfb29d50
@ -1370,42 +1370,6 @@ bool input_joypad_set_rumble(const input_device_driver_t *drv,
|
|||||||
return drv->set_rumble(joy_idx, effect, strength);
|
return drv->set_rumble(joy_idx, effect, strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* input_joypad_is_pressed:
|
|
||||||
* @drv : Input device driver handle.
|
|
||||||
* @port : User number.
|
|
||||||
* @binds : Binds of user.
|
|
||||||
* @key : Identifier of key.
|
|
||||||
*
|
|
||||||
* Checks if key (@key) was being pressed by user
|
|
||||||
* with number @port with provided keybinds (@binds).
|
|
||||||
*
|
|
||||||
* Returns: true (1) if key was pressed, otherwise
|
|
||||||
* false (0).
|
|
||||||
**/
|
|
||||||
bool input_joypad_pressed(
|
|
||||||
const input_device_driver_t *drv,
|
|
||||||
rarch_joypad_info_t joypad_info,
|
|
||||||
unsigned port,
|
|
||||||
const struct retro_keybind *binds,
|
|
||||||
unsigned key)
|
|
||||||
{
|
|
||||||
/* Auto-binds are per joypad, not per user. */
|
|
||||||
uint64_t joykey = (binds[key].joykey != NO_BTN)
|
|
||||||
? binds[key].joykey : joypad_info.auto_binds[key].joykey;
|
|
||||||
|
|
||||||
if ((uint16_t)joykey == NO_BTN || !drv->button(joypad_info.joy_idx, (uint16_t)joykey))
|
|
||||||
{
|
|
||||||
uint32_t joyaxis = (binds[key].joyaxis != AXIS_NONE)
|
|
||||||
? binds[key].joyaxis : joypad_info.auto_binds[key].joyaxis;
|
|
||||||
int16_t axis = drv->axis(joypad_info.joy_idx, joyaxis);
|
|
||||||
float scaled_axis = (float)abs(axis) / 0x8000;
|
|
||||||
return scaled_axis > joypad_info.axis_threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* input_joypad_analog:
|
* input_joypad_analog:
|
||||||
* @drv : Input device driver handle.
|
* @drv : Input device driver handle.
|
||||||
|
@ -18,11 +18,13 @@
|
|||||||
#define __INPUT_DRIVER__H
|
#define __INPUT_DRIVER__H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <retro_common_api.h>
|
#include <retro_common_api.h>
|
||||||
|
#include <retro_inline.h>
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
|
|
||||||
#include "input_defines.h"
|
#include "input_defines.h"
|
||||||
@ -443,11 +445,25 @@ void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident,
|
|||||||
* Returns: true (1) if key was pressed, otherwise
|
* Returns: true (1) if key was pressed, otherwise
|
||||||
* false (0).
|
* false (0).
|
||||||
**/
|
**/
|
||||||
bool input_joypad_pressed(const input_device_driver_t *driver,
|
static INLINE bool input_joypad_pressed(
|
||||||
|
const input_device_driver_t *drv,
|
||||||
rarch_joypad_info_t joypad_info,
|
rarch_joypad_info_t joypad_info,
|
||||||
unsigned port,
|
unsigned port,
|
||||||
const struct retro_keybind *binds,
|
const struct retro_keybind *binds,
|
||||||
unsigned key);
|
unsigned key)
|
||||||
|
{
|
||||||
|
/* Auto-binds are per joypad, not per user. */
|
||||||
|
uint64_t joykey = (binds[key].joykey != NO_BTN)
|
||||||
|
? binds[key].joykey : joypad_info.auto_binds[key].joykey;
|
||||||
|
uint32_t joyaxis = (binds[key].joyaxis != AXIS_NONE)
|
||||||
|
? binds[key].joyaxis : joypad_info.auto_binds[key].joyaxis;
|
||||||
|
|
||||||
|
if ((uint16_t)joykey != NO_BTN && drv->button(joypad_info.joy_idx, (uint16_t)joykey))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return ((float)abs(drv->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* input_joypad_analog:
|
* input_joypad_analog:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user