From 9495ebb1c2b2b2c090a5e5ae35c31c00fa570f9f Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 26 Feb 2023 23:49:58 +0100 Subject: [PATCH] early-access version 3419 --- README.md | 2 +- src/common/settings.h | 2 +- src/core/hid/emulated_controller.cpp | 69 +++------------- src/core/hid/emulated_controller.h | 7 +- src/core/hid/hid_types.h | 26 ------ src/yuzu/applets/qt_controller.cpp | 9 ++- src/yuzu/configuration/config.cpp | 7 +- src/yuzu/configuration/configure_input.cpp | 1 - .../configure_input_per_game.cpp | 16 +++- .../configuration/configure_input_player.cpp | 80 +++++++++++++++++-- 10 files changed, 112 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index bea9efc1e..752015240 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3418. +This is the source code for early-access 3419. ## Legal Notice diff --git a/src/common/settings.h b/src/common/settings.h index 2ccfd936f..eecd0c5ab 100755 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -482,7 +482,7 @@ struct Values { SwitchableSetting sound_index{1, 0, 2, "sound_index"}; // Controls - InputSetting> players; + InputSetting> players; SwitchableSetting use_docked_mode{true, "use_docked_mode"}; diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 50d2258ac..1e3d93b47 100755 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -82,12 +82,7 @@ Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadStyleInde } void EmulatedController::ReloadFromSettings() { - if (npad_id_type == NpadIdType::Other) { - ReloadDebugPadFromSettings(); - return; - } - - const auto player_index = NpadIdTypeToConfigIndex(npad_id_type); + const auto player_index = NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; for (std::size_t index = 0; index < player.buttons.size(); ++index) { @@ -116,25 +111,16 @@ void EmulatedController::ReloadFromSettings() { ring_params[0] = Common::ParamPackage(Settings::values.ringcon_analogs); - // Player 1 shares config with handheld. Disable controller when handheld is selected - // if (npad_id_type == NpadIdType::Player1 && npad_type == NpadStyleIndex::Handheld) { - // Disconnect(); - // ReloadInput(); - // return; - //} - - // Handheld shares config with player 1. Disable controller when handheld isn't selected - if (npad_id_type == NpadIdType::Handheld && npad_type != NpadStyleIndex::Handheld) { - Disconnect(); - ReloadInput(); - return; + // Other or debug controller should always be a pro controller + if (npad_id_type != NpadIdType::Other) { + SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type)); + original_npad_type = npad_type; + } else { + SetNpadStyleIndex(NpadStyleIndex::ProController); + original_npad_type = npad_type; } Disconnect(); - - SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type)); - original_npad_type = npad_type; - if (player.connected) { Connect(); } @@ -142,33 +128,6 @@ void EmulatedController::ReloadFromSettings() { ReloadInput(); } -void EmulatedController::ReloadDebugPadFromSettings() { - for (std::size_t index = 0; index < Settings::values.debug_pad_buttons.size(); ++index) { - button_params[index] = Common::ParamPackage(Settings::values.debug_pad_buttons[index]); - } - for (std::size_t index = 0; index < Settings::values.debug_pad_analogs.size(); ++index) { - stick_params[index] = Common::ParamPackage(Settings::values.debug_pad_analogs[index]); - } - for (std::size_t index = 0; index < motion_params.size(); ++index) { - motion_params[index] = {}; - } - - controller.color_values = {}; - controller.colors_state.fullkey = {}; - controller.colors_state.left = {}; - controller.colors_state.right = {}; - ring_params[0] = {}; - SetNpadStyleIndex(NpadStyleIndex::ProController); - original_npad_type = npad_type; - - Disconnect(); - if (Settings::values.debug_pad_enabled) { - Connect(); - } - - ReloadInput(); -} - void EmulatedController::LoadDevices() { // TODO(german77): Use more buttons to detect the correct device const auto left_joycon = button_params[Settings::NativeButton::DRight]; @@ -601,14 +560,8 @@ bool EmulatedController::IsConfiguring() const { } void EmulatedController::SaveCurrentConfig() { - // Other and Handheld can't alter the config from here - if (npad_id_type == NpadIdType::Other || npad_id_type == NpadIdType::Handheld) { - return; - } - - const auto player_index = NpadIdTypeToConfigIndex(npad_id_type); + const auto player_index = NpadIdTypeToIndex(npad_id_type); auto& player = Settings::values.players.GetValue()[player_index]; - player.connected = is_connected; player.controller_type = MapNPadToSettingsType(npad_type); for (std::size_t index = 0; index < player.buttons.size(); ++index) { @@ -1199,7 +1152,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v if (!output_devices[device_index]) { return false; } - const auto player_index = NpadIdTypeToConfigIndex(npad_id_type); + const auto player_index = NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; const f32 strength = static_cast(player.vibration_strength) / 100.0f; @@ -1225,7 +1178,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v } bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { - const auto player_index = NpadIdTypeToConfigIndex(npad_id_type); + const auto player_index = NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; if (!player.vibration_enabled) { diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 2000e33c7..4da1e9d60 100755 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -250,14 +250,9 @@ public: /// Reload all input devices void ReloadInput(); - /// Overrides current mapped devices with the stored configuration and reloads all input - /// callbacks + /// Overrides current mapped devices with the stored configuration and reloads all input devices void ReloadFromSettings(); - /// Overrides current mapped debug pad with the stored configuration and reloads all input - /// callbacks - void ReloadDebugPadFromSettings(); - /// Saves the current mapped configuration void SaveCurrentConfig(); diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 5e97e3459..156480228 100755 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h @@ -690,32 +690,6 @@ constexpr size_t NpadIdTypeToIndex(NpadIdType npad_id_type) { } } -/// Converts a NpadIdType to a config array index. -constexpr size_t NpadIdTypeToConfigIndex(NpadIdType npad_id_type) { - switch (npad_id_type) { - case NpadIdType::Player1: - return 0; - case NpadIdType::Player2: - return 1; - case NpadIdType::Player3: - return 2; - case NpadIdType::Player4: - return 3; - case NpadIdType::Player5: - return 4; - case NpadIdType::Player6: - return 5; - case NpadIdType::Player7: - return 6; - case NpadIdType::Player8: - return 7; - case NpadIdType::Other: - case NpadIdType::Handheld: - default: - return 0; - } -} - /// Converts an array index to a NpadIdType constexpr NpadIdType IndexToNpadIdType(size_t index) { switch (index) { diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp index 56aa17fd1..397eeefad 100755 --- a/src/yuzu/applets/qt_controller.cpp +++ b/src/yuzu/applets/qt_controller.cpp @@ -542,14 +542,19 @@ void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index) const auto player_connected = player_groupboxes[player_index]->isChecked() && controller_type != Core::HID::NpadStyleIndex::Handheld; + if (controller->GetNpadStyleIndex(true) == controller_type && + controller->IsConnected(true) == player_connected) { + return; + } + // Disconnect the controller first. UpdateController(controller, controller_type, false); // Handheld if (player_index == 0) { - auto* handheld = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld); - UpdateController(handheld, controller_type, false); if (controller_type == Core::HID::NpadStyleIndex::Handheld) { + auto* handheld = + system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld); UpdateController(handheld, Core::HID::NpadStyleIndex::Handheld, player_groupboxes[player_index]->isChecked()); } diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 4e0aed618..c1fa8f2a2 100755 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -212,11 +212,16 @@ void Config::ReadPlayerValue(std::size_t player_index) { } if (player_prefix.isEmpty() && Settings::IsConfiguringGlobal()) { - player.controller_type = static_cast( + const auto controller = static_cast( qt_config ->value(QStringLiteral("%1type").arg(player_prefix), static_cast(Settings::ControllerType::ProController)) .toUInt()); + + if (controller == Settings::ControllerType::LeftJoycon || + controller == Settings::ControllerType::RightJoycon) { + player.controller_type = controller; + } } else { player.connected = ReadSetting(QStringLiteral("%1connected").arg(player_prefix), player_index == 0) diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 855a422ad..d0cf94dfc 100755 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp @@ -194,7 +194,6 @@ void ConfigureInput::ApplyConfiguration() { } advanced->ApplyConfiguration(); - system.HIDCore().ReloadInputDevices(); const bool pre_docked_mode = Settings::values.use_docked_mode.GetValue(); Settings::values.use_docked_mode.SetValue(ui->radioDocked->isChecked()); diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index ef94e8033..78e65d468 100755 --- a/src/yuzu/configuration/configure_input_per_game.cpp +++ b/src/yuzu/configuration/configure_input_per_game.cpp @@ -57,7 +57,7 @@ void ConfigureInputPerGame::ApplyConfiguration() { } void ConfigureInputPerGame::LoadConfiguration() { - static constexpr size_t HANDHELD_INDEX = 0; + static constexpr size_t HANDHELD_INDEX = 8; auto& hid_core = system.HIDCore(); for (size_t player_index = 0; player_index < profile_comboboxes.size(); ++player_index) { @@ -69,6 +69,9 @@ void ConfigureInputPerGame::LoadConfiguration() { const auto selection_index = player_combobox->currentIndex(); if (selection_index == 0) { Settings::values.players.GetValue()[player_index].profile_name = ""; + if (player_index == 0) { + Settings::values.players.GetValue()[HANDHELD_INDEX] = {}; + } Settings::values.players.SetGlobal(true); emulated_controller->ReloadFromSettings(); continue; @@ -86,12 +89,17 @@ void ConfigureInputPerGame::LoadConfiguration() { emulated_controller->ReloadFromSettings(); - if (player_index != HANDHELD_INDEX) { + if (player_index > 0) { continue; } - // Handle Handheld cases - auto handheld_controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + auto& handheld_player = Settings::values.players.GetValue()[HANDHELD_INDEX]; + auto* handheld_controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + if (player.controller_type == Settings::ControllerType::Handheld) { + handheld_player = player; + } else { + handheld_player = {}; + } handheld_controller->ReloadFromSettings(); } } diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 2c30ac086..2fff66ef2 100755 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -295,11 +295,26 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i is_powered_on{is_powered_on_}, input_subsystem{input_subsystem_}, profiles(profiles_), timeout_timer(std::make_unique()), poll_timer(std::make_unique()), bottom_row{bottom_row_}, hid_core{hid_core_} { - - emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); - emulated_controller->SaveCurrentConfig(); - emulated_controller->EnableConfiguration(); - + if (player_index == 0) { + auto* emulated_controller_p1 = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); + auto* emulated_controller_handheld = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + emulated_controller_p1->SaveCurrentConfig(); + emulated_controller_p1->EnableConfiguration(); + emulated_controller_handheld->SaveCurrentConfig(); + emulated_controller_handheld->EnableConfiguration(); + if (emulated_controller_handheld->IsConnected(true)) { + emulated_controller_p1->Disconnect(); + emulated_controller = emulated_controller_handheld; + } else { + emulated_controller = emulated_controller_p1; + } + } else { + emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); + emulated_controller->SaveCurrentConfig(); + emulated_controller->EnableConfiguration(); + } ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); @@ -722,6 +737,29 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i UpdateMotionButtons(); const Core::HID::NpadStyleIndex type = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); + + if (player_index == 0) { + auto* emulated_controller_p1 = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); + auto* emulated_controller_handheld = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + bool is_connected = emulated_controller->IsConnected(true); + + emulated_controller_p1->SetNpadStyleIndex(type); + emulated_controller_handheld->SetNpadStyleIndex(type); + if (is_connected) { + if (type == Core::HID::NpadStyleIndex::Handheld) { + emulated_controller_p1->Disconnect(); + emulated_controller_handheld->Connect(true); + emulated_controller = emulated_controller_handheld; + } else { + emulated_controller_handheld->Disconnect(); + emulated_controller_p1->Connect(true); + emulated_controller = emulated_controller_p1; + } + } + ui->controllerFrame->SetController(emulated_controller); + } emulated_controller->SetNpadStyleIndex(type); }); @@ -757,10 +795,32 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } ConfigureInputPlayer::~ConfigureInputPlayer() { - emulated_controller->DisableConfiguration(); + if (player_index == 0) { + auto* emulated_controller_p1 = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); + auto* emulated_controller_handheld = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + emulated_controller_p1->DisableConfiguration(); + emulated_controller_handheld->DisableConfiguration(); + } else { + emulated_controller->DisableConfiguration(); + } } void ConfigureInputPlayer::ApplyConfiguration() { + if (player_index == 0) { + auto* emulated_controller_p1 = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); + auto* emulated_controller_handheld = + hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + emulated_controller_p1->DisableConfiguration(); + emulated_controller_p1->SaveCurrentConfig(); + emulated_controller_p1->EnableConfiguration(); + emulated_controller_handheld->DisableConfiguration(); + emulated_controller_handheld->SaveCurrentConfig(); + emulated_controller_handheld->EnableConfiguration(); + return; + } emulated_controller->DisableConfiguration(); emulated_controller->SaveCurrentConfig(); emulated_controller->EnableConfiguration(); @@ -1529,6 +1589,7 @@ void ConfigureInputPlayer::LoadProfile() { } void ConfigureInputPlayer::SaveProfile() { + static constexpr size_t HANDHELD_INDEX = 8; const QString profile_name = ui->comboProfiles->itemText(ui->comboProfiles->currentIndex()); if (profile_name.isEmpty()) { @@ -1537,7 +1598,12 @@ void ConfigureInputPlayer::SaveProfile() { ApplyConfiguration(); - if (!profiles->SaveProfile(profile_name.toStdString(), player_index)) { + // When we're in handheld mode, only the handheld emulated controller bindings are updated + const bool is_handheld = player_index == 0 && emulated_controller->GetNpadIdType() == + Core::HID::NpadIdType::Handheld; + const auto profile_player_index = is_handheld ? HANDHELD_INDEX : player_index; + + if (!profiles->SaveProfile(profile_name.toStdString(), profile_player_index)) { QMessageBox::critical(this, tr("Save Input Profile"), tr("Failed to save the input profile \"%1\"").arg(profile_name)); UpdateInputProfiles();