summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_devices.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_devices.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_devices.cpp')
-rw-r--r--src/core/hid/emulated_devices.cpp66
1 files changed, 37 insertions, 29 deletions
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
162void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) { 167void 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
219void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback, 225void 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
289void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) { 295void 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
350void EmulatedDevices::SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index) { 357void 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
377void EmulatedDevices::SetMouseStick(Common::Input::CallbackStatus callback) { 385void 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
436int EmulatedDevices::SetCallback(InterfaceUpdateCallback update_callback) { 444int 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