diff options
| author | 2022-12-17 17:16:13 -0800 | |
|---|---|---|
| committer | 2022-12-17 17:16:13 -0800 | |
| commit | 48108a8c9b28e08f86aab5c2ad41414e455f4706 (patch) | |
| tree | 2dc3ff390a17ebdee32958eac619632cef424fe4 /src/core/hid/emulated_controller.cpp | |
| parent | Merge pull request #7450 from FernandoS27/ndc-vulkan (diff) | |
| parent | input_common: Add virtual gamepad (diff) | |
| download | yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.gz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.xz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.zip | |
Merge pull request #9456 from german77/virtual_gamepad
input_common: Add virtual gamepad
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 67969e938..f238d6ccd 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -145,6 +145,7 @@ void EmulatedController::LoadDevices() { | |||
| 145 | output_params[3].Set("output", true); | 145 | output_params[3].Set("output", true); |
| 146 | 146 | ||
| 147 | LoadTASParams(); | 147 | LoadTASParams(); |
| 148 | LoadVirtualGamepadParams(); | ||
| 148 | 149 | ||
| 149 | std::ranges::transform(button_params, button_devices.begin(), Common::Input::CreateInputDevice); | 150 | std::ranges::transform(button_params, button_devices.begin(), Common::Input::CreateInputDevice); |
| 150 | std::ranges::transform(stick_params, stick_devices.begin(), Common::Input::CreateInputDevice); | 151 | std::ranges::transform(stick_params, stick_devices.begin(), Common::Input::CreateInputDevice); |
| @@ -163,6 +164,12 @@ void EmulatedController::LoadDevices() { | |||
| 163 | Common::Input::CreateInputDevice); | 164 | Common::Input::CreateInputDevice); |
| 164 | std::ranges::transform(tas_stick_params, tas_stick_devices.begin(), | 165 | std::ranges::transform(tas_stick_params, tas_stick_devices.begin(), |
| 165 | Common::Input::CreateInputDevice); | 166 | Common::Input::CreateInputDevice); |
| 167 | |||
| 168 | // Initialize virtual gamepad devices | ||
| 169 | std::ranges::transform(virtual_button_params, virtual_button_devices.begin(), | ||
| 170 | Common::Input::CreateInputDevice); | ||
| 171 | std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(), | ||
| 172 | Common::Input::CreateInputDevice); | ||
| 166 | } | 173 | } |
| 167 | 174 | ||
| 168 | void EmulatedController::LoadTASParams() { | 175 | void EmulatedController::LoadTASParams() { |
| @@ -205,6 +212,46 @@ void EmulatedController::LoadTASParams() { | |||
| 205 | tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3); | 212 | tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3); |
| 206 | } | 213 | } |
| 207 | 214 | ||
| 215 | void EmulatedController::LoadVirtualGamepadParams() { | ||
| 216 | const auto player_index = NpadIdTypeToIndex(npad_id_type); | ||
| 217 | Common::ParamPackage common_params{}; | ||
| 218 | common_params.Set("engine", "virtual_gamepad"); | ||
| 219 | common_params.Set("port", static_cast<int>(player_index)); | ||
| 220 | for (auto& param : virtual_button_params) { | ||
| 221 | param = common_params; | ||
| 222 | } | ||
| 223 | for (auto& param : virtual_stick_params) { | ||
| 224 | param = common_params; | ||
| 225 | } | ||
| 226 | |||
| 227 | // TODO(german77): Replace this with an input profile or something better | ||
| 228 | virtual_button_params[Settings::NativeButton::A].Set("button", 0); | ||
| 229 | virtual_button_params[Settings::NativeButton::B].Set("button", 1); | ||
| 230 | virtual_button_params[Settings::NativeButton::X].Set("button", 2); | ||
| 231 | virtual_button_params[Settings::NativeButton::Y].Set("button", 3); | ||
| 232 | virtual_button_params[Settings::NativeButton::LStick].Set("button", 4); | ||
| 233 | virtual_button_params[Settings::NativeButton::RStick].Set("button", 5); | ||
| 234 | virtual_button_params[Settings::NativeButton::L].Set("button", 6); | ||
| 235 | virtual_button_params[Settings::NativeButton::R].Set("button", 7); | ||
| 236 | virtual_button_params[Settings::NativeButton::ZL].Set("button", 8); | ||
| 237 | virtual_button_params[Settings::NativeButton::ZR].Set("button", 9); | ||
| 238 | virtual_button_params[Settings::NativeButton::Plus].Set("button", 10); | ||
| 239 | virtual_button_params[Settings::NativeButton::Minus].Set("button", 11); | ||
| 240 | virtual_button_params[Settings::NativeButton::DLeft].Set("button", 12); | ||
| 241 | virtual_button_params[Settings::NativeButton::DUp].Set("button", 13); | ||
| 242 | virtual_button_params[Settings::NativeButton::DRight].Set("button", 14); | ||
| 243 | virtual_button_params[Settings::NativeButton::DDown].Set("button", 15); | ||
| 244 | virtual_button_params[Settings::NativeButton::SL].Set("button", 16); | ||
| 245 | virtual_button_params[Settings::NativeButton::SR].Set("button", 17); | ||
| 246 | virtual_button_params[Settings::NativeButton::Home].Set("button", 18); | ||
| 247 | virtual_button_params[Settings::NativeButton::Screenshot].Set("button", 19); | ||
| 248 | |||
| 249 | virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0); | ||
| 250 | virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1); | ||
| 251 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("axis_x", 2); | ||
| 252 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3); | ||
| 253 | } | ||
| 254 | |||
| 208 | void EmulatedController::ReloadInput() { | 255 | void EmulatedController::ReloadInput() { |
| 209 | // If you load any device here add the equivalent to the UnloadInput() function | 256 | // If you load any device here add the equivalent to the UnloadInput() function |
| 210 | LoadDevices(); | 257 | LoadDevices(); |
| @@ -322,6 +369,35 @@ void EmulatedController::ReloadInput() { | |||
| 322 | }, | 369 | }, |
| 323 | }); | 370 | }); |
| 324 | } | 371 | } |
| 372 | |||
| 373 | // Use a common UUID for Virtual Gamepad | ||
| 374 | static constexpr Common::UUID VIRTUAL_UUID = Common::UUID{ | ||
| 375 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; | ||
| 376 | |||
| 377 | // Register virtual devices. No need to force update | ||
| 378 | for (std::size_t index = 0; index < virtual_button_devices.size(); ++index) { | ||
| 379 | if (!virtual_button_devices[index]) { | ||
| 380 | continue; | ||
| 381 | } | ||
| 382 | virtual_button_devices[index]->SetCallback({ | ||
| 383 | .on_change = | ||
| 384 | [this, index](const Common::Input::CallbackStatus& callback) { | ||
| 385 | SetButton(callback, index, VIRTUAL_UUID); | ||
| 386 | }, | ||
| 387 | }); | ||
| 388 | } | ||
| 389 | |||
| 390 | for (std::size_t index = 0; index < virtual_stick_devices.size(); ++index) { | ||
| 391 | if (!virtual_stick_devices[index]) { | ||
| 392 | continue; | ||
| 393 | } | ||
| 394 | virtual_stick_devices[index]->SetCallback({ | ||
| 395 | .on_change = | ||
| 396 | [this, index](const Common::Input::CallbackStatus& callback) { | ||
| 397 | SetStick(callback, index, VIRTUAL_UUID); | ||
| 398 | }, | ||
| 399 | }); | ||
| 400 | } | ||
| 325 | } | 401 | } |
| 326 | 402 | ||
| 327 | void EmulatedController::UnloadInput() { | 403 | void EmulatedController::UnloadInput() { |
| @@ -349,6 +425,12 @@ void EmulatedController::UnloadInput() { | |||
| 349 | for (auto& stick : tas_stick_devices) { | 425 | for (auto& stick : tas_stick_devices) { |
| 350 | stick.reset(); | 426 | stick.reset(); |
| 351 | } | 427 | } |
| 428 | for (auto& button : virtual_button_devices) { | ||
| 429 | button.reset(); | ||
| 430 | } | ||
| 431 | for (auto& stick : virtual_stick_devices) { | ||
| 432 | stick.reset(); | ||
| 433 | } | ||
| 352 | camera_devices.reset(); | 434 | camera_devices.reset(); |
| 353 | nfc_devices.reset(); | 435 | nfc_devices.reset(); |
| 354 | } | 436 | } |