From 4255e30722ff000a8dc15c1842cee014cdc32291 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 5 Dec 2022 18:11:17 -0500 Subject: [PATCH 1/4] emulated_console: std::move() ParamPackages and callbacks where applicable --- src/core/hid/emulated_console.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index b6c8cc58d9..a896a5ad86 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp @@ -37,7 +37,7 @@ void EmulatedConsole::SetTouchParams() { touchscreen_param.Set("axis_x", i * 2); touchscreen_param.Set("axis_y", (i * 2) + 1); touchscreen_param.Set("button", i); - touch_params[index++] = touchscreen_param; + touch_params[index++] = std::move(touchscreen_param); } const auto button_index = @@ -59,7 +59,7 @@ void EmulatedConsole::SetTouchParams() { touch_button_params.Set("button", params.Serialize()); touch_button_params.Set("x", x); touch_button_params.Set("y", y); - touch_params[index] = touch_button_params; + touch_params[index] = std::move(touch_button_params); index++; } } @@ -131,7 +131,7 @@ Common::ParamPackage EmulatedConsole::GetMotionParam() const { } void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { - motion_params = param; + motion_params = std::move(param); ReloadInput(); } @@ -284,7 +284,7 @@ void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) { int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) { std::scoped_lock lock{callback_mutex}; - callback_list.insert_or_assign(last_callback_key, update_callback); + callback_list.insert_or_assign(last_callback_key, std::move(update_callback)); return last_callback_key++; } From 7bf4b453497ac445a94b295b1e4041e790e8f298 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 5 Dec 2022 18:14:31 -0500 Subject: [PATCH 2/4] emulated_console: Amend cast in SetTouch() id is an int value, not a u32. --- src/core/hid/emulated_console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index a896a5ad86..30c2e9d170 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp @@ -199,7 +199,7 @@ void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, st if (is_new_input) { touch_value.pressed.value = true; - touch_value.id = static_cast(index); + touch_value.id = static_cast(index); } touch_value.x = touch_input.x; From 87543b9dea9c7d5644269f5bbe1f278a54a84bea Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 5 Dec 2022 18:21:01 -0500 Subject: [PATCH 3/4] emulated_controller: Use std::move() in GetMappedDevices() Avoids churning allocations in a loop. --- src/core/hid/emulated_controller.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 74c8777285..09f870eb0f 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -432,7 +432,7 @@ std::vector EmulatedController::GetMappedDevices( continue; } const auto devices_it = std::find_if( - devices.begin(), devices.end(), [param](const Common::ParamPackage param_) { + devices.begin(), devices.end(), [¶m](const Common::ParamPackage& param_) { return param.Get("engine", "") == param_.Get("engine", "") && param.Get("guid", "") == param_.Get("guid", "") && param.Get("port", 0) == param_.Get("port", 0) && @@ -441,12 +441,12 @@ std::vector EmulatedController::GetMappedDevices( if (devices_it != devices.end()) { continue; } - Common::ParamPackage device{}; + + auto& device = devices.emplace_back(); device.Set("engine", param.Get("engine", "")); device.Set("guid", param.Get("guid", "")); device.Set("port", param.Get("port", 0)); device.Set("pad", param.Get("pad", 0)); - devices.push_back(device); } for (const auto& param : stick_params) { @@ -457,7 +457,7 @@ std::vector EmulatedController::GetMappedDevices( continue; } const auto devices_it = std::find_if( - devices.begin(), devices.end(), [param](const Common::ParamPackage param_) { + devices.begin(), devices.end(), [¶m](const Common::ParamPackage& param_) { return param.Get("engine", "") == param_.Get("engine", "") && param.Get("guid", "") == param_.Get("guid", "") && param.Get("port", 0) == param_.Get("port", 0) && @@ -466,12 +466,12 @@ std::vector EmulatedController::GetMappedDevices( if (devices_it != devices.end()) { continue; } - Common::ParamPackage device{}; + + auto& device = devices.emplace_back(); device.Set("engine", param.Get("engine", "")); device.Set("guid", param.Get("guid", "")); device.Set("port", param.Get("port", 0)); device.Set("pad", param.Get("pad", 0)); - devices.push_back(device); } return devices; } From e4a16f50eff470d9c87a32143e559716171f12b2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 5 Dec 2022 18:23:17 -0500 Subject: [PATCH 4/4] emulated_controller: Remove unused parameter in GetMappedDevices() This isn't used, so it can be removed to make the function a little nicer. --- src/core/hid/emulated_controller.cpp | 3 +-- src/core/hid/emulated_controller.h | 2 +- src/yuzu/configuration/configure_input_player.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 09f870eb0f..67969e938a 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -424,8 +424,7 @@ void EmulatedController::RestoreConfig() { ReloadFromSettings(); } -std::vector EmulatedController::GetMappedDevices( - EmulatedDeviceIndex device_index) const { +std::vector EmulatedController::GetMappedDevices() const { std::vector devices; for (const auto& param : button_params) { if (!param.Has("engine")) { diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 3f83108d38..fa7a342787 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -244,7 +244,7 @@ public: void RestoreConfig(); /// Returns a vector of mapped devices from the mapped button and stick parameters - std::vector GetMappedDevices(EmulatedDeviceIndex device_index) const; + std::vector GetMappedDevices() const; // Returns the current mapped button device Common::ParamPackage GetButtonParam(std::size_t index) const; diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index ed21f4b92f..b1575b0d3e 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -855,8 +855,7 @@ void ConfigureInputPlayer::UpdateInputDeviceCombobox() { return; } - const auto devices = - emulated_controller->GetMappedDevices(Core::HID::EmulatedDeviceIndex::AllDevices); + const auto devices = emulated_controller->GetMappedDevices(); UpdateInputDevices(); if (devices.empty()) {