diff options
| author | 2021-12-18 13:57:14 +0800 | |
|---|---|---|
| committer | 2021-12-18 13:57:14 +0800 | |
| commit | e49184e6069a9d791d2df3c1958f5c4b1187e124 (patch) | |
| tree | b776caf722e0be0e680f67b0ad0842628162ef1c /src/input_common/main.cpp | |
| parent | Implement convert legacy to generic (diff) | |
| parent | Merge pull request #7570 from ameerj/favorites-expanded (diff) | |
| download | yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip | |
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/input_common/main.cpp')
| -rw-r--r-- | src/input_common/main.cpp | 468 |
1 files changed, 258 insertions, 210 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index f3907c65a..940744c5f 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -4,146 +4,173 @@ | |||
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <thread> | 6 | #include <thread> |
| 7 | #include "common/input.h" | ||
| 7 | #include "common/param_package.h" | 8 | #include "common/param_package.h" |
| 8 | #include "common/settings.h" | 9 | #include "input_common/drivers/gc_adapter.h" |
| 9 | #include "input_common/analog_from_button.h" | 10 | #include "input_common/drivers/keyboard.h" |
| 10 | #include "input_common/gcadapter/gc_adapter.h" | 11 | #include "input_common/drivers/mouse.h" |
| 11 | #include "input_common/gcadapter/gc_poller.h" | 12 | #include "input_common/drivers/tas_input.h" |
| 12 | #include "input_common/keyboard.h" | 13 | #include "input_common/drivers/touch_screen.h" |
| 14 | #include "input_common/drivers/udp_client.h" | ||
| 15 | #include "input_common/helpers/stick_from_buttons.h" | ||
| 16 | #include "input_common/helpers/touch_from_buttons.h" | ||
| 17 | #include "input_common/input_engine.h" | ||
| 18 | #include "input_common/input_mapping.h" | ||
| 19 | #include "input_common/input_poller.h" | ||
| 13 | #include "input_common/main.h" | 20 | #include "input_common/main.h" |
| 14 | #include "input_common/motion_from_button.h" | ||
| 15 | #include "input_common/mouse/mouse_input.h" | ||
| 16 | #include "input_common/mouse/mouse_poller.h" | ||
| 17 | #include "input_common/tas/tas_input.h" | ||
| 18 | #include "input_common/tas/tas_poller.h" | ||
| 19 | #include "input_common/touch_from_button.h" | ||
| 20 | #include "input_common/udp/client.h" | ||
| 21 | #include "input_common/udp/udp.h" | ||
| 22 | #ifdef HAVE_SDL2 | 21 | #ifdef HAVE_SDL2 |
| 23 | #include "input_common/sdl/sdl.h" | 22 | #include "input_common/drivers/sdl_driver.h" |
| 24 | #endif | 23 | #endif |
| 25 | 24 | ||
| 26 | namespace InputCommon { | 25 | namespace InputCommon { |
| 27 | 26 | ||
| 28 | struct InputSubsystem::Impl { | 27 | struct InputSubsystem::Impl { |
| 29 | void Initialize() { | 28 | void Initialize() { |
| 30 | gcadapter = std::make_shared<GCAdapter::Adapter>(); | 29 | mapping_factory = std::make_shared<MappingFactory>(); |
| 31 | gcbuttons = std::make_shared<GCButtonFactory>(gcadapter); | 30 | MappingCallback mapping_callback{[this](MappingData data) { RegisterInput(data); }}; |
| 32 | Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); | 31 | |
| 33 | gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); | 32 | keyboard = std::make_shared<Keyboard>("keyboard"); |
| 34 | Input::RegisterFactory<Input::AnalogDevice>("gcpad", gcanalog); | 33 | keyboard->SetMappingCallback(mapping_callback); |
| 35 | gcvibration = std::make_shared<GCVibrationFactory>(gcadapter); | 34 | keyboard_factory = std::make_shared<InputFactory>(keyboard); |
| 36 | Input::RegisterFactory<Input::VibrationDevice>("gcpad", gcvibration); | 35 | keyboard_output_factory = std::make_shared<OutputFactory>(keyboard); |
| 37 | 36 | Common::Input::RegisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName(), | |
| 38 | keyboard = std::make_shared<Keyboard>(); | 37 | keyboard_factory); |
| 39 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | 38 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName(), |
| 40 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | 39 | keyboard_output_factory); |
| 41 | std::make_shared<AnalogFromButton>()); | 40 | |
| 42 | Input::RegisterFactory<Input::MotionDevice>("keyboard", | 41 | mouse = std::make_shared<Mouse>("mouse"); |
| 43 | std::make_shared<MotionFromButton>()); | 42 | mouse->SetMappingCallback(mapping_callback); |
| 44 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", | 43 | mouse_factory = std::make_shared<InputFactory>(mouse); |
| 45 | std::make_shared<TouchFromButtonFactory>()); | 44 | mouse_output_factory = std::make_shared<OutputFactory>(mouse); |
| 45 | Common::Input::RegisterFactory<Common::Input::InputDevice>(mouse->GetEngineName(), | ||
| 46 | mouse_factory); | ||
| 47 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName(), | ||
| 48 | mouse_output_factory); | ||
| 49 | |||
| 50 | touch_screen = std::make_shared<TouchScreen>("touch"); | ||
| 51 | touch_screen_factory = std::make_shared<InputFactory>(touch_screen); | ||
| 52 | Common::Input::RegisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName(), | ||
| 53 | touch_screen_factory); | ||
| 54 | |||
| 55 | gcadapter = std::make_shared<GCAdapter>("gcpad"); | ||
| 56 | gcadapter->SetMappingCallback(mapping_callback); | ||
| 57 | gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter); | ||
| 58 | gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter); | ||
| 59 | Common::Input::RegisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName(), | ||
| 60 | gcadapter_input_factory); | ||
| 61 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName(), | ||
| 62 | gcadapter_output_factory); | ||
| 63 | |||
| 64 | udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); | ||
| 65 | udp_client->SetMappingCallback(mapping_callback); | ||
| 66 | udp_client_input_factory = std::make_shared<InputFactory>(udp_client); | ||
| 67 | udp_client_output_factory = std::make_shared<OutputFactory>(udp_client); | ||
| 68 | Common::Input::RegisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName(), | ||
| 69 | udp_client_input_factory); | ||
| 70 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(udp_client->GetEngineName(), | ||
| 71 | udp_client_output_factory); | ||
| 72 | |||
| 73 | tas_input = std::make_shared<TasInput::Tas>("tas"); | ||
| 74 | tas_input->SetMappingCallback(mapping_callback); | ||
| 75 | tas_input_factory = std::make_shared<InputFactory>(tas_input); | ||
| 76 | tas_output_factory = std::make_shared<OutputFactory>(tas_input); | ||
| 77 | Common::Input::RegisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName(), | ||
| 78 | tas_input_factory); | ||
| 79 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), | ||
| 80 | tas_output_factory); | ||
| 46 | 81 | ||
| 47 | #ifdef HAVE_SDL2 | 82 | #ifdef HAVE_SDL2 |
| 48 | sdl = SDL::Init(); | 83 | sdl = std::make_shared<SDLDriver>("sdl"); |
| 84 | sdl->SetMappingCallback(mapping_callback); | ||
| 85 | sdl_input_factory = std::make_shared<InputFactory>(sdl); | ||
| 86 | sdl_output_factory = std::make_shared<OutputFactory>(sdl); | ||
| 87 | Common::Input::RegisterFactory<Common::Input::InputDevice>(sdl->GetEngineName(), | ||
| 88 | sdl_input_factory); | ||
| 89 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName(), | ||
| 90 | sdl_output_factory); | ||
| 49 | #endif | 91 | #endif |
| 50 | 92 | ||
| 51 | udp = std::make_shared<InputCommon::CemuhookUDP::Client>(); | 93 | Common::Input::RegisterFactory<Common::Input::InputDevice>( |
| 52 | udpmotion = std::make_shared<UDPMotionFactory>(udp); | 94 | "touch_from_button", std::make_shared<TouchFromButton>()); |
| 53 | Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", udpmotion); | 95 | Common::Input::RegisterFactory<Common::Input::InputDevice>( |
| 54 | udptouch = std::make_shared<UDPTouchFactory>(udp); | 96 | "analog_from_button", std::make_shared<StickFromButton>()); |
| 55 | Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", udptouch); | ||
| 56 | |||
| 57 | mouse = std::make_shared<MouseInput::Mouse>(); | ||
| 58 | mousebuttons = std::make_shared<MouseButtonFactory>(mouse); | ||
| 59 | Input::RegisterFactory<Input::ButtonDevice>("mouse", mousebuttons); | ||
| 60 | mouseanalog = std::make_shared<MouseAnalogFactory>(mouse); | ||
| 61 | Input::RegisterFactory<Input::AnalogDevice>("mouse", mouseanalog); | ||
| 62 | mousemotion = std::make_shared<MouseMotionFactory>(mouse); | ||
| 63 | Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); | ||
| 64 | mousetouch = std::make_shared<MouseTouchFactory>(mouse); | ||
| 65 | Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); | ||
| 66 | |||
| 67 | tas = std::make_shared<TasInput::Tas>(); | ||
| 68 | tasbuttons = std::make_shared<TasButtonFactory>(tas); | ||
| 69 | Input::RegisterFactory<Input::ButtonDevice>("tas", tasbuttons); | ||
| 70 | tasanalog = std::make_shared<TasAnalogFactory>(tas); | ||
| 71 | Input::RegisterFactory<Input::AnalogDevice>("tas", tasanalog); | ||
| 72 | } | 97 | } |
| 73 | 98 | ||
| 74 | void Shutdown() { | 99 | void Shutdown() { |
| 75 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | 100 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName()); |
| 76 | Input::UnregisterFactory<Input::MotionDevice>("keyboard"); | 101 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName()); |
| 77 | keyboard.reset(); | 102 | keyboard.reset(); |
| 78 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | ||
| 79 | Input::UnregisterFactory<Input::TouchDevice>("touch_from_button"); | ||
| 80 | #ifdef HAVE_SDL2 | ||
| 81 | sdl.reset(); | ||
| 82 | #endif | ||
| 83 | Input::UnregisterFactory<Input::ButtonDevice>("gcpad"); | ||
| 84 | Input::UnregisterFactory<Input::AnalogDevice>("gcpad"); | ||
| 85 | Input::UnregisterFactory<Input::VibrationDevice>("gcpad"); | ||
| 86 | 103 | ||
| 87 | gcbuttons.reset(); | 104 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(mouse->GetEngineName()); |
| 88 | gcanalog.reset(); | 105 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName()); |
| 89 | gcvibration.reset(); | 106 | mouse.reset(); |
| 90 | 107 | ||
| 91 | Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp"); | 108 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName()); |
| 92 | Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp"); | 109 | touch_screen.reset(); |
| 93 | 110 | ||
| 94 | udpmotion.reset(); | 111 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName()); |
| 95 | udptouch.reset(); | 112 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName()); |
| 113 | gcadapter.reset(); | ||
| 96 | 114 | ||
| 97 | Input::UnregisterFactory<Input::ButtonDevice>("mouse"); | 115 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName()); |
| 98 | Input::UnregisterFactory<Input::AnalogDevice>("mouse"); | 116 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(udp_client->GetEngineName()); |
| 99 | Input::UnregisterFactory<Input::MotionDevice>("mouse"); | 117 | udp_client.reset(); |
| 100 | Input::UnregisterFactory<Input::TouchDevice>("mouse"); | ||
| 101 | 118 | ||
| 102 | mousebuttons.reset(); | 119 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName()); |
| 103 | mouseanalog.reset(); | 120 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName()); |
| 104 | mousemotion.reset(); | 121 | tas_input.reset(); |
| 105 | mousetouch.reset(); | ||
| 106 | 122 | ||
| 107 | Input::UnregisterFactory<Input::ButtonDevice>("tas"); | 123 | #ifdef HAVE_SDL2 |
| 108 | Input::UnregisterFactory<Input::AnalogDevice>("tas"); | 124 | Common::Input::UnregisterFactory<Common::Input::InputDevice>(sdl->GetEngineName()); |
| 125 | Common::Input::UnregisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName()); | ||
| 126 | sdl.reset(); | ||
| 127 | #endif | ||
| 109 | 128 | ||
| 110 | tasbuttons.reset(); | 129 | Common::Input::UnregisterFactory<Common::Input::InputDevice>("touch_from_button"); |
| 111 | tasanalog.reset(); | 130 | Common::Input::UnregisterFactory<Common::Input::InputDevice>("analog_from_button"); |
| 112 | } | 131 | } |
| 113 | 132 | ||
| 114 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { | 133 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { |
| 115 | std::vector<Common::ParamPackage> devices = { | 134 | std::vector<Common::ParamPackage> devices = { |
| 116 | Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, | 135 | Common::ParamPackage{{"display", "Any"}, {"engine", "any"}}, |
| 117 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, | ||
| 118 | }; | 136 | }; |
| 119 | if (Settings::values.tas_enable) { | 137 | |
| 120 | devices.emplace_back( | 138 | auto keyboard_devices = keyboard->GetInputDevices(); |
| 121 | Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}}); | 139 | devices.insert(devices.end(), keyboard_devices.begin(), keyboard_devices.end()); |
| 122 | } | 140 | auto mouse_devices = mouse->GetInputDevices(); |
| 141 | devices.insert(devices.end(), mouse_devices.begin(), mouse_devices.end()); | ||
| 142 | auto gcadapter_devices = gcadapter->GetInputDevices(); | ||
| 143 | devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end()); | ||
| 144 | auto udp_devices = udp_client->GetInputDevices(); | ||
| 145 | devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); | ||
| 123 | #ifdef HAVE_SDL2 | 146 | #ifdef HAVE_SDL2 |
| 124 | auto sdl_devices = sdl->GetInputDevices(); | 147 | auto sdl_devices = sdl->GetInputDevices(); |
| 125 | devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); | 148 | devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); |
| 126 | #endif | 149 | #endif |
| 127 | auto udp_devices = udp->GetInputDevices(); | 150 | |
| 128 | devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); | ||
| 129 | auto gcpad_devices = gcadapter->GetInputDevices(); | ||
| 130 | devices.insert(devices.end(), gcpad_devices.begin(), gcpad_devices.end()); | ||
| 131 | return devices; | 151 | return devices; |
| 132 | } | 152 | } |
| 133 | 153 | ||
| 134 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice( | 154 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice( |
| 135 | const Common::ParamPackage& params) const { | 155 | const Common::ParamPackage& params) const { |
| 136 | if (!params.Has("class") || params.Get("class", "") == "any") { | 156 | if (!params.Has("engine") || params.Get("engine", "") == "any") { |
| 137 | return {}; | 157 | return {}; |
| 138 | } | 158 | } |
| 139 | if (params.Get("class", "") == "gcpad") { | 159 | const std::string engine = params.Get("engine", ""); |
| 160 | if (engine == mouse->GetEngineName()) { | ||
| 161 | return mouse->GetAnalogMappingForDevice(params); | ||
| 162 | } | ||
| 163 | if (engine == gcadapter->GetEngineName()) { | ||
| 140 | return gcadapter->GetAnalogMappingForDevice(params); | 164 | return gcadapter->GetAnalogMappingForDevice(params); |
| 141 | } | 165 | } |
| 142 | if (params.Get("class", "") == "tas") { | 166 | if (engine == udp_client->GetEngineName()) { |
| 143 | return tas->GetAnalogMappingForDevice(params); | 167 | return udp_client->GetAnalogMappingForDevice(params); |
| 168 | } | ||
| 169 | if (engine == tas_input->GetEngineName()) { | ||
| 170 | return tas_input->GetAnalogMappingForDevice(params); | ||
| 144 | } | 171 | } |
| 145 | #ifdef HAVE_SDL2 | 172 | #ifdef HAVE_SDL2 |
| 146 | if (params.Get("class", "") == "sdl") { | 173 | if (engine == sdl->GetEngineName()) { |
| 147 | return sdl->GetAnalogMappingForDevice(params); | 174 | return sdl->GetAnalogMappingForDevice(params); |
| 148 | } | 175 | } |
| 149 | #endif | 176 | #endif |
| @@ -152,17 +179,21 @@ struct InputSubsystem::Impl { | |||
| 152 | 179 | ||
| 153 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice( | 180 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice( |
| 154 | const Common::ParamPackage& params) const { | 181 | const Common::ParamPackage& params) const { |
| 155 | if (!params.Has("class") || params.Get("class", "") == "any") { | 182 | if (!params.Has("engine") || params.Get("engine", "") == "any") { |
| 156 | return {}; | 183 | return {}; |
| 157 | } | 184 | } |
| 158 | if (params.Get("class", "") == "gcpad") { | 185 | const std::string engine = params.Get("engine", ""); |
| 186 | if (engine == gcadapter->GetEngineName()) { | ||
| 159 | return gcadapter->GetButtonMappingForDevice(params); | 187 | return gcadapter->GetButtonMappingForDevice(params); |
| 160 | } | 188 | } |
| 161 | if (params.Get("class", "") == "tas") { | 189 | if (engine == udp_client->GetEngineName()) { |
| 162 | return tas->GetButtonMappingForDevice(params); | 190 | return udp_client->GetButtonMappingForDevice(params); |
| 191 | } | ||
| 192 | if (engine == tas_input->GetEngineName()) { | ||
| 193 | return tas_input->GetButtonMappingForDevice(params); | ||
| 163 | } | 194 | } |
| 164 | #ifdef HAVE_SDL2 | 195 | #ifdef HAVE_SDL2 |
| 165 | if (params.Get("class", "") == "sdl") { | 196 | if (engine == sdl->GetEngineName()) { |
| 166 | return sdl->GetButtonMappingForDevice(params); | 197 | return sdl->GetButtonMappingForDevice(params); |
| 167 | } | 198 | } |
| 168 | #endif | 199 | #endif |
| @@ -171,40 +202,119 @@ struct InputSubsystem::Impl { | |||
| 171 | 202 | ||
| 172 | [[nodiscard]] MotionMapping GetMotionMappingForDevice( | 203 | [[nodiscard]] MotionMapping GetMotionMappingForDevice( |
| 173 | const Common::ParamPackage& params) const { | 204 | const Common::ParamPackage& params) const { |
| 174 | if (!params.Has("class") || params.Get("class", "") == "any") { | 205 | if (!params.Has("engine") || params.Get("engine", "") == "any") { |
| 175 | return {}; | 206 | return {}; |
| 176 | } | 207 | } |
| 177 | if (params.Get("class", "") == "cemuhookudp") { | 208 | const std::string engine = params.Get("engine", ""); |
| 178 | // TODO return the correct motion device | 209 | if (engine == udp_client->GetEngineName()) { |
| 179 | return {}; | 210 | return udp_client->GetMotionMappingForDevice(params); |
| 180 | } | 211 | } |
| 181 | #ifdef HAVE_SDL2 | 212 | #ifdef HAVE_SDL2 |
| 182 | if (params.Get("class", "") == "sdl") { | 213 | if (engine == sdl->GetEngineName()) { |
| 183 | return sdl->GetMotionMappingForDevice(params); | 214 | return sdl->GetMotionMappingForDevice(params); |
| 184 | } | 215 | } |
| 185 | #endif | 216 | #endif |
| 186 | return {}; | 217 | return {}; |
| 187 | } | 218 | } |
| 188 | 219 | ||
| 220 | Common::Input::ButtonNames GetButtonName(const Common::ParamPackage& params) const { | ||
| 221 | if (!params.Has("engine") || params.Get("engine", "") == "any") { | ||
| 222 | return Common::Input::ButtonNames::Undefined; | ||
| 223 | } | ||
| 224 | const std::string engine = params.Get("engine", ""); | ||
| 225 | if (engine == mouse->GetEngineName()) { | ||
| 226 | return mouse->GetUIName(params); | ||
| 227 | } | ||
| 228 | if (engine == gcadapter->GetEngineName()) { | ||
| 229 | return gcadapter->GetUIName(params); | ||
| 230 | } | ||
| 231 | if (engine == udp_client->GetEngineName()) { | ||
| 232 | return udp_client->GetUIName(params); | ||
| 233 | } | ||
| 234 | if (engine == tas_input->GetEngineName()) { | ||
| 235 | return tas_input->GetUIName(params); | ||
| 236 | } | ||
| 237 | #ifdef HAVE_SDL2 | ||
| 238 | if (engine == sdl->GetEngineName()) { | ||
| 239 | return sdl->GetUIName(params); | ||
| 240 | } | ||
| 241 | #endif | ||
| 242 | return Common::Input::ButtonNames::Invalid; | ||
| 243 | } | ||
| 244 | |||
| 245 | bool IsController(const Common::ParamPackage& params) { | ||
| 246 | const std::string engine = params.Get("engine", ""); | ||
| 247 | if (engine == mouse->GetEngineName()) { | ||
| 248 | return true; | ||
| 249 | } | ||
| 250 | if (engine == gcadapter->GetEngineName()) { | ||
| 251 | return true; | ||
| 252 | } | ||
| 253 | if (engine == udp_client->GetEngineName()) { | ||
| 254 | return true; | ||
| 255 | } | ||
| 256 | if (engine == tas_input->GetEngineName()) { | ||
| 257 | return true; | ||
| 258 | } | ||
| 259 | #ifdef HAVE_SDL2 | ||
| 260 | if (engine == sdl->GetEngineName()) { | ||
| 261 | return true; | ||
| 262 | } | ||
| 263 | #endif | ||
| 264 | return false; | ||
| 265 | } | ||
| 266 | |||
| 267 | void BeginConfiguration() { | ||
| 268 | keyboard->BeginConfiguration(); | ||
| 269 | mouse->BeginConfiguration(); | ||
| 270 | gcadapter->BeginConfiguration(); | ||
| 271 | udp_client->BeginConfiguration(); | ||
| 272 | #ifdef HAVE_SDL2 | ||
| 273 | sdl->BeginConfiguration(); | ||
| 274 | #endif | ||
| 275 | } | ||
| 276 | |||
| 277 | void EndConfiguration() { | ||
| 278 | keyboard->EndConfiguration(); | ||
| 279 | mouse->EndConfiguration(); | ||
| 280 | gcadapter->EndConfiguration(); | ||
| 281 | udp_client->EndConfiguration(); | ||
| 282 | #ifdef HAVE_SDL2 | ||
| 283 | sdl->EndConfiguration(); | ||
| 284 | #endif | ||
| 285 | } | ||
| 286 | |||
| 287 | void RegisterInput(MappingData data) { | ||
| 288 | mapping_factory->RegisterInput(data); | ||
| 289 | } | ||
| 290 | |||
| 291 | std::shared_ptr<MappingFactory> mapping_factory; | ||
| 292 | |||
| 189 | std::shared_ptr<Keyboard> keyboard; | 293 | std::shared_ptr<Keyboard> keyboard; |
| 294 | std::shared_ptr<Mouse> mouse; | ||
| 295 | std::shared_ptr<GCAdapter> gcadapter; | ||
| 296 | std::shared_ptr<TouchScreen> touch_screen; | ||
| 297 | std::shared_ptr<TasInput::Tas> tas_input; | ||
| 298 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; | ||
| 299 | |||
| 300 | std::shared_ptr<InputFactory> keyboard_factory; | ||
| 301 | std::shared_ptr<InputFactory> mouse_factory; | ||
| 302 | std::shared_ptr<InputFactory> gcadapter_input_factory; | ||
| 303 | std::shared_ptr<InputFactory> touch_screen_factory; | ||
| 304 | std::shared_ptr<InputFactory> udp_client_input_factory; | ||
| 305 | std::shared_ptr<InputFactory> tas_input_factory; | ||
| 306 | |||
| 307 | std::shared_ptr<OutputFactory> keyboard_output_factory; | ||
| 308 | std::shared_ptr<OutputFactory> mouse_output_factory; | ||
| 309 | std::shared_ptr<OutputFactory> gcadapter_output_factory; | ||
| 310 | std::shared_ptr<OutputFactory> udp_client_output_factory; | ||
| 311 | std::shared_ptr<OutputFactory> tas_output_factory; | ||
| 312 | |||
| 190 | #ifdef HAVE_SDL2 | 313 | #ifdef HAVE_SDL2 |
| 191 | std::unique_ptr<SDL::State> sdl; | 314 | std::shared_ptr<SDLDriver> sdl; |
| 315 | std::shared_ptr<InputFactory> sdl_input_factory; | ||
| 316 | std::shared_ptr<OutputFactory> sdl_output_factory; | ||
| 192 | #endif | 317 | #endif |
| 193 | std::shared_ptr<GCButtonFactory> gcbuttons; | ||
| 194 | std::shared_ptr<GCAnalogFactory> gcanalog; | ||
| 195 | std::shared_ptr<GCVibrationFactory> gcvibration; | ||
| 196 | std::shared_ptr<UDPMotionFactory> udpmotion; | ||
| 197 | std::shared_ptr<UDPTouchFactory> udptouch; | ||
| 198 | std::shared_ptr<MouseButtonFactory> mousebuttons; | ||
| 199 | std::shared_ptr<MouseAnalogFactory> mouseanalog; | ||
| 200 | std::shared_ptr<MouseMotionFactory> mousemotion; | ||
| 201 | std::shared_ptr<MouseTouchFactory> mousetouch; | ||
| 202 | std::shared_ptr<TasButtonFactory> tasbuttons; | ||
| 203 | std::shared_ptr<TasAnalogFactory> tasanalog; | ||
| 204 | std::shared_ptr<CemuhookUDP::Client> udp; | ||
| 205 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | ||
| 206 | std::shared_ptr<MouseInput::Mouse> mouse; | ||
| 207 | std::shared_ptr<TasInput::Tas> tas; | ||
| 208 | }; | 318 | }; |
| 209 | 319 | ||
| 210 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} | 320 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} |
| @@ -227,20 +337,28 @@ const Keyboard* InputSubsystem::GetKeyboard() const { | |||
| 227 | return impl->keyboard.get(); | 337 | return impl->keyboard.get(); |
| 228 | } | 338 | } |
| 229 | 339 | ||
| 230 | MouseInput::Mouse* InputSubsystem::GetMouse() { | 340 | Mouse* InputSubsystem::GetMouse() { |
| 231 | return impl->mouse.get(); | 341 | return impl->mouse.get(); |
| 232 | } | 342 | } |
| 233 | 343 | ||
| 234 | const MouseInput::Mouse* InputSubsystem::GetMouse() const { | 344 | const Mouse* InputSubsystem::GetMouse() const { |
| 235 | return impl->mouse.get(); | 345 | return impl->mouse.get(); |
| 236 | } | 346 | } |
| 237 | 347 | ||
| 348 | TouchScreen* InputSubsystem::GetTouchScreen() { | ||
| 349 | return impl->touch_screen.get(); | ||
| 350 | } | ||
| 351 | |||
| 352 | const TouchScreen* InputSubsystem::GetTouchScreen() const { | ||
| 353 | return impl->touch_screen.get(); | ||
| 354 | } | ||
| 355 | |||
| 238 | TasInput::Tas* InputSubsystem::GetTas() { | 356 | TasInput::Tas* InputSubsystem::GetTas() { |
| 239 | return impl->tas.get(); | 357 | return impl->tas_input.get(); |
| 240 | } | 358 | } |
| 241 | 359 | ||
| 242 | const TasInput::Tas* InputSubsystem::GetTas() const { | 360 | const TasInput::Tas* InputSubsystem::GetTas() const { |
| 243 | return impl->tas.get(); | 361 | return impl->tas_input.get(); |
| 244 | } | 362 | } |
| 245 | 363 | ||
| 246 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { | 364 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { |
| @@ -259,100 +377,30 @@ MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPacka | |||
| 259 | return impl->GetMotionMappingForDevice(device); | 377 | return impl->GetMotionMappingForDevice(device); |
| 260 | } | 378 | } |
| 261 | 379 | ||
| 262 | GCAnalogFactory* InputSubsystem::GetGCAnalogs() { | 380 | Common::Input::ButtonNames InputSubsystem::GetButtonName(const Common::ParamPackage& params) const { |
| 263 | return impl->gcanalog.get(); | 381 | return impl->GetButtonName(params); |
| 264 | } | ||
| 265 | |||
| 266 | const GCAnalogFactory* InputSubsystem::GetGCAnalogs() const { | ||
| 267 | return impl->gcanalog.get(); | ||
| 268 | } | ||
| 269 | |||
| 270 | GCButtonFactory* InputSubsystem::GetGCButtons() { | ||
| 271 | return impl->gcbuttons.get(); | ||
| 272 | } | ||
| 273 | |||
| 274 | const GCButtonFactory* InputSubsystem::GetGCButtons() const { | ||
| 275 | return impl->gcbuttons.get(); | ||
| 276 | } | ||
| 277 | |||
| 278 | UDPMotionFactory* InputSubsystem::GetUDPMotions() { | ||
| 279 | return impl->udpmotion.get(); | ||
| 280 | } | ||
| 281 | |||
| 282 | const UDPMotionFactory* InputSubsystem::GetUDPMotions() const { | ||
| 283 | return impl->udpmotion.get(); | ||
| 284 | } | ||
| 285 | |||
| 286 | UDPTouchFactory* InputSubsystem::GetUDPTouch() { | ||
| 287 | return impl->udptouch.get(); | ||
| 288 | } | ||
| 289 | |||
| 290 | const UDPTouchFactory* InputSubsystem::GetUDPTouch() const { | ||
| 291 | return impl->udptouch.get(); | ||
| 292 | } | ||
| 293 | |||
| 294 | MouseButtonFactory* InputSubsystem::GetMouseButtons() { | ||
| 295 | return impl->mousebuttons.get(); | ||
| 296 | } | 382 | } |
| 297 | 383 | ||
| 298 | const MouseButtonFactory* InputSubsystem::GetMouseButtons() const { | 384 | bool InputSubsystem::IsController(const Common::ParamPackage& params) const { |
| 299 | return impl->mousebuttons.get(); | 385 | return impl->IsController(params); |
| 300 | } | 386 | } |
| 301 | 387 | ||
| 302 | MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() { | 388 | void InputSubsystem::ReloadInputDevices() { |
| 303 | return impl->mouseanalog.get(); | 389 | impl->udp_client.get()->ReloadSockets(); |
| 304 | } | ||
| 305 | |||
| 306 | const MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() const { | ||
| 307 | return impl->mouseanalog.get(); | ||
| 308 | } | ||
| 309 | |||
| 310 | MouseMotionFactory* InputSubsystem::GetMouseMotions() { | ||
| 311 | return impl->mousemotion.get(); | ||
| 312 | } | ||
| 313 | |||
| 314 | const MouseMotionFactory* InputSubsystem::GetMouseMotions() const { | ||
| 315 | return impl->mousemotion.get(); | ||
| 316 | } | ||
| 317 | |||
| 318 | MouseTouchFactory* InputSubsystem::GetMouseTouch() { | ||
| 319 | return impl->mousetouch.get(); | ||
| 320 | } | ||
| 321 | |||
| 322 | const MouseTouchFactory* InputSubsystem::GetMouseTouch() const { | ||
| 323 | return impl->mousetouch.get(); | ||
| 324 | } | ||
| 325 | |||
| 326 | TasButtonFactory* InputSubsystem::GetTasButtons() { | ||
| 327 | return impl->tasbuttons.get(); | ||
| 328 | } | ||
| 329 | |||
| 330 | const TasButtonFactory* InputSubsystem::GetTasButtons() const { | ||
| 331 | return impl->tasbuttons.get(); | ||
| 332 | } | ||
| 333 | |||
| 334 | TasAnalogFactory* InputSubsystem::GetTasAnalogs() { | ||
| 335 | return impl->tasanalog.get(); | ||
| 336 | } | 390 | } |
| 337 | 391 | ||
| 338 | const TasAnalogFactory* InputSubsystem::GetTasAnalogs() const { | 392 | void InputSubsystem::BeginMapping(Polling::InputType type) { |
| 339 | return impl->tasanalog.get(); | 393 | impl->BeginConfiguration(); |
| 394 | impl->mapping_factory->BeginMapping(type); | ||
| 340 | } | 395 | } |
| 341 | 396 | ||
| 342 | void InputSubsystem::ReloadInputDevices() { | 397 | const Common::ParamPackage InputSubsystem::GetNextInput() const { |
| 343 | if (!impl->udp) { | 398 | return impl->mapping_factory->GetNextInput(); |
| 344 | return; | ||
| 345 | } | ||
| 346 | impl->udp->ReloadSockets(); | ||
| 347 | } | 399 | } |
| 348 | 400 | ||
| 349 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( | 401 | void InputSubsystem::StopMapping() const { |
| 350 | [[maybe_unused]] Polling::DeviceType type) const { | 402 | impl->EndConfiguration(); |
| 351 | #ifdef HAVE_SDL2 | 403 | impl->mapping_factory->StopMapping(); |
| 352 | return impl->sdl->GetPollers(type); | ||
| 353 | #else | ||
| 354 | return {}; | ||
| 355 | #endif | ||
| 356 | } | 404 | } |
| 357 | 405 | ||
| 358 | std::string GenerateKeyboardParam(int key_code) { | 406 | std::string GenerateKeyboardParam(int key_code) { |