diff options
| author | 2021-09-20 17:36:23 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:23 -0600 | |
| commit | 59b995a9e53f09b9831b03608cfe5ce27c3e3485 (patch) | |
| tree | 54cf3df8ed6ef572d754267be8339c9a8f25b203 /src/input_common/sdl/sdl_impl.h | |
| parent | input_common: Rewrite udp client (diff) | |
| download | yuzu-59b995a9e53f09b9831b03608cfe5ce27c3e3485.tar.gz yuzu-59b995a9e53f09b9831b03608cfe5ce27c3e3485.tar.xz yuzu-59b995a9e53f09b9831b03608cfe5ce27c3e3485.zip | |
input_common: Rewrite SDL
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.h (renamed from src/input_common/sdl/sdl_impl.h) | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/drivers/sdl_driver.h index 7a9ad6346..d8d350184 100644 --- a/src/input_common/sdl/sdl_impl.h +++ b/src/input_common/drivers/sdl_driver.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <atomic> | 7 | #include <atomic> |
| 8 | #include <memory> | ||
| 9 | #include <mutex> | 8 | #include <mutex> |
| 10 | #include <thread> | 9 | #include <thread> |
| 11 | #include <unordered_map> | 10 | #include <unordered_map> |
| @@ -13,8 +12,7 @@ | |||
| 13 | #include <SDL.h> | 12 | #include <SDL.h> |
| 14 | 13 | ||
| 15 | #include "common/common_types.h" | 14 | #include "common/common_types.h" |
| 16 | #include "common/threadsafe_queue.h" | 15 | #include "input_common/input_engine.h" |
| 17 | #include "input_common/sdl/sdl.h" | ||
| 18 | 16 | ||
| 19 | union SDL_Event; | 17 | union SDL_Event; |
| 20 | using SDL_GameController = struct _SDL_GameController; | 18 | using SDL_GameController = struct _SDL_GameController; |
| @@ -26,21 +24,17 @@ using ButtonBindings = | |||
| 26 | using ZButtonBindings = | 24 | using ZButtonBindings = |
| 27 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; | 25 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; |
| 28 | 26 | ||
| 29 | namespace InputCommon::SDL { | 27 | namespace InputCommon { |
| 30 | 28 | ||
| 31 | class SDLAnalogFactory; | ||
| 32 | class SDLButtonFactory; | ||
| 33 | class SDLMotionFactory; | ||
| 34 | class SDLVibrationFactory; | ||
| 35 | class SDLJoystick; | 29 | class SDLJoystick; |
| 36 | 30 | ||
| 37 | class SDLState : public State { | 31 | class SDLDriver : public InputCommon::InputEngine { |
| 38 | public: | 32 | public: |
| 39 | /// Initializes and registers SDL device factories | 33 | /// Initializes and registers SDL device factories |
| 40 | SDLState(); | 34 | SDLDriver(const std::string& input_engine_); |
| 41 | 35 | ||
| 42 | /// Unregisters SDL device factories and shut them down. | 36 | /// Unregisters SDL device factories and shut them down. |
| 43 | ~SDLState() override; | 37 | ~SDLDriver() override; |
| 44 | 38 | ||
| 45 | /// Handle SDL_Events for joysticks from SDL_PollEvent | 39 | /// Handle SDL_Events for joysticks from SDL_PollEvent |
| 46 | void HandleGameControllerEvent(const SDL_Event& event); | 40 | void HandleGameControllerEvent(const SDL_Event& event); |
| @@ -54,18 +48,18 @@ public: | |||
| 54 | */ | 48 | */ |
| 55 | std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); | 49 | std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); |
| 56 | 50 | ||
| 57 | /// Get all DevicePoller that use the SDL backend for a specific device type | 51 | std::vector<Common::ParamPackage> GetInputDevices() const override; |
| 58 | Pollers GetPollers(Polling::DeviceType type) override; | ||
| 59 | |||
| 60 | /// Used by the Pollers during config | ||
| 61 | std::atomic<bool> polling = false; | ||
| 62 | Common::SPSCQueue<SDL_Event> event_queue; | ||
| 63 | |||
| 64 | std::vector<Common::ParamPackage> GetInputDevices() override; | ||
| 65 | 52 | ||
| 66 | ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override; | 53 | ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override; |
| 67 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; | 54 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; |
| 68 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; | 55 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; |
| 56 | std::string GetUIName(const Common::ParamPackage& params) const override; | ||
| 57 | |||
| 58 | std::string GetHatButtonName(u8 direction_value) const override; | ||
| 59 | u8 GetHatButtonId(const std::string direction_name) const override; | ||
| 60 | |||
| 61 | bool SetRumble(const PadIdentifier& identifier, | ||
| 62 | const Input::VibrationStatus vibration) override; | ||
| 69 | 63 | ||
| 70 | private: | 64 | private: |
| 71 | void InitJoystick(int joystick_index); | 65 | void InitJoystick(int joystick_index); |
| @@ -74,6 +68,23 @@ private: | |||
| 74 | /// Needs to be called before SDL_QuitSubSystem. | 68 | /// Needs to be called before SDL_QuitSubSystem. |
| 75 | void CloseJoysticks(); | 69 | void CloseJoysticks(); |
| 76 | 70 | ||
| 71 | Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, | ||
| 72 | float value = 0.1f) const; | ||
| 73 | Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, | ||
| 74 | s32 button) const; | ||
| 75 | |||
| 76 | Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, s32 hat, | ||
| 77 | u8 value) const; | ||
| 78 | |||
| 79 | Common::ParamPackage BuildMotionParam(int port, std::string guid) const; | ||
| 80 | |||
| 81 | Common::ParamPackage BuildParamPackageForBinding( | ||
| 82 | int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const; | ||
| 83 | |||
| 84 | Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x, | ||
| 85 | int axis_y, float offset_x, | ||
| 86 | float offset_y) const; | ||
| 87 | |||
| 77 | /// Returns the default button bindings list for generic controllers | 88 | /// Returns the default button bindings list for generic controllers |
| 78 | ButtonBindings GetDefaultButtonBinding() const; | 89 | ButtonBindings GetDefaultButtonBinding() const; |
| 79 | 90 | ||
| @@ -101,14 +112,9 @@ private: | |||
| 101 | std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; | 112 | std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; |
| 102 | std::mutex joystick_map_mutex; | 113 | std::mutex joystick_map_mutex; |
| 103 | 114 | ||
| 104 | std::shared_ptr<SDLButtonFactory> button_factory; | ||
| 105 | std::shared_ptr<SDLAnalogFactory> analog_factory; | ||
| 106 | std::shared_ptr<SDLVibrationFactory> vibration_factory; | ||
| 107 | std::shared_ptr<SDLMotionFactory> motion_factory; | ||
| 108 | |||
| 109 | bool start_thread = false; | 115 | bool start_thread = false; |
| 110 | std::atomic<bool> initialized = false; | 116 | std::atomic<bool> initialized = false; |
| 111 | 117 | ||
| 112 | std::thread poll_thread; | 118 | std::thread poll_thread; |
| 113 | }; | 119 | }; |
| 114 | } // namespace InputCommon::SDL | 120 | } // namespace InputCommon |