mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 06:40:18 +00:00
Hook up rumble interfaces to input drivers.
This commit is contained in:
parent
89fff9d790
commit
7855781cd8
@ -92,6 +92,7 @@ const rarch_joypad_driver_t apple_joypad = {
|
||||
apple_joypad_button,
|
||||
apple_joypad_axis,
|
||||
apple_joypad_poll,
|
||||
NULL,
|
||||
apple_joypad_name,
|
||||
"apple"
|
||||
};
|
||||
|
7
driver.h
7
driver.h
@ -323,6 +323,12 @@ enum keybind_set_id
|
||||
KEYBINDS_ACTION_LAST
|
||||
};
|
||||
|
||||
enum rarch_rumble_effect
|
||||
{
|
||||
RARCH_RUMBLE_STRONG = 0,
|
||||
RARCH_RUMBLE_WEAK = 1
|
||||
};
|
||||
|
||||
typedef struct input_driver
|
||||
{
|
||||
void *(*init)(void);
|
||||
@ -335,6 +341,7 @@ typedef struct input_driver
|
||||
const char *ident;
|
||||
|
||||
void (*grab_mouse)(void *data, bool state);
|
||||
bool (*set_rumble)(void *data, unsigned port, enum rarch_rumble_effect effect, bool state);
|
||||
} input_driver_t;
|
||||
|
||||
struct rarch_viewport;
|
||||
|
@ -334,6 +334,12 @@ static void dinput_grab_mouse(void *data, bool state)
|
||||
IDirectInputDevice8_Acquire(di->mouse);
|
||||
}
|
||||
|
||||
static bool dinput_set_rumble(void *data, unsigned port, enum rarch_rumble_effect effect, bool state)
|
||||
{
|
||||
struct dinput_input *di = (struct dinput_input*)data;
|
||||
return input_joypad_set_rumble(di->joypad, port, effect, state);
|
||||
}
|
||||
|
||||
const input_driver_t input_dinput = {
|
||||
dinput_init,
|
||||
dinput_poll,
|
||||
@ -344,6 +350,7 @@ const input_driver_t input_dinput = {
|
||||
"dinput",
|
||||
|
||||
dinput_grab_mouse,
|
||||
dinput_set_rumble,
|
||||
};
|
||||
|
||||
// Keep track of which pad indexes are 360 controllers
|
||||
@ -651,6 +658,7 @@ const rarch_joypad_driver_t dinput_joypad = {
|
||||
dinput_joypad_button,
|
||||
dinput_joypad_axis,
|
||||
dinput_joypad_poll,
|
||||
NULL,
|
||||
dinput_joypad_name,
|
||||
"dinput",
|
||||
};
|
||||
|
@ -48,12 +48,12 @@ static const rarch_joypad_driver_t *joypad_drivers[] = {
|
||||
#ifdef HAVE_DINPUT
|
||||
&dinput_joypad,
|
||||
#endif
|
||||
#ifdef HAVE_UDEV
|
||||
&udev_joypad,
|
||||
#endif
|
||||
#if defined(__linux) && !defined(ANDROID)
|
||||
&linuxraw_joypad,
|
||||
#endif
|
||||
#ifdef HAVE_UDEV
|
||||
&udev_joypad,
|
||||
#endif
|
||||
#ifdef HAVE_SDL
|
||||
&sdl_joypad,
|
||||
#endif
|
||||
@ -106,6 +106,19 @@ const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joyp
|
||||
return driver->name(joypad);
|
||||
}
|
||||
|
||||
bool input_joypad_set_rumble(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, enum rarch_rumble_effect effect, bool state)
|
||||
{
|
||||
if (!driver)
|
||||
return false;
|
||||
|
||||
int joy_index = g_settings.input.joypad_map[port];
|
||||
if (joy_index < 0 || joy_index >= MAX_PLAYERS)
|
||||
return false;
|
||||
|
||||
return driver->set_rumble(joy_index, effect, state);
|
||||
}
|
||||
|
||||
bool input_joypad_pressed(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, const struct retro_keybind *binds, unsigned key)
|
||||
{
|
||||
|
@ -66,6 +66,7 @@ typedef struct rarch_joypad_driver
|
||||
bool (*button)(unsigned, uint16_t);
|
||||
int16_t (*axis)(unsigned, uint32_t);
|
||||
void (*poll)(void);
|
||||
bool (*set_rumble)(unsigned, enum rarch_rumble_effect, bool); // Optional
|
||||
const char *(*name)(unsigned);
|
||||
|
||||
const char *ident;
|
||||
@ -81,6 +82,9 @@ bool input_joypad_pressed(const rarch_joypad_driver_t *driver,
|
||||
int16_t input_joypad_analog(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, unsigned index, unsigned id, const struct retro_keybind *binds);
|
||||
|
||||
bool input_joypad_set_rumble(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, enum rarch_rumble_effect effect, bool state);
|
||||
|
||||
int16_t input_joypad_axis_raw(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad, unsigned axis);
|
||||
bool input_joypad_button_raw(const rarch_joypad_driver_t *driver,
|
||||
|
@ -285,6 +285,12 @@ static void linuxraw_input_free(void *data)
|
||||
free(data);
|
||||
}
|
||||
|
||||
static bool linuxraw_set_rumble(void *data, unsigned port, enum rarch_rumble_effect effect, bool state)
|
||||
{
|
||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||
return input_joypad_set_rumble(linuxraw->joypad, port, effect, state);
|
||||
}
|
||||
|
||||
static void linuxraw_input_poll(void *data)
|
||||
{
|
||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||
@ -316,5 +322,7 @@ const input_driver_t input_linuxraw = {
|
||||
linuxraw_bind_button_pressed,
|
||||
linuxraw_input_free,
|
||||
NULL,
|
||||
"linuxraw"
|
||||
"linuxraw",
|
||||
NULL,
|
||||
linuxraw_set_rumble,
|
||||
};
|
||||
|
@ -312,6 +312,7 @@ const rarch_joypad_driver_t linuxraw_joypad = {
|
||||
linuxraw_joypad_button,
|
||||
linuxraw_joypad_axis,
|
||||
linuxraw_joypad_poll,
|
||||
NULL,
|
||||
linuxraw_joypad_name,
|
||||
"linuxraw",
|
||||
};
|
||||
|
@ -214,6 +214,12 @@ static void sdl_input_free(void *data)
|
||||
free(data);
|
||||
}
|
||||
|
||||
static bool sdl_set_rumble(void *data, unsigned port, enum rarch_rumble_effect effect, bool state)
|
||||
{
|
||||
sdl_input_t *sdl = (sdl_input_t*)data;
|
||||
return input_joypad_set_rumble(sdl->joypad, port, effect, state);
|
||||
}
|
||||
|
||||
static void sdl_poll_mouse(sdl_input_t *sdl)
|
||||
{
|
||||
Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y);
|
||||
@ -240,5 +246,7 @@ const input_driver_t input_sdl = {
|
||||
sdl_input_free,
|
||||
NULL,
|
||||
"sdl",
|
||||
NULL,
|
||||
sdl_set_rumble,
|
||||
};
|
||||
|
||||
|
@ -170,6 +170,7 @@ const rarch_joypad_driver_t sdl_joypad = {
|
||||
sdl_joypad_button,
|
||||
sdl_joypad_axis,
|
||||
sdl_joypad_poll,
|
||||
NULL,
|
||||
sdl_joypad_name,
|
||||
"sdl",
|
||||
};
|
||||
|
@ -177,14 +177,14 @@ end:
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
||||
static void udev_set_rumble(unsigned i, unsigned effect, bool state)
|
||||
static bool udev_set_rumble(unsigned i, unsigned effect, bool state)
|
||||
{
|
||||
struct udev_joypad *pad = &g_pads[i];
|
||||
|
||||
if (pad->fd < 0)
|
||||
return;
|
||||
return false;
|
||||
if (!pad->support_ff[effect])
|
||||
return;
|
||||
return false;
|
||||
|
||||
struct input_event play;
|
||||
memset(&play, 0, sizeof(play));
|
||||
@ -195,7 +195,10 @@ static void udev_set_rumble(unsigned i, unsigned effect, bool state)
|
||||
{
|
||||
RARCH_ERR("[udev]: Failed to set rumble effect %u on pad %u.\n",
|
||||
effect, i);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void udev_joypad_poll(void)
|
||||
@ -578,6 +581,7 @@ const rarch_joypad_driver_t udev_joypad = {
|
||||
udev_joypad_button,
|
||||
udev_joypad_axis,
|
||||
udev_joypad_poll,
|
||||
udev_set_rumble,
|
||||
udev_joypad_name,
|
||||
"udev",
|
||||
};
|
||||
|
@ -371,6 +371,7 @@ const rarch_joypad_driver_t winxinput_joypad = {
|
||||
winxinput_joypad_button,
|
||||
winxinput_joypad_axis,
|
||||
winxinput_joypad_poll,
|
||||
NULL, // FIXME: Add rumble.
|
||||
winxinput_joypad_name,
|
||||
"winxinput",
|
||||
};
|
||||
|
@ -269,6 +269,12 @@ static void x_grab_mouse(void *data, bool state)
|
||||
x11->grab_mouse = state;
|
||||
}
|
||||
|
||||
static bool x_set_rumble(void *data, unsigned port, enum rarch_rumble_effect effect, bool state)
|
||||
{
|
||||
x11_input_t *x11 = (x11_input_t*)data;
|
||||
return input_joypad_set_rumble(x11->joypad, port, effect, state);
|
||||
}
|
||||
|
||||
const input_driver_t input_x = {
|
||||
x_input_init,
|
||||
x_input_poll,
|
||||
@ -278,5 +284,6 @@ const input_driver_t input_x = {
|
||||
NULL,
|
||||
"x",
|
||||
x_grab_mouse,
|
||||
x_set_rumble,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user