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/hid/emulated_console.cpp | |
| 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/hid/emulated_console.cpp')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 21 |
1 files changed, 12 insertions, 9 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 | } |