changed var name; fixed class name; removed hashset argument from GetConfiguredController function.

This commit is contained in:
uncavo-hdmi 2025-02-22 10:15:41 +01:00
parent da268ebbee
commit 72c3ca7769
3 changed files with 215 additions and 218 deletions

View File

@ -1,11 +1,6 @@
using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.UI.ViewModels;
using Ryujinx.Ava.Utilities.Configuration; using Ryujinx.Ava.Utilities.Configuration;
using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Common.Configuration.Hid.Controller.Motion;
using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId;
using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.HLE; using Ryujinx.Input.HLE;
@ -20,7 +15,7 @@ namespace Ryujinx.Ava.Input
private readonly InputManager _inputManager; private readonly InputManager _inputManager;
private readonly MainWindowViewModel _viewModel; private readonly MainWindowViewModel _viewModel;
private readonly ConfigurationState _configurationState; private readonly ConfigurationState _configurationState;
private readonly ControllerConfigurator _controllerConfigurator; private readonly ControllerAssignmentManager _assignmentManager;
public event Action ConfigurationUpdated; public event Action ConfigurationUpdated;
@ -29,7 +24,7 @@ namespace Ryujinx.Ava.Input
_inputManager = inputManager; _inputManager = inputManager;
_viewModel = mainWindowViewModel; _viewModel = mainWindowViewModel;
_configurationState = ConfigurationState.Instance; _configurationState = ConfigurationState.Instance;
_controllerConfigurator = new ControllerConfigurator(); _assignmentManager = new ControllerAssignmentManager();
_inputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _inputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
_inputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; _inputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
@ -56,8 +51,8 @@ namespace Ryujinx.Ava.Input
List<IGamepad> controllers = _inputManager.GamepadDriver.GetGamepads().ToList(); List<IGamepad> controllers = _inputManager.GamepadDriver.GetGamepads().ToList();
List<InputConfig> oldConfig = _configurationState.Hid.InputConfig.Value.Where(x => x != null).ToList(); List<InputConfig> oldConfig = _configurationState.Hid.InputConfig.Value.Where(x => x != null).ToList();
List<InputConfig> newConfig = _controllerConfigurator.GetConfiguredControllers( List<InputConfig> newConfig = _assignmentManager.GetConfiguredControllers(
controllers, oldConfig, new HashSet<int>(), out bool hasNewControllersConnected); controllers, oldConfig, out bool hasNewControllersConnected);
_viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse); _viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse);
@ -66,7 +61,7 @@ namespace Ryujinx.Ava.Input
// there is no *new* controller, we must switch the order of the controllers in // there is no *new* controller, we must switch the order of the controllers in
// oldConfig to match the new order since probably a controller was disconnected // oldConfig to match the new order since probably a controller was disconnected
// or an old controller was reconnected // or an old controller was reconnected
newConfig = _controllerConfigurator.ReorderControllers(newConfig, oldConfig); newConfig = ControllerAssignmentManager.ReorderControllers(newConfig, oldConfig);
} }
_configurationState.Hid.InputConfig.Value = newConfig; _configurationState.Hid.InputConfig.Value = newConfig;

View File

@ -10,7 +10,7 @@ using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.Input namespace Ryujinx.Ava.Input
{ {
public class ControllerConfigurator public class ControllerAssignmentManager
{ {
private readonly uint[] _playerColors = private readonly uint[] _playerColors =
[ [
@ -26,7 +26,7 @@ namespace Ryujinx.Ava.Input
private const int MaxControllers = 9; private const int MaxControllers = 9;
public List<InputConfig> ReorderControllers(List<InputConfig> newConfig, List<InputConfig> oldConfig) public static List<InputConfig> ReorderControllers(List<InputConfig> newConfig, List<InputConfig> oldConfig)
{ {
List<InputConfig> reorderedConfig = oldConfig.Select(config => new GamepadInputConfig(config).GetConfig()).ToList(); List<InputConfig> reorderedConfig = oldConfig.Select(config => new GamepadInputConfig(config).GetConfig()).ToList();
@ -46,7 +46,6 @@ namespace Ryujinx.Ava.Input
public List<InputConfig> GetConfiguredControllers( public List<InputConfig> GetConfiguredControllers(
List<IGamepad> controllers, List<IGamepad> controllers,
List<InputConfig> oldConfig, List<InputConfig> oldConfig,
HashSet<int> usedIndices,
out bool hasNewControllersConnected) out bool hasNewControllersConnected)
{ {
Dictionary<string, InputConfig> oldConfigMap = oldConfig Dictionary<string, InputConfig> oldConfigMap = oldConfig
@ -54,6 +53,7 @@ namespace Ryujinx.Ava.Input
.ToDictionary(x => x.Id); .ToDictionary(x => x.Id);
Dictionary<int, InputConfig> playerIndexMap = new(); Dictionary<int, InputConfig> playerIndexMap = new();
HashSet<int> usedIndices = [];
int recognizedControllersCount = 0; int recognizedControllersCount = 0;
List<IGamepad> remainingControllers = controllers.Where(c => c?.Id != null).ToList(); List<IGamepad> remainingControllers = controllers.Where(c => c?.Id != null).ToList();
@ -76,7 +76,7 @@ namespace Ryujinx.Ava.Input
return orderedConfigs; return orderedConfigs;
} }
private void AddExistingControllers( private static void AddExistingControllers(
List<IGamepad> controllers, List<IGamepad> controllers,
Dictionary<string, InputConfig> oldConfigMap, Dictionary<string, InputConfig> oldConfigMap,
Dictionary<int, InputConfig> playerIndexMap, Dictionary<int, InputConfig> playerIndexMap,
@ -85,8 +85,11 @@ namespace Ryujinx.Ava.Input
{ {
foreach (var controller in controllers.ToList()) foreach (var controller in controllers.ToList())
{ {
if (oldConfigMap.TryGetValue(controller.Id, out InputConfig existingConfig)) if (!oldConfigMap.TryGetValue(controller.Id, out InputConfig existingConfig))
{ {
continue;
}
int desiredIndex = (int)existingConfig.PlayerIndex; int desiredIndex = (int)existingConfig.PlayerIndex;
// Ensure the index is valid and available // Ensure the index is valid and available
@ -106,9 +109,8 @@ namespace Ryujinx.Ava.Input
controllers.Remove(controller); controllers.Remove(controller);
} }
} }
}
private void AddNewControllers( private static void AddNewControllers(
List<IGamepad> controllers, List<IGamepad> controllers,
Dictionary<int, InputConfig> playerIndexMap, Dictionary<int, InputConfig> playerIndexMap,
HashSet<int> usedIndices) HashSet<int> usedIndices)
@ -123,7 +125,7 @@ namespace Ryujinx.Ava.Input
} }
} }
private int GetFirstAvailableIndex(HashSet<int> usedIndices) private static int GetFirstAvailableIndex(HashSet<int> usedIndices)
{ {
for (int i = 0; i < MaxControllers; i++) for (int i = 0; i < MaxControllers; i++)
{ {