yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Merge pull request #9389 from lioncash/emumove

emulated_console/emulated_controller: std::move ParamPackage instances where applicable
This commit is contained in:
liamwhite 2022-12-06 11:26:46 -05:00 committed by GitHub
commit bbdb6d391e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -37,7 +37,7 @@ void EmulatedConsole::SetTouchParams() {
touchscreen_param.Set("axis_x", i * 2); touchscreen_param.Set("axis_x", i * 2);
touchscreen_param.Set("axis_y", (i * 2) + 1); touchscreen_param.Set("axis_y", (i * 2) + 1);
touchscreen_param.Set("button", i); touchscreen_param.Set("button", i);
touch_params[index++] = touchscreen_param; touch_params[index++] = std::move(touchscreen_param);
} }
const auto button_index = const auto button_index =
@ -59,7 +59,7 @@ void EmulatedConsole::SetTouchParams() {
touch_button_params.Set("button", params.Serialize()); touch_button_params.Set("button", params.Serialize());
touch_button_params.Set("x", x); touch_button_params.Set("x", x);
touch_button_params.Set("y", y); touch_button_params.Set("y", y);
touch_params[index] = touch_button_params; touch_params[index] = std::move(touch_button_params);
index++; index++;
} }
} }
@ -131,7 +131,7 @@ Common::ParamPackage EmulatedConsole::GetMotionParam() const {
} }
void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
motion_params = param; motion_params = std::move(param);
ReloadInput(); ReloadInput();
} }
@ -199,7 +199,7 @@ void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, st
if (is_new_input) { if (is_new_input) {
touch_value.pressed.value = true; touch_value.pressed.value = true;
touch_value.id = static_cast<u32>(index); touch_value.id = static_cast<int>(index);
} }
touch_value.x = touch_input.x; touch_value.x = touch_input.x;
@ -284,7 +284,7 @@ void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) {
int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) { int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) {
std::scoped_lock lock{callback_mutex}; 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++; return last_callback_key++;
} }

View File

@ -424,15 +424,14 @@ void EmulatedController::RestoreConfig() {
ReloadFromSettings(); ReloadFromSettings();
} }
std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices( std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices() const {
EmulatedDeviceIndex device_index) const {
std::vector<Common::ParamPackage> devices; std::vector<Common::ParamPackage> devices;
for (const auto& param : button_params) { for (const auto& param : button_params) {
if (!param.Has("engine")) { if (!param.Has("engine")) {
continue; continue;
} }
const auto devices_it = std::find_if( const auto devices_it = std::find_if(
devices.begin(), devices.end(), [param](const Common::ParamPackage param_) { devices.begin(), devices.end(), [&param](const Common::ParamPackage& param_) {
return param.Get("engine", "") == param_.Get("engine", "") && return param.Get("engine", "") == param_.Get("engine", "") &&
param.Get("guid", "") == param_.Get("guid", "") && param.Get("guid", "") == param_.Get("guid", "") &&
param.Get("port", 0) == param_.Get("port", 0) && param.Get("port", 0) == param_.Get("port", 0) &&
@ -441,12 +440,12 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
if (devices_it != devices.end()) { if (devices_it != devices.end()) {
continue; continue;
} }
Common::ParamPackage device{};
auto& device = devices.emplace_back();
device.Set("engine", param.Get("engine", "")); device.Set("engine", param.Get("engine", ""));
device.Set("guid", param.Get("guid", "")); device.Set("guid", param.Get("guid", ""));
device.Set("port", param.Get("port", 0)); device.Set("port", param.Get("port", 0));
device.Set("pad", param.Get("pad", 0)); device.Set("pad", param.Get("pad", 0));
devices.push_back(device);
} }
for (const auto& param : stick_params) { for (const auto& param : stick_params) {
@ -457,7 +456,7 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
continue; continue;
} }
const auto devices_it = std::find_if( const auto devices_it = std::find_if(
devices.begin(), devices.end(), [param](const Common::ParamPackage param_) { devices.begin(), devices.end(), [&param](const Common::ParamPackage& param_) {
return param.Get("engine", "") == param_.Get("engine", "") && return param.Get("engine", "") == param_.Get("engine", "") &&
param.Get("guid", "") == param_.Get("guid", "") && param.Get("guid", "") == param_.Get("guid", "") &&
param.Get("port", 0) == param_.Get("port", 0) && param.Get("port", 0) == param_.Get("port", 0) &&
@ -466,12 +465,12 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
if (devices_it != devices.end()) { if (devices_it != devices.end()) {
continue; continue;
} }
Common::ParamPackage device{};
auto& device = devices.emplace_back();
device.Set("engine", param.Get("engine", "")); device.Set("engine", param.Get("engine", ""));
device.Set("guid", param.Get("guid", "")); device.Set("guid", param.Get("guid", ""));
device.Set("port", param.Get("port", 0)); device.Set("port", param.Get("port", 0));
device.Set("pad", param.Get("pad", 0)); device.Set("pad", param.Get("pad", 0));
devices.push_back(device);
} }
return devices; return devices;
} }

View File

@ -244,7 +244,7 @@ public:
void RestoreConfig(); void RestoreConfig();
/// Returns a vector of mapped devices from the mapped button and stick parameters /// Returns a vector of mapped devices from the mapped button and stick parameters
std::vector<Common::ParamPackage> GetMappedDevices(EmulatedDeviceIndex device_index) const; std::vector<Common::ParamPackage> GetMappedDevices() const;
// Returns the current mapped button device // Returns the current mapped button device
Common::ParamPackage GetButtonParam(std::size_t index) const; Common::ParamPackage GetButtonParam(std::size_t index) const;

View File

@ -855,8 +855,7 @@ void ConfigureInputPlayer::UpdateInputDeviceCombobox() {
return; return;
} }
const auto devices = const auto devices = emulated_controller->GetMappedDevices();
emulated_controller->GetMappedDevices(Core::HID::EmulatedDeviceIndex::AllDevices);
UpdateInputDevices(); UpdateInputDevices();
if (devices.empty()) { if (devices.empty()) {