diff options
| author | 2021-12-13 21:09:28 -0500 | |
|---|---|---|
| committer | 2021-12-13 21:22:02 -0500 | |
| commit | e05d2a70b24e550d67fcdd24aae7094ad41745f8 (patch) | |
| tree | af5116d02b99366344c261df03cae992b2e96ae5 /src/core | |
| parent | common/input: Remove unnecessary returns (diff) | |
| download | yuzu-e05d2a70b24e550d67fcdd24aae7094ad41745f8.tar.gz yuzu-e05d2a70b24e550d67fcdd24aae7094ad41745f8.tar.xz yuzu-e05d2a70b24e550d67fcdd24aae7094ad41745f8.zip | |
common/input: Avoid numerous large copies of CallbackStatus
CallbackStatus instances aren't the cheapest things to copy around
(relative to everything else), given that they're currently 520 bytes in
size and are currently copied numerous times when callbacks are invoked.
Instead, we can pass the status by const reference to avoid all the
copying.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 21 | ||||
| -rw-r--r-- | src/core/hid/emulated_console.h | 4 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 95 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 13 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 66 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.h | 11 |
6 files changed, 118 insertions, 92 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index 80db8e9c6..685ec080c 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -66,9 +66,10 @@ void EmulatedConsole::ReloadInput() { | |||
| 66 | 66 | ||
| 67 | motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params); | 67 | motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params); |
| 68 | if (motion_devices) { | 68 | if (motion_devices) { |
| 69 | Common::Input::InputCallback motion_callback{ | 69 | motion_devices->SetCallback({ |
| 70 | [this](Common::Input::CallbackStatus callback) { SetMotion(callback); }}; | 70 | .on_change = |
| 71 | motion_devices->SetCallback(motion_callback); | 71 | [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); }, |
| 72 | }); | ||
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | // Unique index for identifying touch device source | 75 | // Unique index for identifying touch device source |
| @@ -78,9 +79,12 @@ void EmulatedConsole::ReloadInput() { | |||
| 78 | if (!touch_device) { | 79 | if (!touch_device) { |
| 79 | continue; | 80 | continue; |
| 80 | } | 81 | } |
| 81 | Common::Input::InputCallback touch_callback{ | 82 | touch_device->SetCallback({ |
| 82 | [this, index](Common::Input::CallbackStatus callback) { SetTouch(callback, index); }}; | 83 | .on_change = |
| 83 | touch_device->SetCallback(touch_callback); | 84 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 85 | SetTouch(callback, index); | ||
| 86 | }, | ||
| 87 | }); | ||
| 84 | index++; | 88 | index++; |
| 85 | } | 89 | } |
| 86 | } | 90 | } |
| @@ -127,7 +131,7 @@ void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { | |||
| 127 | ReloadInput(); | 131 | ReloadInput(); |
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) { | 134 | void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) { |
| 131 | std::lock_guard lock{mutex}; | 135 | std::lock_guard lock{mutex}; |
| 132 | auto& raw_status = console.motion_values.raw_status; | 136 | auto& raw_status = console.motion_values.raw_status; |
| 133 | auto& emulated = console.motion_values.emulated; | 137 | auto& emulated = console.motion_values.emulated; |
| @@ -162,8 +166,7 @@ void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) { | |||
| 162 | TriggerOnChange(ConsoleTriggerType::Motion); | 166 | TriggerOnChange(ConsoleTriggerType::Motion); |
| 163 | } | 167 | } |
| 164 | 168 | ||
| 165 | void EmulatedConsole::SetTouch(Common::Input::CallbackStatus callback, | 169 | void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index) { |
| 166 | [[maybe_unused]] std::size_t index) { | ||
| 167 | if (index >= console.touch_values.size()) { | 170 | if (index >= console.touch_values.size()) { |
| 168 | return; | 171 | return; |
| 169 | } | 172 | } |
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index bb3d7ab90..3afd284d5 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h | |||
| @@ -155,14 +155,14 @@ private: | |||
| 155 | * Updates the motion status of the console | 155 | * Updates the motion status of the console |
| 156 | * @param callback A CallbackStatus containing gyro and accelerometer data | 156 | * @param callback A CallbackStatus containing gyro and accelerometer data |
| 157 | */ | 157 | */ |
| 158 | void SetMotion(Common::Input::CallbackStatus callback); | 158 | void SetMotion(const Common::Input::CallbackStatus& callback); |
| 159 | 159 | ||
| 160 | /** | 160 | /** |
| 161 | * Updates the touch status of the console | 161 | * Updates the touch status of the console |
| 162 | * @param callback A CallbackStatus containing the touch position | 162 | * @param callback A CallbackStatus containing the touch position |
| 163 | * @param index Finger ID to be updated | 163 | * @param index Finger ID to be updated |
| 164 | */ | 164 | */ |
| 165 | void SetTouch(Common::Input::CallbackStatus callback, std::size_t index); | 165 | void SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 166 | 166 | ||
| 167 | /** | 167 | /** |
| 168 | * Triggers a callback that something has changed on the console status | 168 | * Triggers a callback that something has changed on the console status |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index fbb19f230..eb2e0ab4f 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -205,11 +205,12 @@ void EmulatedController::ReloadInput() { | |||
| 205 | continue; | 205 | continue; |
| 206 | } | 206 | } |
| 207 | const auto uuid = Common::UUID{button_params[index].Get("guid", "")}; | 207 | const auto uuid = Common::UUID{button_params[index].Get("guid", "")}; |
| 208 | Common::Input::InputCallback button_callback{ | 208 | button_devices[index]->SetCallback({ |
| 209 | [this, index, uuid](Common::Input::CallbackStatus callback) { | 209 | .on_change = |
| 210 | SetButton(callback, index, uuid); | 210 | [this, index, uuid](const Common::Input::CallbackStatus& callback) { |
| 211 | }}; | 211 | SetButton(callback, index, uuid); |
| 212 | button_devices[index]->SetCallback(button_callback); | 212 | }, |
| 213 | }); | ||
| 213 | button_devices[index]->ForceUpdate(); | 214 | button_devices[index]->ForceUpdate(); |
| 214 | } | 215 | } |
| 215 | 216 | ||
| @@ -218,11 +219,12 @@ void EmulatedController::ReloadInput() { | |||
| 218 | continue; | 219 | continue; |
| 219 | } | 220 | } |
| 220 | const auto uuid = Common::UUID{stick_params[index].Get("guid", "")}; | 221 | const auto uuid = Common::UUID{stick_params[index].Get("guid", "")}; |
| 221 | Common::Input::InputCallback stick_callback{ | 222 | stick_devices[index]->SetCallback({ |
| 222 | [this, index, uuid](Common::Input::CallbackStatus callback) { | 223 | .on_change = |
| 223 | SetStick(callback, index, uuid); | 224 | [this, index, uuid](const Common::Input::CallbackStatus& callback) { |
| 224 | }}; | 225 | SetStick(callback, index, uuid); |
| 225 | stick_devices[index]->SetCallback(stick_callback); | 226 | }, |
| 227 | }); | ||
| 226 | stick_devices[index]->ForceUpdate(); | 228 | stick_devices[index]->ForceUpdate(); |
| 227 | } | 229 | } |
| 228 | 230 | ||
| @@ -231,11 +233,12 @@ void EmulatedController::ReloadInput() { | |||
| 231 | continue; | 233 | continue; |
| 232 | } | 234 | } |
| 233 | const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")}; | 235 | const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")}; |
| 234 | Common::Input::InputCallback trigger_callback{ | 236 | trigger_devices[index]->SetCallback({ |
| 235 | [this, index, uuid](Common::Input::CallbackStatus callback) { | 237 | .on_change = |
| 236 | SetTrigger(callback, index, uuid); | 238 | [this, index, uuid](const Common::Input::CallbackStatus& callback) { |
| 237 | }}; | 239 | SetTrigger(callback, index, uuid); |
| 238 | trigger_devices[index]->SetCallback(trigger_callback); | 240 | }, |
| 241 | }); | ||
| 239 | trigger_devices[index]->ForceUpdate(); | 242 | trigger_devices[index]->ForceUpdate(); |
| 240 | } | 243 | } |
| 241 | 244 | ||
| @@ -243,9 +246,12 @@ void EmulatedController::ReloadInput() { | |||
| 243 | if (!battery_devices[index]) { | 246 | if (!battery_devices[index]) { |
| 244 | continue; | 247 | continue; |
| 245 | } | 248 | } |
| 246 | Common::Input::InputCallback battery_callback{ | 249 | battery_devices[index]->SetCallback({ |
| 247 | [this, index](Common::Input::CallbackStatus callback) { SetBattery(callback, index); }}; | 250 | .on_change = |
| 248 | battery_devices[index]->SetCallback(battery_callback); | 251 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 252 | SetBattery(callback, index); | ||
| 253 | }, | ||
| 254 | }); | ||
| 249 | battery_devices[index]->ForceUpdate(); | 255 | battery_devices[index]->ForceUpdate(); |
| 250 | } | 256 | } |
| 251 | 257 | ||
| @@ -253,9 +259,12 @@ void EmulatedController::ReloadInput() { | |||
| 253 | if (!motion_devices[index]) { | 259 | if (!motion_devices[index]) { |
| 254 | continue; | 260 | continue; |
| 255 | } | 261 | } |
| 256 | Common::Input::InputCallback motion_callback{ | 262 | motion_devices[index]->SetCallback({ |
| 257 | [this, index](Common::Input::CallbackStatus callback) { SetMotion(callback, index); }}; | 263 | .on_change = |
| 258 | motion_devices[index]->SetCallback(motion_callback); | 264 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 265 | SetMotion(callback, index); | ||
| 266 | }, | ||
| 267 | }); | ||
| 259 | motion_devices[index]->ForceUpdate(); | 268 | motion_devices[index]->ForceUpdate(); |
| 260 | } | 269 | } |
| 261 | 270 | ||
| @@ -267,22 +276,24 @@ void EmulatedController::ReloadInput() { | |||
| 267 | if (!tas_button_devices[index]) { | 276 | if (!tas_button_devices[index]) { |
| 268 | continue; | 277 | continue; |
| 269 | } | 278 | } |
| 270 | Common::Input::InputCallback button_callback{ | 279 | tas_button_devices[index]->SetCallback({ |
| 271 | [this, index, tas_uuid](Common::Input::CallbackStatus callback) { | 280 | .on_change = |
| 272 | SetButton(callback, index, tas_uuid); | 281 | [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { |
| 273 | }}; | 282 | SetButton(callback, index, tas_uuid); |
| 274 | tas_button_devices[index]->SetCallback(button_callback); | 283 | }, |
| 284 | }); | ||
| 275 | } | 285 | } |
| 276 | 286 | ||
| 277 | for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) { | 287 | for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) { |
| 278 | if (!tas_stick_devices[index]) { | 288 | if (!tas_stick_devices[index]) { |
| 279 | continue; | 289 | continue; |
| 280 | } | 290 | } |
| 281 | Common::Input::InputCallback stick_callback{ | 291 | tas_stick_devices[index]->SetCallback({ |
| 282 | [this, index, tas_uuid](Common::Input::CallbackStatus callback) { | 292 | .on_change = |
| 283 | SetStick(callback, index, tas_uuid); | 293 | [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { |
| 284 | }}; | 294 | SetStick(callback, index, tas_uuid); |
| 285 | tas_stick_devices[index]->SetCallback(stick_callback); | 295 | }, |
| 296 | }); | ||
| 286 | } | 297 | } |
| 287 | } | 298 | } |
| 288 | 299 | ||
| @@ -440,7 +451,7 @@ void EmulatedController::SetButtonParam(std::size_t index, Common::ParamPackage | |||
| 440 | if (index >= button_params.size()) { | 451 | if (index >= button_params.size()) { |
| 441 | return; | 452 | return; |
| 442 | } | 453 | } |
| 443 | button_params[index] = param; | 454 | button_params[index] = std::move(param); |
| 444 | ReloadInput(); | 455 | ReloadInput(); |
| 445 | } | 456 | } |
| 446 | 457 | ||
| @@ -448,7 +459,7 @@ void EmulatedController::SetStickParam(std::size_t index, Common::ParamPackage p | |||
| 448 | if (index >= stick_params.size()) { | 459 | if (index >= stick_params.size()) { |
| 449 | return; | 460 | return; |
| 450 | } | 461 | } |
| 451 | stick_params[index] = param; | 462 | stick_params[index] = std::move(param); |
| 452 | ReloadInput(); | 463 | ReloadInput(); |
| 453 | } | 464 | } |
| 454 | 465 | ||
| @@ -456,11 +467,11 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage | |||
| 456 | if (index >= motion_params.size()) { | 467 | if (index >= motion_params.size()) { |
| 457 | return; | 468 | return; |
| 458 | } | 469 | } |
| 459 | motion_params[index] = param; | 470 | motion_params[index] = std::move(param); |
| 460 | ReloadInput(); | 471 | ReloadInput(); |
| 461 | } | 472 | } |
| 462 | 473 | ||
| 463 | void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index, | 474 | void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback, std::size_t index, |
| 464 | Common::UUID uuid) { | 475 | Common::UUID uuid) { |
| 465 | if (index >= controller.button_values.size()) { | 476 | if (index >= controller.button_values.size()) { |
| 466 | return; | 477 | return; |
| @@ -600,7 +611,7 @@ void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std:: | |||
| 600 | TriggerOnChange(ControllerTriggerType::Button, true); | 611 | TriggerOnChange(ControllerTriggerType::Button, true); |
| 601 | } | 612 | } |
| 602 | 613 | ||
| 603 | void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index, | 614 | void EmulatedController::SetStick(const Common::Input::CallbackStatus& callback, std::size_t index, |
| 604 | Common::UUID uuid) { | 615 | Common::UUID uuid) { |
| 605 | if (index >= controller.stick_values.size()) { | 616 | if (index >= controller.stick_values.size()) { |
| 606 | return; | 617 | return; |
| @@ -650,8 +661,8 @@ void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::s | |||
| 650 | TriggerOnChange(ControllerTriggerType::Stick, true); | 661 | TriggerOnChange(ControllerTriggerType::Stick, true); |
| 651 | } | 662 | } |
| 652 | 663 | ||
| 653 | void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, | 664 | void EmulatedController::SetTrigger(const Common::Input::CallbackStatus& callback, |
| 654 | Common::UUID uuid) { | 665 | std::size_t index, Common::UUID uuid) { |
| 655 | if (index >= controller.trigger_values.size()) { | 666 | if (index >= controller.trigger_values.size()) { |
| 656 | return; | 667 | return; |
| 657 | } | 668 | } |
| @@ -692,7 +703,8 @@ void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std: | |||
| 692 | TriggerOnChange(ControllerTriggerType::Trigger, true); | 703 | TriggerOnChange(ControllerTriggerType::Trigger, true); |
| 693 | } | 704 | } |
| 694 | 705 | ||
| 695 | void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) { | 706 | void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback, |
| 707 | std::size_t index) { | ||
| 696 | if (index >= controller.motion_values.size()) { | 708 | if (index >= controller.motion_values.size()) { |
| 697 | return; | 709 | return; |
| 698 | } | 710 | } |
| @@ -730,7 +742,8 @@ void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std:: | |||
| 730 | TriggerOnChange(ControllerTriggerType::Motion, true); | 742 | TriggerOnChange(ControllerTriggerType::Motion, true); |
| 731 | } | 743 | } |
| 732 | 744 | ||
| 733 | void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) { | 745 | void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback, |
| 746 | std::size_t index) { | ||
| 734 | if (index >= controller.battery_values.size()) { | 747 | if (index >= controller.battery_values.size()) { |
| 735 | return; | 748 | return; |
| 736 | } | 749 | } |
| @@ -1110,7 +1123,7 @@ void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npa | |||
| 1110 | 1123 | ||
| 1111 | int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) { | 1124 | int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) { |
| 1112 | std::lock_guard lock{mutex}; | 1125 | std::lock_guard lock{mutex}; |
| 1113 | callback_list.insert_or_assign(last_callback_key, update_callback); | 1126 | callback_list.insert_or_assign(last_callback_key, std::move(update_callback)); |
| 1114 | return last_callback_key++; | 1127 | return last_callback_key++; |
| 1115 | } | 1128 | } |
| 1116 | 1129 | ||
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 425b3e7c4..e42aafebc 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -328,35 +328,38 @@ private: | |||
| 328 | * @param callback A CallbackStatus containing the button status | 328 | * @param callback A CallbackStatus containing the button status |
| 329 | * @param index Button ID of the to be updated | 329 | * @param index Button ID of the to be updated |
| 330 | */ | 330 | */ |
| 331 | void SetButton(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); | 331 | void SetButton(const Common::Input::CallbackStatus& callback, std::size_t index, |
| 332 | Common::UUID uuid); | ||
| 332 | 333 | ||
| 333 | /** | 334 | /** |
| 334 | * Updates the analog stick status of the controller | 335 | * Updates the analog stick status of the controller |
| 335 | * @param callback A CallbackStatus containing the analog stick status | 336 | * @param callback A CallbackStatus containing the analog stick status |
| 336 | * @param index stick ID of the to be updated | 337 | * @param index stick ID of the to be updated |
| 337 | */ | 338 | */ |
| 338 | void SetStick(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); | 339 | void SetStick(const Common::Input::CallbackStatus& callback, std::size_t index, |
| 340 | Common::UUID uuid); | ||
| 339 | 341 | ||
| 340 | /** | 342 | /** |
| 341 | * Updates the trigger status of the controller | 343 | * Updates the trigger status of the controller |
| 342 | * @param callback A CallbackStatus containing the trigger status | 344 | * @param callback A CallbackStatus containing the trigger status |
| 343 | * @param index trigger ID of the to be updated | 345 | * @param index trigger ID of the to be updated |
| 344 | */ | 346 | */ |
| 345 | void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid); | 347 | void SetTrigger(const Common::Input::CallbackStatus& callback, std::size_t index, |
| 348 | Common::UUID uuid); | ||
| 346 | 349 | ||
| 347 | /** | 350 | /** |
| 348 | * Updates the motion status of the controller | 351 | * Updates the motion status of the controller |
| 349 | * @param callback A CallbackStatus containing gyro and accelerometer data | 352 | * @param callback A CallbackStatus containing gyro and accelerometer data |
| 350 | * @param index motion ID of the to be updated | 353 | * @param index motion ID of the to be updated |
| 351 | */ | 354 | */ |
| 352 | void SetMotion(Common::Input::CallbackStatus callback, std::size_t index); | 355 | void SetMotion(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 353 | 356 | ||
| 354 | /** | 357 | /** |
| 355 | * Updates the battery status of the controller | 358 | * Updates the battery status of the controller |
| 356 | * @param callback A CallbackStatus containing the battery status | 359 | * @param callback A CallbackStatus containing the battery status |
| 357 | * @param index Button ID of the to be updated | 360 | * @param index Button ID of the to be updated |
| 358 | */ | 361 | */ |
| 359 | void SetBattery(Common::Input::CallbackStatus callback, std::size_t index); | 362 | void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 360 | 363 | ||
| 361 | /** | 364 | /** |
| 362 | * Triggers a callback that something has changed on the controller status | 365 | * Triggers a callback that something has changed on the controller status |
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 874780ec2..708480f2d 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -70,50 +70,55 @@ void EmulatedDevices::ReloadInput() { | |||
| 70 | if (!mouse_button_devices[index]) { | 70 | if (!mouse_button_devices[index]) { |
| 71 | continue; | 71 | continue; |
| 72 | } | 72 | } |
| 73 | Common::Input::InputCallback button_callback{ | 73 | mouse_button_devices[index]->SetCallback({ |
| 74 | [this, index](Common::Input::CallbackStatus callback) { | 74 | .on_change = |
| 75 | SetMouseButton(callback, index); | 75 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 76 | }}; | 76 | SetMouseButton(callback, index); |
| 77 | mouse_button_devices[index]->SetCallback(button_callback); | 77 | }, |
| 78 | }); | ||
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { | 81 | for (std::size_t index = 0; index < mouse_analog_devices.size(); ++index) { |
| 81 | if (!mouse_analog_devices[index]) { | 82 | if (!mouse_analog_devices[index]) { |
| 82 | continue; | 83 | continue; |
| 83 | } | 84 | } |
| 84 | Common::Input::InputCallback button_callback{ | 85 | mouse_analog_devices[index]->SetCallback({ |
| 85 | [this, index](Common::Input::CallbackStatus callback) { | 86 | .on_change = |
| 86 | SetMouseAnalog(callback, index); | 87 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 87 | }}; | 88 | SetMouseAnalog(callback, index); |
| 88 | mouse_analog_devices[index]->SetCallback(button_callback); | 89 | }, |
| 90 | }); | ||
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | if (mouse_stick_device) { | 93 | if (mouse_stick_device) { |
| 92 | Common::Input::InputCallback button_callback{ | 94 | mouse_stick_device->SetCallback({ |
| 93 | [this](Common::Input::CallbackStatus callback) { SetMouseStick(callback); }}; | 95 | .on_change = |
| 94 | mouse_stick_device->SetCallback(button_callback); | 96 | [this](const Common::Input::CallbackStatus& callback) { SetMouseStick(callback); }, |
| 97 | }); | ||
| 95 | } | 98 | } |
| 96 | 99 | ||
| 97 | for (std::size_t index = 0; index < keyboard_devices.size(); ++index) { | 100 | for (std::size_t index = 0; index < keyboard_devices.size(); ++index) { |
| 98 | if (!keyboard_devices[index]) { | 101 | if (!keyboard_devices[index]) { |
| 99 | continue; | 102 | continue; |
| 100 | } | 103 | } |
| 101 | Common::Input::InputCallback button_callback{ | 104 | keyboard_devices[index]->SetCallback({ |
| 102 | [this, index](Common::Input::CallbackStatus callback) { | 105 | .on_change = |
| 103 | SetKeyboardButton(callback, index); | 106 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 104 | }}; | 107 | SetKeyboardButton(callback, index); |
| 105 | keyboard_devices[index]->SetCallback(button_callback); | 108 | }, |
| 109 | }); | ||
| 106 | } | 110 | } |
| 107 | 111 | ||
| 108 | for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) { | 112 | for (std::size_t index = 0; index < keyboard_modifier_devices.size(); ++index) { |
| 109 | if (!keyboard_modifier_devices[index]) { | 113 | if (!keyboard_modifier_devices[index]) { |
| 110 | continue; | 114 | continue; |
| 111 | } | 115 | } |
| 112 | Common::Input::InputCallback button_callback{ | 116 | keyboard_modifier_devices[index]->SetCallback({ |
| 113 | [this, index](Common::Input::CallbackStatus callback) { | 117 | .on_change = |
| 114 | SetKeyboardModifier(callback, index); | 118 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 115 | }}; | 119 | SetKeyboardModifier(callback, index); |
| 116 | keyboard_modifier_devices[index]->SetCallback(button_callback); | 120 | }, |
| 121 | }); | ||
| 117 | } | 122 | } |
| 118 | } | 123 | } |
| 119 | 124 | ||
| @@ -159,7 +164,8 @@ void EmulatedDevices::RestoreConfig() { | |||
| 159 | ReloadFromSettings(); | 164 | ReloadFromSettings(); |
| 160 | } | 165 | } |
| 161 | 166 | ||
| 162 | void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) { | 167 | void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback, |
| 168 | std::size_t index) { | ||
| 163 | if (index >= device_status.keyboard_values.size()) { | 169 | if (index >= device_status.keyboard_values.size()) { |
| 164 | return; | 170 | return; |
| 165 | } | 171 | } |
| @@ -216,7 +222,7 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) { | |||
| 216 | } | 222 | } |
| 217 | } | 223 | } |
| 218 | 224 | ||
| 219 | void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback, | 225 | void EmulatedDevices::SetKeyboardModifier(const Common::Input::CallbackStatus& callback, |
| 220 | std::size_t index) { | 226 | std::size_t index) { |
| 221 | if (index >= device_status.keyboard_moddifier_values.size()) { | 227 | if (index >= device_status.keyboard_moddifier_values.size()) { |
| 222 | return; | 228 | return; |
| @@ -286,7 +292,8 @@ void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback | |||
| 286 | TriggerOnChange(DeviceTriggerType::KeyboardModdifier); | 292 | TriggerOnChange(DeviceTriggerType::KeyboardModdifier); |
| 287 | } | 293 | } |
| 288 | 294 | ||
| 289 | void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) { | 295 | void EmulatedDevices::SetMouseButton(const Common::Input::CallbackStatus& callback, |
| 296 | std::size_t index) { | ||
| 290 | if (index >= device_status.mouse_button_values.size()) { | 297 | if (index >= device_status.mouse_button_values.size()) { |
| 291 | return; | 298 | return; |
| 292 | } | 299 | } |
| @@ -347,7 +354,8 @@ void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std | |||
| 347 | TriggerOnChange(DeviceTriggerType::Mouse); | 354 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 348 | } | 355 | } |
| 349 | 356 | ||
| 350 | void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index) { | 357 | void EmulatedDevices::SetMouseAnalog(const Common::Input::CallbackStatus& callback, |
| 358 | std::size_t index) { | ||
| 351 | if (index >= device_status.mouse_analog_values.size()) { | 359 | if (index >= device_status.mouse_analog_values.size()) { |
| 352 | return; | 360 | return; |
| 353 | } | 361 | } |
| @@ -374,7 +382,7 @@ void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std | |||
| 374 | TriggerOnChange(DeviceTriggerType::Mouse); | 382 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 375 | } | 383 | } |
| 376 | 384 | ||
| 377 | void EmulatedDevices::SetMouseStick(Common::Input::CallbackStatus callback) { | 385 | void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callback) { |
| 378 | std::lock_guard lock{mutex}; | 386 | std::lock_guard lock{mutex}; |
| 379 | const auto touch_value = TransformToTouch(callback); | 387 | const auto touch_value = TransformToTouch(callback); |
| 380 | 388 | ||
| @@ -435,7 +443,7 @@ void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) { | |||
| 435 | 443 | ||
| 436 | int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { | 444 | int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { |
| 437 | std::lock_guard lock{mutex}; | 445 | std::lock_guard lock{mutex}; |
| 438 | callback_list.insert_or_assign(last_callback_key, update_callback); | 446 | callback_list.insert_or_assign(last_callback_key, std::move(update_callback)); |
| 439 | return last_callback_key++; | 447 | return last_callback_key++; |
| 440 | } | 448 | } |
| 441 | 449 | ||
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h index c72327681..790d3b411 100644 --- a/src/core/hid/emulated_devices.h +++ b/src/core/hid/emulated_devices.h | |||
| @@ -156,35 +156,34 @@ private: | |||
| 156 | * @param callback A CallbackStatus containing the key status | 156 | * @param callback A CallbackStatus containing the key status |
| 157 | * @param index key ID to be updated | 157 | * @param index key ID to be updated |
| 158 | */ | 158 | */ |
| 159 | void SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index); | 159 | void SetKeyboardButton(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 160 | 160 | ||
| 161 | /** | 161 | /** |
| 162 | * Updates the keyboard status of the keyboard device | 162 | * Updates the keyboard status of the keyboard device |
| 163 | * @param callback A CallbackStatus containing the modifier key status | 163 | * @param callback A CallbackStatus containing the modifier key status |
| 164 | * @param index modifier key ID to be updated | 164 | * @param index modifier key ID to be updated |
| 165 | */ | 165 | */ |
| 166 | void SetKeyboardModifier(Common::Input::CallbackStatus callback, std::size_t index); | 166 | void SetKeyboardModifier(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 167 | 167 | ||
| 168 | /** | 168 | /** |
| 169 | * Updates the mouse button status of the mouse device | 169 | * Updates the mouse button status of the mouse device |
| 170 | * @param callback A CallbackStatus containing the button status | 170 | * @param callback A CallbackStatus containing the button status |
| 171 | * @param index Button ID to be updated | 171 | * @param index Button ID to be updated |
| 172 | */ | 172 | */ |
| 173 | void SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index); | 173 | void SetMouseButton(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 174 | 174 | ||
| 175 | /** | 175 | /** |
| 176 | * Updates the mouse wheel status of the mouse device | 176 | * Updates the mouse wheel status of the mouse device |
| 177 | * @param callback A CallbackStatus containing the wheel status | 177 | * @param callback A CallbackStatus containing the wheel status |
| 178 | * @param index wheel ID to be updated | 178 | * @param index wheel ID to be updated |
| 179 | */ | 179 | */ |
| 180 | void SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index); | 180 | void SetMouseAnalog(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 181 | 181 | ||
| 182 | /** | 182 | /** |
| 183 | * Updates the mouse position status of the mouse device | 183 | * Updates the mouse position status of the mouse device |
| 184 | * @param callback A CallbackStatus containing the position status | 184 | * @param callback A CallbackStatus containing the position status |
| 185 | * @param index stick ID to be updated | ||
| 186 | */ | 185 | */ |
| 187 | void SetMouseStick(Common::Input::CallbackStatus callback); | 186 | void SetMouseStick(const Common::Input::CallbackStatus& callback); |
| 188 | 187 | ||
| 189 | /** | 188 | /** |
| 190 | * Triggers a callback that something has changed on the device status | 189 | * Triggers a callback that something has changed on the device status |