diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.h')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.h | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h deleted file mode 100644 index 7a9ad6346..000000000 --- a/src/input_common/sdl/sdl_impl.h +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | // Copyright 2018 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | #include <memory> | ||
| 9 | #include <mutex> | ||
| 10 | #include <thread> | ||
| 11 | #include <unordered_map> | ||
| 12 | |||
| 13 | #include <SDL.h> | ||
| 14 | |||
| 15 | #include "common/common_types.h" | ||
| 16 | #include "common/threadsafe_queue.h" | ||
| 17 | #include "input_common/sdl/sdl.h" | ||
| 18 | |||
| 19 | union SDL_Event; | ||
| 20 | using SDL_GameController = struct _SDL_GameController; | ||
| 21 | using SDL_Joystick = struct _SDL_Joystick; | ||
| 22 | using SDL_JoystickID = s32; | ||
| 23 | |||
| 24 | using ButtonBindings = | ||
| 25 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; | ||
| 26 | using ZButtonBindings = | ||
| 27 | std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; | ||
| 28 | |||
| 29 | namespace InputCommon::SDL { | ||
| 30 | |||
| 31 | class SDLAnalogFactory; | ||
| 32 | class SDLButtonFactory; | ||
| 33 | class SDLMotionFactory; | ||
| 34 | class SDLVibrationFactory; | ||
| 35 | class SDLJoystick; | ||
| 36 | |||
| 37 | class SDLState : public State { | ||
| 38 | public: | ||
| 39 | /// Initializes and registers SDL device factories | ||
| 40 | SDLState(); | ||
| 41 | |||
| 42 | /// Unregisters SDL device factories and shut them down. | ||
| 43 | ~SDLState() override; | ||
| 44 | |||
| 45 | /// Handle SDL_Events for joysticks from SDL_PollEvent | ||
| 46 | void HandleGameControllerEvent(const SDL_Event& event); | ||
| 47 | |||
| 48 | /// Get the nth joystick with the corresponding GUID | ||
| 49 | std::shared_ptr<SDLJoystick> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so | ||
| 53 | * tie it to a SDLJoystick with the same guid and that port | ||
| 54 | */ | ||
| 55 | std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); | ||
| 56 | |||
| 57 | /// Get all DevicePoller that use the SDL backend for a specific device type | ||
| 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 | |||
| 66 | ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override; | ||
| 67 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; | ||
| 68 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; | ||
| 69 | |||
| 70 | private: | ||
| 71 | void InitJoystick(int joystick_index); | ||
| 72 | void CloseJoystick(SDL_Joystick* sdl_joystick); | ||
| 73 | |||
| 74 | /// Needs to be called before SDL_QuitSubSystem. | ||
| 75 | void CloseJoysticks(); | ||
| 76 | |||
| 77 | /// Returns the default button bindings list for generic controllers | ||
| 78 | ButtonBindings GetDefaultButtonBinding() const; | ||
| 79 | |||
| 80 | /// Returns the default button bindings list for nintendo controllers | ||
| 81 | ButtonBindings GetNintendoButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; | ||
| 82 | |||
| 83 | /// Returns the button mappings from a single controller | ||
| 84 | ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, | ||
| 85 | const ButtonBindings& switch_to_sdl_button, | ||
| 86 | const ZButtonBindings& switch_to_sdl_axis) const; | ||
| 87 | |||
| 88 | /// Returns the button mappings from two different controllers | ||
| 89 | ButtonMapping GetDualControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, | ||
| 90 | const std::shared_ptr<SDLJoystick>& joystick2, | ||
| 91 | const ButtonBindings& switch_to_sdl_button, | ||
| 92 | const ZButtonBindings& switch_to_sdl_axis) const; | ||
| 93 | |||
| 94 | /// Returns true if the button is on the left joycon | ||
| 95 | bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const; | ||
| 96 | |||
| 97 | // Set to true if SDL supports game controller subsystem | ||
| 98 | bool has_gamecontroller = false; | ||
| 99 | |||
| 100 | /// Map of GUID of a list of corresponding virtual Joysticks | ||
| 101 | std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; | ||
| 102 | std::mutex joystick_map_mutex; | ||
| 103 | |||
| 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; | ||
| 110 | std::atomic<bool> initialized = false; | ||
| 111 | |||
| 112 | std::thread poll_thread; | ||
| 113 | }; | ||
| 114 | } // namespace InputCommon::SDL | ||