diff options
Diffstat (limited to 'src/core/hid/emulated_console.cpp')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
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 | ||