mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 16:39:43 +00:00
Add rumble tests to libretro-test.
This commit is contained in:
parent
a01ef18f80
commit
8b1ac3bc9e
2
driver.c
2
driver.c
@ -311,7 +311,7 @@ void driver_set_nonblock_state(bool nonblock)
|
||||
|
||||
bool driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable)
|
||||
{
|
||||
if (driver.input && driver.input_data)
|
||||
if (driver.input && driver.input_data && driver.input->set_rumble)
|
||||
return driver.input->set_rumble(driver.input_data, port, effect, enable);
|
||||
else
|
||||
return false;
|
||||
|
@ -109,7 +109,7 @@ const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joyp
|
||||
bool input_joypad_set_rumble(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, enum retro_rumble_effect effect, bool state)
|
||||
{
|
||||
if (!driver)
|
||||
if (!driver || !driver->set_rumble)
|
||||
return false;
|
||||
|
||||
int joy_index = g_settings.input.joypad_map[port];
|
||||
|
@ -177,8 +177,9 @@ end:
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
||||
static bool udev_set_rumble(unsigned i, unsigned effect, bool state)
|
||||
static bool udev_set_rumble(unsigned i, enum retro_rumble_effect effect, bool state)
|
||||
{
|
||||
fprintf(stderr, "Rumble: Pad %u, Effect %u, State %u.\n", i, (unsigned)effect, (unsigned)state);
|
||||
struct udev_joypad *pad = &g_pads[i];
|
||||
|
||||
if (pad->fd < 0)
|
||||
@ -264,13 +265,11 @@ static int find_vacant_pad(void)
|
||||
static void free_pad(unsigned pad)
|
||||
{
|
||||
if (g_pads[pad].fd >= 0)
|
||||
{
|
||||
udev_set_rumble(pad, 0, false);
|
||||
udev_set_rumble(pad, 1, false);
|
||||
close(g_pads[pad].fd);
|
||||
}
|
||||
|
||||
free(g_pads[pad].path);
|
||||
if (g_pads[pad].ident)
|
||||
*g_pads[pad].ident = '\0';
|
||||
memset(&g_pads[pad], 0, sizeof(g_pads[pad]));
|
||||
g_pads[pad].fd = -1;
|
||||
|
||||
@ -280,8 +279,12 @@ static void free_pad(unsigned pad)
|
||||
static bool add_pad(unsigned i, int fd, const char *path)
|
||||
{
|
||||
struct udev_joypad *pad = &g_pads[i];
|
||||
pad->ident = g_settings.input.device_names[i];
|
||||
if (ioctl(fd, EVIOCGNAME(sizeof(g_settings.input.device_names[0])), pad->ident) < 0)
|
||||
{
|
||||
RARCH_LOG("[udev]: Failed to get pad name.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
RARCH_LOG("[udev]: Plugged pad: %s on port #%u.\n", pad->ident, i);
|
||||
|
||||
|
@ -61,6 +61,8 @@ static retro_environment_t environ_cb;
|
||||
static retro_input_poll_t input_poll_cb;
|
||||
static retro_input_state_t input_state_cb;
|
||||
|
||||
static struct retro_rumble_interface rumble;
|
||||
|
||||
void retro_set_environment(retro_environment_t cb)
|
||||
{
|
||||
environ_cb = cb;
|
||||
@ -173,6 +175,30 @@ static void update_input(void)
|
||||
|
||||
x_coord = (x_coord + dir_x) & 31;
|
||||
y_coord = (y_coord + dir_y) & 31;
|
||||
|
||||
if (rumble.set_rumble_state)
|
||||
{
|
||||
static bool old_start;
|
||||
static bool old_select;
|
||||
bool start = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
|
||||
bool select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
|
||||
if (old_start != start)
|
||||
{
|
||||
fprintf(stderr, "Strong rumble: %s.\n", start ? "ON": "OFF");
|
||||
if (!rumble.set_rumble_state(0, RETRO_RUMBLE_STRONG, start))
|
||||
fprintf(stderr, "Strong rumble; failed to set state.\n");
|
||||
}
|
||||
|
||||
if (old_select != select)
|
||||
{
|
||||
fprintf(stderr, "Weak rumble: %s.\n", select ? "ON": "OFF");
|
||||
if (!rumble.set_rumble_state(0, RETRO_RUMBLE_WEAK, select))
|
||||
fprintf(stderr, "Weak rumble; failed to set state.\n");
|
||||
}
|
||||
|
||||
old_start = start;
|
||||
old_select = select;
|
||||
}
|
||||
}
|
||||
|
||||
static void render_checkered(void)
|
||||
@ -262,6 +288,10 @@ bool retro_load_game(const struct retro_game_info *info)
|
||||
|
||||
struct retro_keyboard_callback cb = { keyboard_cb };
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &cb);
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble))
|
||||
fprintf(stderr, "Rumble environment supported.\n");
|
||||
else
|
||||
fprintf(stderr, "Rumble environment not supported.\n");
|
||||
|
||||
check_variables();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user