From a01ef18f8093949a959e99f078da7991571f026a Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 25 Sep 2013 23:21:32 +0200 Subject: [PATCH] Add RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE. --- driver.c | 8 ++++++++ driver.h | 11 ++++------- dynamic.c | 9 +++++++++ general.h | 1 + input/dinput.c | 2 +- input/input_common.c | 2 +- input/input_common.h | 4 ++-- input/linuxraw_input.c | 2 +- input/sdl_input.c | 2 +- input/x11_input.c | 2 +- libretro.h | 24 ++++++++++++++++++++++++ 11 files changed, 53 insertions(+), 14 deletions(-) diff --git a/driver.c b/driver.c index 019d5d1e1a..d96275c7fd 100644 --- a/driver.c +++ b/driver.c @@ -309,6 +309,14 @@ void driver_set_nonblock_state(bool nonblock) g_extern.audio_data.nonblock_chunk_size : g_extern.audio_data.block_chunk_size; } +bool driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable) +{ + if (driver.input && driver.input_data) + return driver.input->set_rumble(driver.input_data, port, effect, enable); + else + return false; +} + uintptr_t driver_get_current_framebuffer(void) { #ifdef HAVE_FBO diff --git a/driver.h b/driver.h index ac6dd1748a..d7ef4613ef 100644 --- a/driver.h +++ b/driver.h @@ -323,12 +323,6 @@ 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); @@ -341,7 +335,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); + bool (*set_rumble)(void *data, unsigned port, enum retro_rumble_effect effect, bool state); } input_driver_t; struct rarch_viewport; @@ -502,6 +496,9 @@ void driver_set_nonblock_state(bool nonblock); uintptr_t driver_get_current_framebuffer(void); retro_proc_address_t driver_get_proc_address(const char *sym); +// Used by RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE +bool driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable); + extern driver_t driver; //////////////////////////////////////////////// Backends diff --git a/dynamic.c b/dynamic.c index d1b356e067..ece577c181 100644 --- a/dynamic.c +++ b/dynamic.c @@ -756,6 +756,15 @@ bool rarch_environment_cb(unsigned cmd, void *data) break; } + case RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE: + { + RARCH_LOG("Environ GET_RUMBLE_INTERFACE.\n"); + struct retro_rumble_interface *iface = (struct retro_rumble_interface*)data; + iface->set_rumble_state = driver_set_rumble_state; + break; + } + + // Private extensions for internal use, not part of libretro API. case RETRO_ENVIRONMENT_SET_LIBRETRO_PATH: RARCH_LOG("Environ (Private) SET_LIBRETRO_PATH.\n"); diff --git a/general.h b/general.h index eb0c981526..0a3e9d8d6c 100644 --- a/general.h +++ b/general.h @@ -712,6 +712,7 @@ void rarch_set_fullscreen(bool fullscreen); void rarch_disk_control_set_eject(bool state, bool log); void rarch_disk_control_set_index(unsigned index); void rarch_disk_control_append_image(const char *path); +bool rarch_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable); void rarch_init_autosave(void); void rarch_deinit_autosave(void); void rarch_take_screenshot(void); diff --git a/input/dinput.c b/input/dinput.c index ddd327fd8c..13d62fc8ab 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -334,7 +334,7 @@ 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) +static bool dinput_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, bool state) { struct dinput_input *di = (struct dinput_input*)data; return input_joypad_set_rumble(di->joypad, port, effect, state); diff --git a/input/input_common.c b/input/input_common.c index 02468c0e5f..daa69be9cb 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -107,7 +107,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 rarch_rumble_effect effect, bool state) + unsigned port, enum retro_rumble_effect effect, bool state) { if (!driver) return false; diff --git a/input/input_common.h b/input/input_common.h index faba3be263..66866b2ba1 100644 --- a/input/input_common.h +++ b/input/input_common.h @@ -66,7 +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 + bool (*set_rumble)(unsigned, enum retro_rumble_effect, bool); // Optional const char *(*name)(unsigned); const char *ident; @@ -83,7 +83,7 @@ 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); + unsigned port, enum retro_rumble_effect effect, bool state); int16_t input_joypad_axis_raw(const rarch_joypad_driver_t *driver, unsigned joypad, unsigned axis); diff --git a/input/linuxraw_input.c b/input/linuxraw_input.c index 90dde34034..823c95e70f 100644 --- a/input/linuxraw_input.c +++ b/input/linuxraw_input.c @@ -285,7 +285,7 @@ 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) +static bool linuxraw_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, bool state) { linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; return input_joypad_set_rumble(linuxraw->joypad, port, effect, state); diff --git a/input/sdl_input.c b/input/sdl_input.c index a75302af10..e2c2dcff2d 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -214,7 +214,7 @@ 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) +static bool sdl_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, bool state) { sdl_input_t *sdl = (sdl_input_t*)data; return input_joypad_set_rumble(sdl->joypad, port, effect, state); diff --git a/input/x11_input.c b/input/x11_input.c index d788e5bdf8..c1a4ce7977 100644 --- a/input/x11_input.c +++ b/input/x11_input.c @@ -269,7 +269,7 @@ 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) +static bool x_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, bool state) { x11_input_t *x11 = (x11_input_t*)data; return input_joypad_set_rumble(x11->joypad, port, effect, state); diff --git a/libretro.h b/libretro.h index 8d23356138..973c9b36dc 100755 --- a/libretro.h +++ b/libretro.h @@ -514,8 +514,32 @@ enum retro_mod // Lets the core know how much time has passed since last invocation of retro_run(). // The frontend can tamper with the timing to fake fast-forward, slow-motion, frame stepping, etc. // In this case the delta time will use the reference value in frame_time_callback.. + // +#define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE (23 | RETRO_ENVIRONMENT_EXPERIMENTAL) + // struct retro_rumble_interface * -- + // Gets an interface which is used by a libretro core to set state of rumble motors in controllers. + // A strong and weak motor is supported, and they can be controlled indepedently. +enum retro_rumble_effect +{ + RETRO_RUMBLE_STRONG = 0, + RETRO_RUMBLE_WEAK = 1, + + RETRO_RUMBLE_DUMMY = INT_MAX +}; + +// Sets rumble state for joypad plugged in port 'port'. Rumble effects are controlled independently, +// and setting e.g. strong rumble does not override weak rumble. +// Should only be called when rumble state changes. +// +// Returns true if rumble state request was honored. Calling this before first retro_run() is likely to return false. +typedef bool (*retro_set_rumble_state_t)(unsigned port, enum retro_rumble_effect effect, bool enable); +struct retro_rumble_interface +{ + retro_set_rumble_state_t set_rumble_state; +}; + // Notifies libretro that audio data should be written. typedef void (*retro_audio_callback_t)(void);