diff options
| author | 2022-12-18 13:24:02 -0600 | |
|---|---|---|
| committer | 2022-12-18 15:33:11 -0600 | |
| commit | cf01a507fb3c49791daf2420eec9e7e9e41a9d6b (patch) | |
| tree | 75126aff0497c95b7db36533e01f49620bdc5c8b /src/input_common/main.cpp | |
| parent | Enable compiler optimizations and enforce x86-64-v2 on GCC/Clang (#9442) (diff) | |
| download | yuzu-cf01a507fb3c49791daf2420eec9e7e9e41a9d6b.tar.gz yuzu-cf01a507fb3c49791daf2420eec9e7e9e41a9d6b.tar.xz yuzu-cf01a507fb3c49791daf2420eec9e7e9e41a9d6b.zip | |
input_common: Cleanup project
Diffstat (limited to 'src/input_common/main.cpp')
| -rw-r--r-- | src/input_common/main.cpp | 283 |
1 files changed, 83 insertions, 200 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 75b856c95..86deb4c7c 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -26,79 +26,33 @@ | |||
| 26 | namespace InputCommon { | 26 | namespace InputCommon { |
| 27 | 27 | ||
| 28 | struct InputSubsystem::Impl { | 28 | struct InputSubsystem::Impl { |
| 29 | void Initialize() { | 29 | template <typename Engine> |
| 30 | mapping_factory = std::make_shared<MappingFactory>(); | 30 | void RegisterEngine(std::string name, std::shared_ptr<Engine>& engine) { |
| 31 | MappingCallback mapping_callback{[this](const MappingData& data) { RegisterInput(data); }}; | 31 | MappingCallback mapping_callback{[this](const MappingData& data) { RegisterInput(data); }}; |
| 32 | 32 | ||
| 33 | keyboard = std::make_shared<Keyboard>("keyboard"); | 33 | engine = std::make_shared<Engine>(name); |
| 34 | keyboard->SetMappingCallback(mapping_callback); | 34 | engine->SetMappingCallback(mapping_callback); |
| 35 | keyboard_factory = std::make_shared<InputFactory>(keyboard); | 35 | |
| 36 | keyboard_output_factory = std::make_shared<OutputFactory>(keyboard); | 36 | std::shared_ptr<InputFactory> input_factory = std::make_shared<InputFactory>(engine); |
| 37 | Common::Input::RegisterInputFactory(keyboard->GetEngineName(), keyboard_factory); | 37 | std::shared_ptr<OutputFactory> output_factory = std::make_shared<OutputFactory>(engine); |
| 38 | Common::Input::RegisterOutputFactory(keyboard->GetEngineName(), keyboard_output_factory); | 38 | Common::Input::RegisterInputFactory(engine->GetEngineName(), std::move(input_factory)); |
| 39 | 39 | Common::Input::RegisterOutputFactory(engine->GetEngineName(), std::move(output_factory)); | |
| 40 | mouse = std::make_shared<Mouse>("mouse"); | 40 | } |
| 41 | mouse->SetMappingCallback(mapping_callback); | ||
| 42 | mouse_factory = std::make_shared<InputFactory>(mouse); | ||
| 43 | mouse_output_factory = std::make_shared<OutputFactory>(mouse); | ||
| 44 | Common::Input::RegisterInputFactory(mouse->GetEngineName(), mouse_factory); | ||
| 45 | Common::Input::RegisterOutputFactory(mouse->GetEngineName(), mouse_output_factory); | ||
| 46 | |||
| 47 | touch_screen = std::make_shared<TouchScreen>("touch"); | ||
| 48 | touch_screen_factory = std::make_shared<InputFactory>(touch_screen); | ||
| 49 | Common::Input::RegisterInputFactory(touch_screen->GetEngineName(), touch_screen_factory); | ||
| 50 | |||
| 51 | gcadapter = std::make_shared<GCAdapter>("gcpad"); | ||
| 52 | gcadapter->SetMappingCallback(mapping_callback); | ||
| 53 | gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter); | ||
| 54 | gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter); | ||
| 55 | Common::Input::RegisterInputFactory(gcadapter->GetEngineName(), gcadapter_input_factory); | ||
| 56 | Common::Input::RegisterOutputFactory(gcadapter->GetEngineName(), gcadapter_output_factory); | ||
| 57 | |||
| 58 | udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); | ||
| 59 | udp_client->SetMappingCallback(mapping_callback); | ||
| 60 | udp_client_input_factory = std::make_shared<InputFactory>(udp_client); | ||
| 61 | udp_client_output_factory = std::make_shared<OutputFactory>(udp_client); | ||
| 62 | Common::Input::RegisterInputFactory(udp_client->GetEngineName(), udp_client_input_factory); | ||
| 63 | Common::Input::RegisterOutputFactory(udp_client->GetEngineName(), | ||
| 64 | udp_client_output_factory); | ||
| 65 | |||
| 66 | tas_input = std::make_shared<TasInput::Tas>("tas"); | ||
| 67 | tas_input->SetMappingCallback(mapping_callback); | ||
| 68 | tas_input_factory = std::make_shared<InputFactory>(tas_input); | ||
| 69 | tas_output_factory = std::make_shared<OutputFactory>(tas_input); | ||
| 70 | Common::Input::RegisterInputFactory(tas_input->GetEngineName(), tas_input_factory); | ||
| 71 | Common::Input::RegisterOutputFactory(tas_input->GetEngineName(), tas_output_factory); | ||
| 72 | |||
| 73 | camera = std::make_shared<Camera>("camera"); | ||
| 74 | camera->SetMappingCallback(mapping_callback); | ||
| 75 | camera_input_factory = std::make_shared<InputFactory>(camera); | ||
| 76 | camera_output_factory = std::make_shared<OutputFactory>(camera); | ||
| 77 | Common::Input::RegisterInputFactory(camera->GetEngineName(), camera_input_factory); | ||
| 78 | Common::Input::RegisterOutputFactory(camera->GetEngineName(), camera_output_factory); | ||
| 79 | |||
| 80 | virtual_amiibo = std::make_shared<VirtualAmiibo>("virtual_amiibo"); | ||
| 81 | virtual_amiibo->SetMappingCallback(mapping_callback); | ||
| 82 | virtual_amiibo_input_factory = std::make_shared<InputFactory>(virtual_amiibo); | ||
| 83 | virtual_amiibo_output_factory = std::make_shared<OutputFactory>(virtual_amiibo); | ||
| 84 | Common::Input::RegisterInputFactory(virtual_amiibo->GetEngineName(), | ||
| 85 | virtual_amiibo_input_factory); | ||
| 86 | Common::Input::RegisterOutputFactory(virtual_amiibo->GetEngineName(), | ||
| 87 | virtual_amiibo_output_factory); | ||
| 88 | |||
| 89 | virtual_gamepad = std::make_shared<VirtualGamepad>("virtual_gamepad"); | ||
| 90 | virtual_gamepad->SetMappingCallback(mapping_callback); | ||
| 91 | virtual_gamepad_input_factory = std::make_shared<InputFactory>(virtual_gamepad); | ||
| 92 | Common::Input::RegisterInputFactory(virtual_gamepad->GetEngineName(), | ||
| 93 | virtual_gamepad_input_factory); | ||
| 94 | 41 | ||
| 42 | void Initialize() { | ||
| 43 | mapping_factory = std::make_shared<MappingFactory>(); | ||
| 44 | |||
| 45 | RegisterEngine("keyboard", keyboard); | ||
| 46 | RegisterEngine("mouse", mouse); | ||
| 47 | RegisterEngine("touch", touch_screen); | ||
| 48 | RegisterEngine("gcpad", gcadapter); | ||
| 49 | RegisterEngine("cemuhookudp", udp_client); | ||
| 50 | RegisterEngine("tas", tas_input); | ||
| 51 | RegisterEngine("camera", camera); | ||
| 52 | RegisterEngine("virtual_amiibo", virtual_amiibo); | ||
| 53 | RegisterEngine("virtual_gamepad", virtual_gamepad); | ||
| 95 | #ifdef HAVE_SDL2 | 54 | #ifdef HAVE_SDL2 |
| 96 | sdl = std::make_shared<SDLDriver>("sdl"); | 55 | RegisterEngine("sdl", sdl); |
| 97 | sdl->SetMappingCallback(mapping_callback); | ||
| 98 | sdl_input_factory = std::make_shared<InputFactory>(sdl); | ||
| 99 | sdl_output_factory = std::make_shared<OutputFactory>(sdl); | ||
| 100 | Common::Input::RegisterInputFactory(sdl->GetEngineName(), sdl_input_factory); | ||
| 101 | Common::Input::RegisterOutputFactory(sdl->GetEngineName(), sdl_output_factory); | ||
| 102 | #endif | 56 | #endif |
| 103 | 57 | ||
| 104 | Common::Input::RegisterInputFactory("touch_from_button", | 58 | Common::Input::RegisterInputFactory("touch_from_button", |
| @@ -107,45 +61,25 @@ struct InputSubsystem::Impl { | |||
| 107 | std::make_shared<StickFromButton>()); | 61 | std::make_shared<StickFromButton>()); |
| 108 | } | 62 | } |
| 109 | 63 | ||
| 110 | void Shutdown() { | 64 | template <typename Engine> |
| 111 | Common::Input::UnregisterInputFactory(keyboard->GetEngineName()); | 65 | void UnregisterEngine(std::shared_ptr<Engine>& engine) { |
| 112 | Common::Input::UnregisterOutputFactory(keyboard->GetEngineName()); | 66 | Common::Input::UnregisterInputFactory(engine->GetEngineName()); |
| 113 | keyboard.reset(); | 67 | Common::Input::UnregisterOutputFactory(engine->GetEngineName()); |
| 114 | 68 | engine.reset(); | |
| 115 | Common::Input::UnregisterInputFactory(mouse->GetEngineName()); | 69 | } |
| 116 | Common::Input::UnregisterOutputFactory(mouse->GetEngineName()); | ||
| 117 | mouse.reset(); | ||
| 118 | |||
| 119 | Common::Input::UnregisterInputFactory(touch_screen->GetEngineName()); | ||
| 120 | touch_screen.reset(); | ||
| 121 | |||
| 122 | Common::Input::UnregisterInputFactory(gcadapter->GetEngineName()); | ||
| 123 | Common::Input::UnregisterOutputFactory(gcadapter->GetEngineName()); | ||
| 124 | gcadapter.reset(); | ||
| 125 | |||
| 126 | Common::Input::UnregisterInputFactory(udp_client->GetEngineName()); | ||
| 127 | Common::Input::UnregisterOutputFactory(udp_client->GetEngineName()); | ||
| 128 | udp_client.reset(); | ||
| 129 | |||
| 130 | Common::Input::UnregisterInputFactory(tas_input->GetEngineName()); | ||
| 131 | Common::Input::UnregisterOutputFactory(tas_input->GetEngineName()); | ||
| 132 | tas_input.reset(); | ||
| 133 | |||
| 134 | Common::Input::UnregisterInputFactory(camera->GetEngineName()); | ||
| 135 | Common::Input::UnregisterOutputFactory(camera->GetEngineName()); | ||
| 136 | camera.reset(); | ||
| 137 | |||
| 138 | Common::Input::UnregisterInputFactory(virtual_amiibo->GetEngineName()); | ||
| 139 | Common::Input::UnregisterOutputFactory(virtual_amiibo->GetEngineName()); | ||
| 140 | virtual_amiibo.reset(); | ||
| 141 | |||
| 142 | Common::Input::UnregisterInputFactory(virtual_gamepad->GetEngineName()); | ||
| 143 | virtual_gamepad.reset(); | ||
| 144 | 70 | ||
| 71 | void Shutdown() { | ||
| 72 | UnregisterEngine(keyboard); | ||
| 73 | UnregisterEngine(mouse); | ||
| 74 | UnregisterEngine(touch_screen); | ||
| 75 | UnregisterEngine(gcadapter); | ||
| 76 | UnregisterEngine(udp_client); | ||
| 77 | UnregisterEngine(tas_input); | ||
| 78 | UnregisterEngine(camera); | ||
| 79 | UnregisterEngine(virtual_amiibo); | ||
| 80 | UnregisterEngine(virtual_gamepad); | ||
| 145 | #ifdef HAVE_SDL2 | 81 | #ifdef HAVE_SDL2 |
| 146 | Common::Input::UnregisterInputFactory(sdl->GetEngineName()); | 82 | UnregisterEngine(sdl); |
| 147 | Common::Input::UnregisterOutputFactory(sdl->GetEngineName()); | ||
| 148 | sdl.reset(); | ||
| 149 | #endif | 83 | #endif |
| 150 | 84 | ||
| 151 | Common::Input::UnregisterInputFactory("touch_from_button"); | 85 | Common::Input::UnregisterInputFactory("touch_from_button"); |
| @@ -173,117 +107,86 @@ struct InputSubsystem::Impl { | |||
| 173 | return devices; | 107 | return devices; |
| 174 | } | 108 | } |
| 175 | 109 | ||
| 176 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice( | 110 | [[nodiscard]] std::shared_ptr<InputEngine> GetInputEngine( |
| 177 | const Common::ParamPackage& params) const { | 111 | const Common::ParamPackage& params) const { |
| 178 | if (!params.Has("engine") || params.Get("engine", "") == "any") { | 112 | if (!params.Has("engine") || params.Get("engine", "") == "any") { |
| 179 | return {}; | 113 | return nullptr; |
| 180 | } | 114 | } |
| 181 | const std::string engine = params.Get("engine", ""); | 115 | const std::string engine = params.Get("engine", ""); |
| 116 | if (engine == keyboard->GetEngineName()) { | ||
| 117 | return keyboard; | ||
| 118 | } | ||
| 182 | if (engine == mouse->GetEngineName()) { | 119 | if (engine == mouse->GetEngineName()) { |
| 183 | return mouse->GetAnalogMappingForDevice(params); | 120 | return mouse; |
| 184 | } | 121 | } |
| 185 | if (engine == gcadapter->GetEngineName()) { | 122 | if (engine == gcadapter->GetEngineName()) { |
| 186 | return gcadapter->GetAnalogMappingForDevice(params); | 123 | return gcadapter; |
| 187 | } | 124 | } |
| 188 | if (engine == udp_client->GetEngineName()) { | 125 | if (engine == udp_client->GetEngineName()) { |
| 189 | return udp_client->GetAnalogMappingForDevice(params); | 126 | return udp_client; |
| 190 | } | ||
| 191 | if (engine == tas_input->GetEngineName()) { | ||
| 192 | return tas_input->GetAnalogMappingForDevice(params); | ||
| 193 | } | 127 | } |
| 194 | #ifdef HAVE_SDL2 | 128 | #ifdef HAVE_SDL2 |
| 195 | if (engine == sdl->GetEngineName()) { | 129 | if (engine == sdl->GetEngineName()) { |
| 196 | return sdl->GetAnalogMappingForDevice(params); | 130 | return sdl; |
| 197 | } | 131 | } |
| 198 | #endif | 132 | #endif |
| 199 | return {}; | 133 | return nullptr; |
| 200 | } | 134 | } |
| 201 | 135 | ||
| 202 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice( | 136 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice( |
| 203 | const Common::ParamPackage& params) const { | 137 | const Common::ParamPackage& params) const { |
| 204 | if (!params.Has("engine") || params.Get("engine", "") == "any") { | 138 | const auto input_engine = GetInputEngine(params); |
| 139 | |||
| 140 | if (input_engine == nullptr) { | ||
| 205 | return {}; | 141 | return {}; |
| 206 | } | 142 | } |
| 207 | const std::string engine = params.Get("engine", ""); | 143 | |
| 208 | if (engine == gcadapter->GetEngineName()) { | 144 | return input_engine->GetAnalogMappingForDevice(params); |
| 209 | return gcadapter->GetButtonMappingForDevice(params); | 145 | } |
| 210 | } | 146 | |
| 211 | if (engine == udp_client->GetEngineName()) { | 147 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice( |
| 212 | return udp_client->GetButtonMappingForDevice(params); | 148 | const Common::ParamPackage& params) const { |
| 213 | } | 149 | const auto input_engine = GetInputEngine(params); |
| 214 | if (engine == tas_input->GetEngineName()) { | 150 | |
| 215 | return tas_input->GetButtonMappingForDevice(params); | 151 | if (input_engine == nullptr) { |
| 216 | } | 152 | return {}; |
| 217 | #ifdef HAVE_SDL2 | ||
| 218 | if (engine == sdl->GetEngineName()) { | ||
| 219 | return sdl->GetButtonMappingForDevice(params); | ||
| 220 | } | 153 | } |
| 221 | #endif | 154 | |
| 222 | return {}; | 155 | return input_engine->GetButtonMappingForDevice(params); |
| 223 | } | 156 | } |
| 224 | 157 | ||
| 225 | [[nodiscard]] MotionMapping GetMotionMappingForDevice( | 158 | [[nodiscard]] MotionMapping GetMotionMappingForDevice( |
| 226 | const Common::ParamPackage& params) const { | 159 | const Common::ParamPackage& params) const { |
| 227 | if (!params.Has("engine") || params.Get("engine", "") == "any") { | 160 | const auto input_engine = GetInputEngine(params); |
| 161 | |||
| 162 | if (input_engine == nullptr) { | ||
| 228 | return {}; | 163 | return {}; |
| 229 | } | 164 | } |
| 230 | const std::string engine = params.Get("engine", ""); | 165 | |
| 231 | if (engine == udp_client->GetEngineName()) { | 166 | return input_engine->GetMotionMappingForDevice(params); |
| 232 | return udp_client->GetMotionMappingForDevice(params); | ||
| 233 | } | ||
| 234 | #ifdef HAVE_SDL2 | ||
| 235 | if (engine == sdl->GetEngineName()) { | ||
| 236 | return sdl->GetMotionMappingForDevice(params); | ||
| 237 | } | ||
| 238 | #endif | ||
| 239 | return {}; | ||
| 240 | } | 167 | } |
| 241 | 168 | ||
| 242 | Common::Input::ButtonNames GetButtonName(const Common::ParamPackage& params) const { | 169 | Common::Input::ButtonNames GetButtonName(const Common::ParamPackage& params) const { |
| 243 | if (!params.Has("engine") || params.Get("engine", "") == "any") { | 170 | if (!params.Has("engine") || params.Get("engine", "") == "any") { |
| 244 | return Common::Input::ButtonNames::Undefined; | 171 | return Common::Input::ButtonNames::Undefined; |
| 245 | } | 172 | } |
| 246 | const std::string engine = params.Get("engine", ""); | 173 | const auto input_engine = GetInputEngine(params); |
| 247 | if (engine == mouse->GetEngineName()) { | 174 | |
| 248 | return mouse->GetUIName(params); | 175 | if (input_engine == nullptr) { |
| 249 | } | 176 | return Common::Input::ButtonNames::Invalid; |
| 250 | if (engine == gcadapter->GetEngineName()) { | ||
| 251 | return gcadapter->GetUIName(params); | ||
| 252 | } | ||
| 253 | if (engine == udp_client->GetEngineName()) { | ||
| 254 | return udp_client->GetUIName(params); | ||
| 255 | } | ||
| 256 | if (engine == tas_input->GetEngineName()) { | ||
| 257 | return tas_input->GetUIName(params); | ||
| 258 | } | ||
| 259 | #ifdef HAVE_SDL2 | ||
| 260 | if (engine == sdl->GetEngineName()) { | ||
| 261 | return sdl->GetUIName(params); | ||
| 262 | } | 177 | } |
| 263 | #endif | 178 | |
| 264 | return Common::Input::ButtonNames::Invalid; | 179 | return input_engine->GetUIName(params); |
| 265 | } | 180 | } |
| 266 | 181 | ||
| 267 | bool IsStickInverted(const Common::ParamPackage& params) { | 182 | bool IsStickInverted(const Common::ParamPackage& params) { |
| 268 | const std::string engine = params.Get("engine", ""); | 183 | const auto input_engine = GetInputEngine(params); |
| 269 | if (engine == mouse->GetEngineName()) { | 184 | |
| 270 | return mouse->IsStickInverted(params); | 185 | if (input_engine == nullptr) { |
| 271 | } | 186 | return false; |
| 272 | if (engine == gcadapter->GetEngineName()) { | ||
| 273 | return gcadapter->IsStickInverted(params); | ||
| 274 | } | ||
| 275 | if (engine == udp_client->GetEngineName()) { | ||
| 276 | return udp_client->IsStickInverted(params); | ||
| 277 | } | ||
| 278 | if (engine == tas_input->GetEngineName()) { | ||
| 279 | return tas_input->IsStickInverted(params); | ||
| 280 | } | ||
| 281 | #ifdef HAVE_SDL2 | ||
| 282 | if (engine == sdl->GetEngineName()) { | ||
| 283 | return sdl->IsStickInverted(params); | ||
| 284 | } | 187 | } |
| 285 | #endif | 188 | |
| 286 | return false; | 189 | return input_engine->IsStickInverted(params); |
| 287 | } | 190 | } |
| 288 | 191 | ||
| 289 | bool IsController(const Common::ParamPackage& params) { | 192 | bool IsController(const Common::ParamPackage& params) { |
| @@ -353,28 +256,8 @@ struct InputSubsystem::Impl { | |||
| 353 | std::shared_ptr<VirtualAmiibo> virtual_amiibo; | 256 | std::shared_ptr<VirtualAmiibo> virtual_amiibo; |
| 354 | std::shared_ptr<VirtualGamepad> virtual_gamepad; | 257 | std::shared_ptr<VirtualGamepad> virtual_gamepad; |
| 355 | 258 | ||
| 356 | std::shared_ptr<InputFactory> keyboard_factory; | ||
| 357 | std::shared_ptr<InputFactory> mouse_factory; | ||
| 358 | std::shared_ptr<InputFactory> gcadapter_input_factory; | ||
| 359 | std::shared_ptr<InputFactory> touch_screen_factory; | ||
| 360 | std::shared_ptr<InputFactory> udp_client_input_factory; | ||
| 361 | std::shared_ptr<InputFactory> tas_input_factory; | ||
| 362 | std::shared_ptr<InputFactory> camera_input_factory; | ||
| 363 | std::shared_ptr<InputFactory> virtual_amiibo_input_factory; | ||
| 364 | std::shared_ptr<InputFactory> virtual_gamepad_input_factory; | ||
| 365 | |||
| 366 | std::shared_ptr<OutputFactory> keyboard_output_factory; | ||
| 367 | std::shared_ptr<OutputFactory> mouse_output_factory; | ||
| 368 | std::shared_ptr<OutputFactory> gcadapter_output_factory; | ||
| 369 | std::shared_ptr<OutputFactory> udp_client_output_factory; | ||
| 370 | std::shared_ptr<OutputFactory> tas_output_factory; | ||
| 371 | std::shared_ptr<OutputFactory> camera_output_factory; | ||
| 372 | std::shared_ptr<OutputFactory> virtual_amiibo_output_factory; | ||
| 373 | |||
| 374 | #ifdef HAVE_SDL2 | 259 | #ifdef HAVE_SDL2 |
| 375 | std::shared_ptr<SDLDriver> sdl; | 260 | std::shared_ptr<SDLDriver> sdl; |
| 376 | std::shared_ptr<InputFactory> sdl_input_factory; | ||
| 377 | std::shared_ptr<OutputFactory> sdl_output_factory; | ||
| 378 | #endif | 261 | #endif |
| 379 | }; | 262 | }; |
| 380 | 263 | ||