diff options
Diffstat (limited to 'src/input_common/main.cpp')
| -rw-r--r-- | src/input_common/main.cpp | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index a4d7ed645..b2064ef95 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -1,17 +1,17 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | 1 | // SPDX-FileCopyrightText: 2017 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | // Refer to the license.txt file included. | ||
| 4 | 3 | ||
| 5 | #include <memory> | 4 | #include <memory> |
| 6 | #include <thread> | ||
| 7 | #include "common/input.h" | 5 | #include "common/input.h" |
| 8 | #include "common/param_package.h" | 6 | #include "common/param_package.h" |
| 7 | #include "input_common/drivers/camera.h" | ||
| 9 | #include "input_common/drivers/gc_adapter.h" | 8 | #include "input_common/drivers/gc_adapter.h" |
| 10 | #include "input_common/drivers/keyboard.h" | 9 | #include "input_common/drivers/keyboard.h" |
| 11 | #include "input_common/drivers/mouse.h" | 10 | #include "input_common/drivers/mouse.h" |
| 12 | #include "input_common/drivers/tas_input.h" | 11 | #include "input_common/drivers/tas_input.h" |
| 13 | #include "input_common/drivers/touch_screen.h" | 12 | #include "input_common/drivers/touch_screen.h" |
| 14 | #include "input_common/drivers/udp_client.h" | 13 | #include "input_common/drivers/udp_client.h" |
| 14 | #include "input_common/drivers/virtual_amiibo.h" | ||
| 15 | #include "input_common/helpers/stick_from_buttons.h" | 15 | #include "input_common/helpers/stick_from_buttons.h" |
| 16 | #include "input_common/helpers/touch_from_buttons.h" | 16 | #include "input_common/helpers/touch_from_buttons.h" |
| 17 | #include "input_common/input_engine.h" | 17 | #include "input_common/input_engine.h" |
| @@ -79,6 +79,24 @@ struct InputSubsystem::Impl { | |||
| 79 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), | 79 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), |
| 80 | tas_output_factory); | 80 | tas_output_factory); |
| 81 | 81 | ||
| 82 | camera = std::make_shared<Camera>("camera"); | ||
| 83 | camera->SetMappingCallback(mapping_callback); | ||
| 84 | camera_input_factory = std::make_shared<InputFactory>(camera); | ||
| 85 | camera_output_factory = std::make_shared<OutputFactory>(camera); | ||
| 86 | Common::Input::RegisterFactory<Common::Input::InputDevice>(camera->GetEngineName(), | ||
| 87 | camera_input_factory); | ||
| 88 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(camera->GetEngineName(), | ||
| 89 | camera_output_factory); | ||
| 90 | |||
| 91 | virtual_amiibo = std::make_shared<VirtualAmiibo>("virtual_amiibo"); | ||
| 92 | virtual_amiibo->SetMappingCallback(mapping_callback); | ||
| 93 | virtual_amiibo_input_factory = std::make_shared<InputFactory>(virtual_amiibo); | ||
| 94 | virtual_amiibo_output_factory = std::make_shared<OutputFactory>(virtual_amiibo); | ||
| 95 | Common::Input::RegisterFactory<Common::Input::InputDevice>(virtual_amiibo->GetEngineName(), | ||
| 96 | virtual_amiibo_input_factory); | ||
| 97 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(virtual_amiibo->GetEngineName(), | ||
| 98 | virtual_amiibo_output_factory); | ||
| 99 | |||
| 82 | #ifdef HAVE_SDL2 | 100 | #ifdef HAVE_SDL2 |
| 83 | sdl = std::make_shared<SDLDriver>("sdl"); | 101 | sdl = std::make_shared<SDLDriver>("sdl"); |
| 84 | sdl->SetMappingCallback(mapping_callback); | 102 | sdl->SetMappingCallback(mapping_callback); |
| @@ -242,6 +260,28 @@ struct InputSubsystem::Impl { | |||
| 242 | return Common::Input::ButtonNames::Invalid; | 260 | return Common::Input::ButtonNames::Invalid; |
| 243 | } | 261 | } |
| 244 | 262 | ||
| 263 | bool IsStickInverted(const Common::ParamPackage& params) { | ||
| 264 | const std::string engine = params.Get("engine", ""); | ||
| 265 | if (engine == mouse->GetEngineName()) { | ||
| 266 | return mouse->IsStickInverted(params); | ||
| 267 | } | ||
| 268 | if (engine == gcadapter->GetEngineName()) { | ||
| 269 | return gcadapter->IsStickInverted(params); | ||
| 270 | } | ||
| 271 | if (engine == udp_client->GetEngineName()) { | ||
| 272 | return udp_client->IsStickInverted(params); | ||
| 273 | } | ||
| 274 | if (engine == tas_input->GetEngineName()) { | ||
| 275 | return tas_input->IsStickInverted(params); | ||
| 276 | } | ||
| 277 | #ifdef HAVE_SDL2 | ||
| 278 | if (engine == sdl->GetEngineName()) { | ||
| 279 | return sdl->IsStickInverted(params); | ||
| 280 | } | ||
| 281 | #endif | ||
| 282 | return false; | ||
| 283 | } | ||
| 284 | |||
| 245 | bool IsController(const Common::ParamPackage& params) { | 285 | bool IsController(const Common::ParamPackage& params) { |
| 246 | const std::string engine = params.Get("engine", ""); | 286 | const std::string engine = params.Get("engine", ""); |
| 247 | if (engine == mouse->GetEngineName()) { | 287 | if (engine == mouse->GetEngineName()) { |
| @@ -296,6 +336,8 @@ struct InputSubsystem::Impl { | |||
| 296 | std::shared_ptr<TouchScreen> touch_screen; | 336 | std::shared_ptr<TouchScreen> touch_screen; |
| 297 | std::shared_ptr<TasInput::Tas> tas_input; | 337 | std::shared_ptr<TasInput::Tas> tas_input; |
| 298 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; | 338 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; |
| 339 | std::shared_ptr<Camera> camera; | ||
| 340 | std::shared_ptr<VirtualAmiibo> virtual_amiibo; | ||
| 299 | 341 | ||
| 300 | std::shared_ptr<InputFactory> keyboard_factory; | 342 | std::shared_ptr<InputFactory> keyboard_factory; |
| 301 | std::shared_ptr<InputFactory> mouse_factory; | 343 | std::shared_ptr<InputFactory> mouse_factory; |
| @@ -303,12 +345,16 @@ struct InputSubsystem::Impl { | |||
| 303 | std::shared_ptr<InputFactory> touch_screen_factory; | 345 | std::shared_ptr<InputFactory> touch_screen_factory; |
| 304 | std::shared_ptr<InputFactory> udp_client_input_factory; | 346 | std::shared_ptr<InputFactory> udp_client_input_factory; |
| 305 | std::shared_ptr<InputFactory> tas_input_factory; | 347 | std::shared_ptr<InputFactory> tas_input_factory; |
| 348 | std::shared_ptr<InputFactory> camera_input_factory; | ||
| 349 | std::shared_ptr<InputFactory> virtual_amiibo_input_factory; | ||
| 306 | 350 | ||
| 307 | std::shared_ptr<OutputFactory> keyboard_output_factory; | 351 | std::shared_ptr<OutputFactory> keyboard_output_factory; |
| 308 | std::shared_ptr<OutputFactory> mouse_output_factory; | 352 | std::shared_ptr<OutputFactory> mouse_output_factory; |
| 309 | std::shared_ptr<OutputFactory> gcadapter_output_factory; | 353 | std::shared_ptr<OutputFactory> gcadapter_output_factory; |
| 310 | std::shared_ptr<OutputFactory> udp_client_output_factory; | 354 | std::shared_ptr<OutputFactory> udp_client_output_factory; |
| 311 | std::shared_ptr<OutputFactory> tas_output_factory; | 355 | std::shared_ptr<OutputFactory> tas_output_factory; |
| 356 | std::shared_ptr<OutputFactory> camera_output_factory; | ||
| 357 | std::shared_ptr<OutputFactory> virtual_amiibo_output_factory; | ||
| 312 | 358 | ||
| 313 | #ifdef HAVE_SDL2 | 359 | #ifdef HAVE_SDL2 |
| 314 | std::shared_ptr<SDLDriver> sdl; | 360 | std::shared_ptr<SDLDriver> sdl; |
| @@ -361,6 +407,22 @@ const TasInput::Tas* InputSubsystem::GetTas() const { | |||
| 361 | return impl->tas_input.get(); | 407 | return impl->tas_input.get(); |
| 362 | } | 408 | } |
| 363 | 409 | ||
| 410 | Camera* InputSubsystem::GetCamera() { | ||
| 411 | return impl->camera.get(); | ||
| 412 | } | ||
| 413 | |||
| 414 | const Camera* InputSubsystem::GetCamera() const { | ||
| 415 | return impl->camera.get(); | ||
| 416 | } | ||
| 417 | |||
| 418 | VirtualAmiibo* InputSubsystem::GetVirtualAmiibo() { | ||
| 419 | return impl->virtual_amiibo.get(); | ||
| 420 | } | ||
| 421 | |||
| 422 | const VirtualAmiibo* InputSubsystem::GetVirtualAmiibo() const { | ||
| 423 | return impl->virtual_amiibo.get(); | ||
| 424 | } | ||
| 425 | |||
| 364 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { | 426 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { |
| 365 | return impl->GetInputDevices(); | 427 | return impl->GetInputDevices(); |
| 366 | } | 428 | } |
| @@ -385,6 +447,13 @@ bool InputSubsystem::IsController(const Common::ParamPackage& params) const { | |||
| 385 | return impl->IsController(params); | 447 | return impl->IsController(params); |
| 386 | } | 448 | } |
| 387 | 449 | ||
| 450 | bool InputSubsystem::IsStickInverted(const Common::ParamPackage& params) const { | ||
| 451 | if (params.Has("axis_x") && params.Has("axis_y")) { | ||
| 452 | return impl->IsStickInverted(params); | ||
| 453 | } | ||
| 454 | return false; | ||
| 455 | } | ||
| 456 | |||
| 388 | void InputSubsystem::ReloadInputDevices() { | 457 | void InputSubsystem::ReloadInputDevices() { |
| 389 | impl->udp_client.get()->ReloadSockets(); | 458 | impl->udp_client.get()->ReloadSockets(); |
| 390 | } | 459 | } |