diff options
| author | 2023-04-11 20:39:05 -0600 | |
|---|---|---|
| committer | 2023-06-03 00:05:56 -0700 | |
| commit | 5c1310dc5ddc022f70d376325e6c112e95348344 (patch) | |
| tree | cc5c49deb2482c72b6a86bf3aa497def4cc4a8b1 /src | |
| parent | android: Change wording for "Add Games" button (#100) (diff) | |
| download | yuzu-5c1310dc5ddc022f70d376325e6c112e95348344.tar.gz yuzu-5c1310dc5ddc022f70d376325e6c112e95348344.tar.xz yuzu-5c1310dc5ddc022f70d376325e6c112e95348344.zip | |
core: hid: Finish linking motion from virtual controllers
Diffstat (limited to 'src')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt | 2 | ||||
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 32 | ||||
| -rw-r--r-- | src/core/hid/emulated_console.h | 4 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 26 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 2 |
5 files changed, 57 insertions, 9 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index 4c57de067..4670bc375 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt | |||
| @@ -117,11 +117,13 @@ open class EmulationActivity : AppCompatActivity() { | |||
| 117 | override fun onResume() { | 117 | override fun onResume() { |
| 118 | super.onResume() | 118 | super.onResume() |
| 119 | nfcReader.startScanning() | 119 | nfcReader.startScanning() |
| 120 | startMotionSensorListener() | ||
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | override fun onPause() { | 123 | override fun onPause() { |
| 123 | super.onPause() | 124 | super.onPause() |
| 124 | nfcReader.stopScanning() | 125 | nfcReader.stopScanning() |
| 126 | stopMotionSensorListener() | ||
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | override fun onNewIntent(intent: Intent) { | 129 | override fun onNewIntent(intent: Intent) { |
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index 17d663379..b4afd930e 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -13,7 +13,7 @@ EmulatedConsole::~EmulatedConsole() = default; | |||
| 13 | void EmulatedConsole::ReloadFromSettings() { | 13 | void EmulatedConsole::ReloadFromSettings() { |
| 14 | // Using first motion device from player 1. No need to assign any unique config at the moment | 14 | // Using first motion device from player 1. No need to assign any unique config at the moment |
| 15 | const auto& player = Settings::values.players.GetValue()[0]; | 15 | const auto& player = Settings::values.players.GetValue()[0]; |
| 16 | motion_params = Common::ParamPackage(player.motions[0]); | 16 | motion_params[0] = Common::ParamPackage(player.motions[0]); |
| 17 | 17 | ||
| 18 | ReloadInput(); | 18 | ReloadInput(); |
| 19 | } | 19 | } |
| @@ -74,14 +74,30 @@ void EmulatedConsole::ReloadInput() { | |||
| 74 | // If you load any device here add the equivalent to the UnloadInput() function | 74 | // If you load any device here add the equivalent to the UnloadInput() function |
| 75 | SetTouchParams(); | 75 | SetTouchParams(); |
| 76 | 76 | ||
| 77 | motion_devices = Common::Input::CreateInputDevice(motion_params); | 77 | motion_params[1] = Common::ParamPackage{"engine:virtual_gamepad,port:8,motion:0"}; |
| 78 | if (motion_devices) { | 78 | |
| 79 | motion_devices->SetCallback({ | 79 | for (std::size_t index = 0; index < motion_devices.size(); ++index) { |
| 80 | motion_devices[index] = Common::Input::CreateInputDevice(motion_params[index]); | ||
| 81 | if (!motion_devices[index]) { | ||
| 82 | continue; | ||
| 83 | } | ||
| 84 | motion_devices[index]->SetCallback({ | ||
| 80 | .on_change = | 85 | .on_change = |
| 81 | [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); }, | 86 | [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); }, |
| 82 | }); | 87 | }); |
| 83 | } | 88 | } |
| 84 | 89 | ||
| 90 | // Restore motion state | ||
| 91 | auto& emulated_motion = console.motion_values.emulated; | ||
| 92 | auto& motion = console.motion_state; | ||
| 93 | emulated_motion.ResetRotations(); | ||
| 94 | emulated_motion.ResetQuaternion(); | ||
| 95 | motion.accel = emulated_motion.GetAcceleration(); | ||
| 96 | motion.gyro = emulated_motion.GetGyroscope(); | ||
| 97 | motion.rotation = emulated_motion.GetRotations(); | ||
| 98 | motion.orientation = emulated_motion.GetOrientation(); | ||
| 99 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); | ||
| 100 | |||
| 85 | // Unique index for identifying touch device source | 101 | // Unique index for identifying touch device source |
| 86 | std::size_t index = 0; | 102 | std::size_t index = 0; |
| 87 | for (auto& touch_device : touch_devices) { | 103 | for (auto& touch_device : touch_devices) { |
| @@ -100,7 +116,9 @@ void EmulatedConsole::ReloadInput() { | |||
| 100 | } | 116 | } |
| 101 | 117 | ||
| 102 | void EmulatedConsole::UnloadInput() { | 118 | void EmulatedConsole::UnloadInput() { |
| 103 | motion_devices.reset(); | 119 | for (auto& motion : motion_devices) { |
| 120 | motion.reset(); | ||
| 121 | } | ||
| 104 | for (auto& touch : touch_devices) { | 122 | for (auto& touch : touch_devices) { |
| 105 | touch.reset(); | 123 | touch.reset(); |
| 106 | } | 124 | } |
| @@ -133,11 +151,11 @@ void EmulatedConsole::RestoreConfig() { | |||
| 133 | } | 151 | } |
| 134 | 152 | ||
| 135 | Common::ParamPackage EmulatedConsole::GetMotionParam() const { | 153 | Common::ParamPackage EmulatedConsole::GetMotionParam() const { |
| 136 | return motion_params; | 154 | return motion_params[0]; |
| 137 | } | 155 | } |
| 138 | 156 | ||
| 139 | void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { | 157 | void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { |
| 140 | motion_params = std::move(param); | 158 | motion_params[0] = std::move(param); |
| 141 | ReloadInput(); | 159 | ReloadInput(); |
| 142 | } | 160 | } |
| 143 | 161 | ||
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index 697ecd2d6..79114bb6d 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h | |||
| @@ -29,10 +29,10 @@ struct ConsoleMotionInfo { | |||
| 29 | MotionInput emulated{}; | 29 | MotionInput emulated{}; |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | using ConsoleMotionDevices = std::unique_ptr<Common::Input::InputDevice>; | 32 | using ConsoleMotionDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, 2>; |
| 33 | using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, MaxTouchDevices>; | 33 | using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, MaxTouchDevices>; |
| 34 | 34 | ||
| 35 | using ConsoleMotionParams = Common::ParamPackage; | 35 | using ConsoleMotionParams = std::array<Common::ParamPackage, 2>; |
| 36 | using TouchParams = std::array<Common::ParamPackage, MaxTouchDevices>; | 36 | using TouchParams = std::array<Common::ParamPackage, MaxTouchDevices>; |
| 37 | 37 | ||
| 38 | using ConsoleMotionValues = ConsoleMotionInfo; | 38 | using ConsoleMotionValues = ConsoleMotionInfo; |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index bbfea7117..0a7777732 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -193,6 +193,8 @@ void EmulatedController::LoadDevices() { | |||
| 193 | Common::Input::CreateInputDevice); | 193 | Common::Input::CreateInputDevice); |
| 194 | std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(), | 194 | std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(), |
| 195 | Common::Input::CreateInputDevice); | 195 | Common::Input::CreateInputDevice); |
| 196 | std::ranges::transform(virtual_motion_params, virtual_motion_devices.begin(), | ||
| 197 | Common::Input::CreateInputDevice); | ||
| 196 | } | 198 | } |
| 197 | 199 | ||
| 198 | void EmulatedController::LoadTASParams() { | 200 | void EmulatedController::LoadTASParams() { |
| @@ -253,6 +255,12 @@ void EmulatedController::LoadVirtualGamepadParams() { | |||
| 253 | for (auto& param : virtual_stick_params) { | 255 | for (auto& param : virtual_stick_params) { |
| 254 | param = common_params; | 256 | param = common_params; |
| 255 | } | 257 | } |
| 258 | for (auto& param : virtual_stick_params) { | ||
| 259 | param = common_params; | ||
| 260 | } | ||
| 261 | for (auto& param : virtual_motion_params) { | ||
| 262 | param = common_params; | ||
| 263 | } | ||
| 256 | 264 | ||
| 257 | // TODO(german77): Replace this with an input profile or something better | 265 | // TODO(german77): Replace this with an input profile or something better |
| 258 | virtual_button_params[Settings::NativeButton::A].Set("button", 0); | 266 | virtual_button_params[Settings::NativeButton::A].Set("button", 0); |
| @@ -284,6 +292,9 @@ void EmulatedController::LoadVirtualGamepadParams() { | |||
| 284 | virtual_stick_params[Settings::NativeAnalog::LStick].Set("range", 1.0f); | 292 | virtual_stick_params[Settings::NativeAnalog::LStick].Set("range", 1.0f); |
| 285 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("deadzone", 0.0f); | 293 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("deadzone", 0.0f); |
| 286 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("range", 1.0f); | 294 | virtual_stick_params[Settings::NativeAnalog::RStick].Set("range", 1.0f); |
| 295 | |||
| 296 | virtual_motion_params[Settings::NativeMotion::MotionLeft].Set("motion", 0); | ||
| 297 | virtual_motion_params[Settings::NativeMotion::MotionRight].Set("motion", 0); | ||
| 287 | } | 298 | } |
| 288 | 299 | ||
| 289 | void EmulatedController::ReloadInput() { | 300 | void EmulatedController::ReloadInput() { |
| @@ -463,6 +474,18 @@ void EmulatedController::ReloadInput() { | |||
| 463 | }, | 474 | }, |
| 464 | }); | 475 | }); |
| 465 | } | 476 | } |
| 477 | |||
| 478 | for (std::size_t index = 0; index < virtual_motion_devices.size(); ++index) { | ||
| 479 | if (!virtual_motion_devices[index]) { | ||
| 480 | continue; | ||
| 481 | } | ||
| 482 | virtual_motion_devices[index]->SetCallback({ | ||
| 483 | .on_change = | ||
| 484 | [this, index](const Common::Input::CallbackStatus& callback) { | ||
| 485 | SetMotion(callback, index); | ||
| 486 | }, | ||
| 487 | }); | ||
| 488 | } | ||
| 466 | turbo_button_state = 0; | 489 | turbo_button_state = 0; |
| 467 | } | 490 | } |
| 468 | 491 | ||
| @@ -500,6 +523,9 @@ void EmulatedController::UnloadInput() { | |||
| 500 | for (auto& stick : virtual_stick_devices) { | 523 | for (auto& stick : virtual_stick_devices) { |
| 501 | stick.reset(); | 524 | stick.reset(); |
| 502 | } | 525 | } |
| 526 | for (auto& motion : virtual_motion_devices) { | ||
| 527 | motion.reset(); | ||
| 528 | } | ||
| 503 | for (auto& camera : camera_devices) { | 529 | for (auto& camera : camera_devices) { |
| 504 | camera.reset(); | 530 | camera.reset(); |
| 505 | } | 531 | } |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 88fad2f56..09fe1a0ab 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -568,8 +568,10 @@ private: | |||
| 568 | // Virtual gamepad related variables | 568 | // Virtual gamepad related variables |
| 569 | ButtonParams virtual_button_params; | 569 | ButtonParams virtual_button_params; |
| 570 | StickParams virtual_stick_params; | 570 | StickParams virtual_stick_params; |
| 571 | ControllerMotionParams virtual_motion_params; | ||
| 571 | ButtonDevices virtual_button_devices; | 572 | ButtonDevices virtual_button_devices; |
| 572 | StickDevices virtual_stick_devices; | 573 | StickDevices virtual_stick_devices; |
| 574 | ControllerMotionDevices virtual_motion_devices; | ||
| 573 | 575 | ||
| 574 | mutable std::mutex mutex; | 576 | mutable std::mutex mutex; |
| 575 | mutable std::mutex callback_mutex; | 577 | mutable std::mutex callback_mutex; |