configuration: Migrate controller settings to emulated controller

This commit is contained in:
german77 2021-10-20 17:53:14 -05:00 committed by Narr the Reg
parent c3ff0a8ac0
commit af55dd1935
12 changed files with 140 additions and 126 deletions

View file

@ -91,7 +91,6 @@ void EmulatedController::ReloadFromSettings() {
}
void EmulatedController::ReloadInput() {
// LOG_ERROR(Service_HID, "reload config {}", NpadIdTypeToIndex(npad_id_type));
// If you load any device here add the equivalent to the UnloadInput() function
const auto left_side = button_params[Settings::NativeButton::ZL];
const auto right_side = button_params[Settings::NativeButton::ZR];

View file

@ -329,7 +329,7 @@ private:
* @param type: Input type of the event to trigger
* @param is_service_update: indicates if this event should be sended to only services
*/
void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
NpadIdType npad_id_type;
NpadType npad_type{NpadType::None};

View file

@ -111,6 +111,27 @@ NpadStyleTag HIDCore::GetSupportedStyleTag() const {
return supported_style_tag;
}
s8 HIDCore::GetPlayerCount() const {
s8 active_players = 0;
for (std::size_t player_index = 0; player_index < 8; player_index++) {
const auto* controller = GetEmulatedControllerByIndex(player_index);
if (controller->IsConnected()) {
active_players++;
}
}
return active_players;
}
NpadIdType HIDCore::GetFirstNpadId() const {
for (std::size_t player_index = 0; player_index < 10; player_index++) {
const auto* controller = GetEmulatedControllerByIndex(player_index);
if (controller->IsConnected()) {
return controller->GetNpadIdType();
}
}
return NpadIdType::Player1;
}
void HIDCore::ReloadInputDevices() {
player_1->ReloadFromSettings();
player_2->ReloadFromSettings();

View file

@ -35,10 +35,16 @@ public:
void SetSupportedStyleTag(NpadStyleTag style_tag);
NpadStyleTag GetSupportedStyleTag() const;
// Reloads all input devices from settings
/// Counts the connected players from P1-P8
s8 GetPlayerCount() const;
/// Returns the first connected npad id
NpadIdType GetFirstNpadId() const;
/// Reloads all input devices from settings
void ReloadInputDevices();
// Removes all callbacks from input common
/// Removes all callbacks from input common
void UnloadInputDevices();
private:

View file

@ -243,19 +243,11 @@ void Controller::Execute() {
void Controller::ConfigurationComplete() {
ControllerSupportResultInfo result_info{};
const auto& players = Settings::values.players.GetValue();
// If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
// Otherwise, only count connected players from P1-P8.
result_info.player_count =
is_single_mode
? 1
: static_cast<s8>(std::count_if(players.begin(), players.end() - 2,
[](const auto& player) { return player.connected; }));
result_info.player_count = is_single_mode ? 1 : system.HIDCore().GetPlayerCount();
result_info.selected_id = HID::Controller_NPad::IndexToNPad(std::distance(
players.begin(), std::find_if(players.begin(), players.end(),
[](const auto& player) { return player.connected; })));
result_info.selected_id = static_cast<u32>(system.HIDCore().GetFirstNpadId());
result_info.result = 0;