diff options
Diffstat (limited to 'src/input_common/drivers/sdl_driver.h')
-rw-r--r-- | src/input_common/drivers/sdl_driver.h | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index dcd0d1e64..0846fbb50 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -12,6 +12,7 @@ #include <SDL.h> #include "common/common_types.h" +#include "common/threadsafe_queue.h" #include "input_common/input_engine.h" union SDL_Event; @@ -46,6 +47,7 @@ public: * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so * tie it to a SDLJoystick with the same guid and that port */ + std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const Common::UUID& guid, int port); std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); std::vector<Common::ParamPackage> GetInputDevices() const override; @@ -64,24 +66,32 @@ public: const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; private: + struct VibrationRequest { + PadIdentifier identifier; + Common::Input::VibrationStatus vibration; + }; + void InitJoystick(int joystick_index); void CloseJoystick(SDL_Joystick* sdl_joystick); /// Needs to be called before SDL_QuitSubSystem. void CloseJoysticks(); - Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, - float value = 0.1f) const; - Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, + /// Takes all vibrations from the queue and sends the command to the controller + void SendVibrations(); + + Common::ParamPackage BuildAnalogParamPackageForButton(int port, const Common::UUID& guid, + s32 axis, float value = 0.1f) const; + Common::ParamPackage BuildButtonParamPackageForButton(int port, const Common::UUID& guid, s32 button) const; - Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, s32 hat, + Common::ParamPackage BuildHatParamPackageForButton(int port, const Common::UUID& guid, s32 hat, u8 value) const; - Common::ParamPackage BuildMotionParam(int port, std::string guid) const; + Common::ParamPackage BuildMotionParam(int port, const Common::UUID& guid) const; Common::ParamPackage BuildParamPackageForBinding( - int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const; + int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const; Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x, int axis_y, float offset_x, @@ -107,8 +117,11 @@ private: /// Returns true if the button is on the left joycon bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const; + /// Queue of vibration request to controllers + Common::SPSCQueue<VibrationRequest> vibration_queue; + /// Map of GUID of a list of corresponding virtual Joysticks - std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; + std::unordered_map<Common::UUID, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; std::mutex joystick_map_mutex; bool start_thread = false; |