summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_controller.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2021-12-13 21:09:28 -0500
committerGravatar Lioncash2021-12-13 21:22:02 -0500
commite05d2a70b24e550d67fcdd24aae7094ad41745f8 (patch)
treeaf5116d02b99366344c261df03cae992b2e96ae5 /src/core/hid/emulated_controller.cpp
parentcommon/input: Remove unnecessary returns (diff)
downloadyuzu-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/hid/emulated_controller.cpp')
-rw-r--r--src/core/hid/emulated_controller.cpp95
1 files changed, 54 insertions, 41 deletions
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
463void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index, 474void 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
603void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index, 614void 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
653void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, 664void 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
695void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) { 706void 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
733void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) { 745void 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
1111int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) { 1124int 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