summaryrefslogtreecommitdiff
path: root/src/input_common/main.h
diff options
context:
space:
mode:
authorGravatar bunnei2020-08-28 09:57:50 -0400
committerGravatar GitHub2020-08-28 09:57:50 -0400
commit45b73ba840411fa61c75e6fe954b9a46ca5d59b6 (patch)
treec99333f0b6b386bfb80712d8e6ffa94bef04a9ff /src/input_common/main.h
parentMerge pull request #4586 from yuzu-emu/tsan-cpu-interrupt (diff)
parentinput_common: Eliminate most global state (diff)
downloadyuzu-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.h130
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
18namespace InputCommon { 18namespace InputCommon {
19
20/// Initializes and registers all built-in input device factories.
21void Init();
22
23/// Deregisters all built-in input device factories and shuts them down.
24void Shutdown();
25
26class Keyboard;
27
28/// Gets the keyboard button device factory.
29Keyboard* GetKeyboard();
30
31class MotionEmu;
32
33/// Gets the motion emulation factory.
34MotionEmu* GetMotionEmu();
35
36GCButtonFactory* GetGCButtons();
37
38GCAnalogFactory* GetGCAnalogs();
39
40/// Generates a serialized param package for creating a keyboard button device
41std::string GenerateKeyboardParam(int key_code);
42
43/// Generates a serialized param package for creating an analog device taking input from keyboard
44std::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 */
53std::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 */
59using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>;
60using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>;
61
62ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage&);
63AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage&);
64
65namespace Polling { 19namespace Polling {
66 20
67enum class DeviceType { Button, AnalogPreferred }; 21enum 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
91std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type); 45std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
92} // namespace Polling 46} // namespace Polling
47
48class GCAnalogFactory;
49class GCButtonFactory;
50class Keyboard;
51class 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 */
57using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>;
58using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>;
59
60class InputSubsystem {
61public:
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
119private:
120 struct Impl;
121 std::unique_ptr<Impl> impl;
122};
123
124/// Generates a serialized param package for creating a keyboard button device
125std::string GenerateKeyboardParam(int key_code);
126
127/// Generates a serialized param package for creating an analog device taking input from keyboard
128std::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