summaryrefslogtreecommitdiff
path: root/src/core/frontend/applets/controller.cpp
diff options
context:
space:
mode:
authorGravatar Feng Chen2021-12-18 13:57:14 +0800
committerGravatar GitHub2021-12-18 13:57:14 +0800
commite49184e6069a9d791d2df3c1958f5c4b1187e124 (patch)
treeb776caf722e0be0e680f67b0ad0842628162ef1c /src/core/frontend/applets/controller.cpp
parentImplement convert legacy to generic (diff)
parentMerge pull request #7570 from ameerj/favorites-expanded (diff)
downloadyuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/core/frontend/applets/controller.cpp')
-rw-r--r--src/core/frontend/applets/controller.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
index 03bbedf8b..6dbd38ffa 100644
--- a/src/core/frontend/applets/controller.cpp
+++ b/src/core/frontend/applets/controller.cpp
@@ -5,16 +5,15 @@
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/frontend/applets/controller.h" 7#include "core/frontend/applets/controller.h"
8#include "core/hle/service/hid/controllers/npad.h" 8#include "core/hid/emulated_controller.h"
9#include "core/hle/service/hid/hid.h" 9#include "core/hid/hid_core.h"
10#include "core/hle/service/sm/sm.h" 10#include "core/hid/hid_types.h"
11 11
12namespace Core::Frontend { 12namespace Core::Frontend {
13 13
14ControllerApplet::~ControllerApplet() = default; 14ControllerApplet::~ControllerApplet() = default;
15 15
16DefaultControllerApplet::DefaultControllerApplet(Service::SM::ServiceManager& service_manager_) 16DefaultControllerApplet::DefaultControllerApplet(HID::HIDCore& hid_core_) : hid_core{hid_core_} {}
17 : service_manager{service_manager_} {}
18 17
19DefaultControllerApplet::~DefaultControllerApplet() = default; 18DefaultControllerApplet::~DefaultControllerApplet() = default;
20 19
@@ -22,24 +21,20 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
22 const ControllerParameters& parameters) const { 21 const ControllerParameters& parameters) const {
23 LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!"); 22 LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!");
24 23
25 auto& npad =
26 service_manager.GetService<Service::HID::Hid>("hid")
27 ->GetAppletResource()
28 ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad);
29
30 auto& players = Settings::values.players.GetValue();
31
32 const std::size_t min_supported_players = 24 const std::size_t min_supported_players =
33 parameters.enable_single_mode ? 1 : parameters.min_players; 25 parameters.enable_single_mode ? 1 : parameters.min_players;
34 26
35 // Disconnect Handheld first. 27 // Disconnect Handheld first.
36 npad.DisconnectNpadAtIndex(8); 28 auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld);
29 handheld->Disconnect();
37 30
38 // Deduce the best configuration based on the input parameters. 31 // Deduce the best configuration based on the input parameters.
39 for (std::size_t index = 0; index < players.size() - 2; ++index) { 32 for (std::size_t index = 0; index < hid_core.available_controllers - 2; ++index) {
33 auto* controller = hid_core.GetEmulatedControllerByIndex(index);
34
40 // First, disconnect all controllers regardless of the value of keep_controllers_connected. 35 // First, disconnect all controllers regardless of the value of keep_controllers_connected.
41 // This makes it easy to connect the desired controllers. 36 // This makes it easy to connect the desired controllers.
42 npad.DisconnectNpadAtIndex(index); 37 controller->Disconnect();
43 38
44 // Only connect the minimum number of required players. 39 // Only connect the minimum number of required players.
45 if (index >= min_supported_players) { 40 if (index >= min_supported_players) {
@@ -49,27 +44,27 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
49 // Connect controllers based on the following priority list from highest to lowest priority: 44 // Connect controllers based on the following priority list from highest to lowest priority:
50 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld 45 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
51 if (parameters.allow_pro_controller) { 46 if (parameters.allow_pro_controller) {
52 npad.AddNewControllerAt( 47 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
53 npad.MapSettingsTypeToNPad(Settings::ControllerType::ProController), index); 48 controller->Connect();
54 } else if (parameters.allow_dual_joycons) { 49 } else if (parameters.allow_dual_joycons) {
55 npad.AddNewControllerAt( 50 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);
56 npad.MapSettingsTypeToNPad(Settings::ControllerType::DualJoyconDetached), index); 51 controller->Connect();
57 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) { 52 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) {
58 // Assign left joycons to even player indices and right joycons to odd player indices. 53 // Assign left joycons to even player indices and right joycons to odd player indices.
59 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and 54 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and
60 // a right Joycon for Player 2 in 2 Player Assist mode. 55 // a right Joycon for Player 2 in 2 Player Assist mode.
61 if (index % 2 == 0) { 56 if (index % 2 == 0) {
62 npad.AddNewControllerAt( 57 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconLeft);
63 npad.MapSettingsTypeToNPad(Settings::ControllerType::LeftJoycon), index); 58 controller->Connect();
64 } else { 59 } else {
65 npad.AddNewControllerAt( 60 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconRight);
66 npad.MapSettingsTypeToNPad(Settings::ControllerType::RightJoycon), index); 61 controller->Connect();
67 } 62 }
68 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld && 63 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld &&
69 !Settings::values.use_docked_mode.GetValue()) { 64 !Settings::values.use_docked_mode.GetValue()) {
70 // We should *never* reach here under any normal circumstances. 65 // We should *never* reach here under any normal circumstances.
71 npad.AddNewControllerAt(npad.MapSettingsTypeToNPad(Settings::ControllerType::Handheld), 66 controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Handheld);
72 index); 67 controller->Connect();
73 } else { 68 } else {
74 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!"); 69 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!");
75 } 70 }