diff options
| author | 2020-08-28 09:57:50 -0400 | |
|---|---|---|
| committer | 2020-08-28 09:57:50 -0400 | |
| commit | 45b73ba840411fa61c75e6fe954b9a46ca5d59b6 (patch) | |
| tree | c99333f0b6b386bfb80712d8e6ffa94bef04a9ff /src/input_common/main.h | |
| parent | Merge pull request #4586 from yuzu-emu/tsan-cpu-interrupt (diff) | |
| parent | input_common: Eliminate most global state (diff) | |
| download | yuzu-45b73ba840411fa61c75e6fe954b9a46ca5d59b6.tar.gz yuzu-45b73ba840411fa61c75e6fe954b9a46ca5d59b6.tar.xz yuzu-45b73ba840411fa61c75e6fe954b9a46ca5d59b6.zip | |
Merge pull request #4544 from lioncash/input-sub
input_common: Eliminate most global state
Diffstat (limited to 'src/input_common/main.h')
| -rw-r--r-- | src/input_common/main.h | 130 |
1 files changed, 84 insertions, 46 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h index e706c3750..f66308163 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -16,52 +16,6 @@ class ParamPackage; | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | namespace InputCommon { | 18 | namespace InputCommon { |
| 19 | |||
| 20 | /// Initializes and registers all built-in input device factories. | ||
| 21 | void Init(); | ||
| 22 | |||
| 23 | /// Deregisters all built-in input device factories and shuts them down. | ||
| 24 | void Shutdown(); | ||
| 25 | |||
| 26 | class Keyboard; | ||
| 27 | |||
| 28 | /// Gets the keyboard button device factory. | ||
| 29 | Keyboard* GetKeyboard(); | ||
| 30 | |||
| 31 | class MotionEmu; | ||
| 32 | |||
| 33 | /// Gets the motion emulation factory. | ||
| 34 | MotionEmu* GetMotionEmu(); | ||
| 35 | |||
| 36 | GCButtonFactory* GetGCButtons(); | ||
| 37 | |||
| 38 | GCAnalogFactory* GetGCAnalogs(); | ||
| 39 | |||
| 40 | /// Generates a serialized param package for creating a keyboard button device | ||
| 41 | std::string GenerateKeyboardParam(int key_code); | ||
| 42 | |||
| 43 | /// Generates a serialized param package for creating an analog device taking input from keyboard | ||
| 44 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 45 | int key_modifier, float modifier_scale); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Return a list of available input devices that this Factory can create a new device with. | ||
| 49 | * Each returned Parampackage should have a `display` field used for display, a class field for | ||
| 50 | * backends to determine if this backend is meant to service the request and any other information | ||
| 51 | * needed to identify this in the backend later. | ||
| 52 | */ | ||
| 53 | std::vector<Common::ParamPackage> GetInputDevices(); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default | ||
| 57 | * mapping for the device. This is currently only implemented for the sdl backend devices. | ||
| 58 | */ | ||
| 59 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; | ||
| 60 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; | ||
| 61 | |||
| 62 | ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage&); | ||
| 63 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage&); | ||
| 64 | |||
| 65 | namespace Polling { | 19 | namespace Polling { |
| 66 | 20 | ||
| 67 | enum class DeviceType { Button, AnalogPreferred }; | 21 | enum class DeviceType { Button, AnalogPreferred }; |
| @@ -90,4 +44,88 @@ public: | |||
| 90 | // Get all DevicePoller from all backends for a specific device type | 44 | // Get all DevicePoller from all backends for a specific device type |
| 91 | std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type); | 45 | std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type); |
| 92 | } // namespace Polling | 46 | } // namespace Polling |
| 47 | |||
| 48 | class GCAnalogFactory; | ||
| 49 | class GCButtonFactory; | ||
| 50 | class Keyboard; | ||
| 51 | class MotionEmu; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default | ||
| 55 | * mapping for the device. This is currently only implemented for the SDL backend devices. | ||
| 56 | */ | ||
| 57 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; | ||
| 58 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; | ||
| 59 | |||
| 60 | class InputSubsystem { | ||
| 61 | public: | ||
| 62 | explicit InputSubsystem(); | ||
| 63 | ~InputSubsystem(); | ||
| 64 | |||
| 65 | InputSubsystem(const InputSubsystem&) = delete; | ||
| 66 | InputSubsystem& operator=(const InputSubsystem&) = delete; | ||
| 67 | |||
| 68 | InputSubsystem(InputSubsystem&&) = delete; | ||
| 69 | InputSubsystem& operator=(InputSubsystem&&) = delete; | ||
| 70 | |||
| 71 | /// Initializes and registers all built-in input device factories. | ||
| 72 | void Initialize(); | ||
| 73 | |||
| 74 | /// Unregisters all built-in input device factories and shuts them down. | ||
| 75 | void Shutdown(); | ||
| 76 | |||
| 77 | /// Retrieves the underlying keyboard device. | ||
| 78 | [[nodiscard]] Keyboard* GetKeyboard(); | ||
| 79 | |||
| 80 | /// Retrieves the underlying keyboard device. | ||
| 81 | [[nodiscard]] const Keyboard* GetKeyboard() const; | ||
| 82 | |||
| 83 | /// Retrieves the underlying motion emulation factory. | ||
| 84 | [[nodiscard]] MotionEmu* GetMotionEmu(); | ||
| 85 | |||
| 86 | /// Retrieves the underlying motion emulation factory. | ||
| 87 | [[nodiscard]] const MotionEmu* GetMotionEmu() const; | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Returns all available input devices that this Factory can create a new device with. | ||
| 91 | * Each returned ParamPackage should have a `display` field used for display, a class field for | ||
| 92 | * backends to determine if this backend is meant to service the request and any other | ||
| 93 | * information needed to identify this in the backend later. | ||
| 94 | */ | ||
| 95 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const; | ||
| 96 | |||
| 97 | /// Retrieves the analog mappings for the given device. | ||
| 98 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& device) const; | ||
| 99 | |||
| 100 | /// Retrieves the button mappings for the given device. | ||
| 101 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const; | ||
| 102 | |||
| 103 | /// Retrieves the underlying GameCube analog handler. | ||
| 104 | [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); | ||
| 105 | |||
| 106 | /// Retrieves the underlying GameCube analog handler. | ||
| 107 | [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const; | ||
| 108 | |||
| 109 | /// Retrieves the underlying GameCube button handler. | ||
| 110 | [[nodiscard]] GCButtonFactory* GetGCButtons(); | ||
| 111 | |||
| 112 | /// Retrieves the underlying GameCube button handler. | ||
| 113 | [[nodiscard]] const GCButtonFactory* GetGCButtons() const; | ||
| 114 | |||
| 115 | /// Get all DevicePoller from all backends for a specific device type | ||
| 116 | [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( | ||
| 117 | Polling::DeviceType type) const; | ||
| 118 | |||
| 119 | private: | ||
| 120 | struct Impl; | ||
| 121 | std::unique_ptr<Impl> impl; | ||
| 122 | }; | ||
| 123 | |||
| 124 | /// Generates a serialized param package for creating a keyboard button device | ||
| 125 | std::string GenerateKeyboardParam(int key_code); | ||
| 126 | |||
| 127 | /// Generates a serialized param package for creating an analog device taking input from keyboard | ||
| 128 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 129 | int key_modifier, float modifier_scale); | ||
| 130 | |||
| 93 | } // namespace InputCommon | 131 | } // namespace InputCommon |