Feat : Input : Dynamic Input Swap, Device Profile Linking and Player Device Assignement #125
No reviewers
Labels
No labels
audio
bug
confirmed
cpu
critical
development
enhancement
gpu
graphics-backend:opengl
graphics-backend:vulkan
gui
help wanted
horizon/hle
i18n
infra
input
kernel
linux
macos
suggestion
windows
No assignees
2 participants
Notifications
Due date
No due date set.
Reference
projects/Ryubing!125
Loading…
Reference in a new issue
No description provided.
Delete branch "Babib3l/Ryubing:player-input-assignments-and-dynamic-swap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Heyy everyone!
Continuing my work on the input system overhaul, this PR is mainly focused around three new features :
What are these new features and why are they bundled in the same PR you might ask?
Is a new feature that, when enabled, allows the user to switch between multiple input devices, without having to return to the settings menu. This feature can be enabled at the bottom of the Input Settings menu, next to the "global input" checkbox. A nifty new tooltip has been added for clarity.
While working on Dynamic Input Swap, one issue arose, which was that Ryujinx would use that device’s Default profile, without the user being able to specify a specific profile to use on that specific device. This feature fixes that, by allowing the user to link a profile as the device’s Default. This means that this profile will be auto loaded when selecting that same device, both when connecting it to the emulator, and when using Dynamic Input Swap. This feature can be found next to the Device Profiles dropdown, and includes a nifty new tooltip. By default, the "default" profile is linked to any device. There also is a small icon to the right of the profile name’s Right to visualise which profile is linked.
Another issue that arose while working on Dynamic Input Swap was that enabling the feature would render multi player configurations unusable. This new feature addresses this issue by adding a new menu, which allows the user to assign different Input Devices to different players. Inside this new menu, you also get the device’s linked profile and the list of which players are already assigned to which input device, below and to the right of the input device name, respectively. You also get an option to allow mapping the same input device to different players.
Nerd Zone
This PR adds a new player-level input routing layer on top of the existing
InputConfigsystem.Previously, each player effectively had one active input config, tied to one device. Given Dynamic Input Swap needs more state than that, this PR introduces a persisted
PlayerInputAssignmentmodel, which stores the player index, whether Dynamic Input Swap is enabled or not, the list of assigned input devices and an optional profile name bound to each assigned device.The new assignment data lives coexists with the existing input configs instead of replacing them, which should keep the old single-device behavior intact when Dynamic Input Swap is disabled, while allowing dynamic players to own multiple devices.
New configl types include:
AssignedInputDeviceAssignedInputDeviceTypePlayerInputAssignmentPlayerInputAssignmentHelperPlayerInputDeviceAssignmentItemPlayerInputAssignmentHelpernormalizes assignments, deduplicates device entries, preserves a primary device, and compares assignments for dirty-checking.On the runtime side,
NpadManagernow passes both the normalInputConfigand the player assignment toNpadController. When Dynamic Input Swap is disabled, Ryujinx switches to the old behavior : one player config opens one device. However, when it's enabled,NpadControlleropens every assigned keyboard/controller device it can resolve, tracks their state snapshots, and promotes the active source based on recent input.Dynamic swap currently follows a “last meaningful input wins” model (annotated in the code) :
So if the keyboard produces new input, it becomes active; if an assigned controller produces new input, that controller becomes active; if the active device stops producing input and another assigned device is held/active, the active source can fall back; and if no device has produced input yet, the initial active source is chosen from the selected config and available assigned devices.
Per-device profile binding is handled by storing the profile name on the assigned device entry. When a device is selected or resolved through Dynamic Input Swap, Ryujinx tries to load that bound profile for the matching device type. If the profile is missing, invalid, or explicitly
Default, it falls back to the generated default config for that device type.The new restore-to-defaults behavior deliberately bypasses linked profiles. This means pressing the reset button loads the real generated Default profile for the currently selected device, not the profile linked to that device.
The input settings UI now dirty-checks both the currently edited input config and the player input assignment state, meaning that assigning/unassigning devices, changing Dynamic Input Swap, or changing profile bindings correctly marks the page as modified -> in continuation of my previous efforts in #13 to clean up its behaviour.
The Assigned Devices dialog is backed by the currently available keyboard/controller device list. It also checks other players’ persisted assignments so the UI can show which players already use a device. If duplicate assignment is disabled, devices already assigned to another dynamic-swap player are disabled for the current player.
If no explicit player assignments exist yet, Ryujinx synthesizes a default assignment from the existing input config. Dynamic swap is disabled by default until the user enables it.
Signed by : 🦫
With the very generous help and support from @neo 🤗
c1184456d691034c5579WIP : Feat : Input : Dynamic Input Swap, Device Profile Linking and Device Player Assignementto WIP : Feat : Input : Dynamic Input Swap, Device Profile Linking and Player Device AssignementWIP : Feat : Input : Dynamic Input Swap, Device Profile Linking and Player Device Assignementto Feat : Input : Dynamic Input Swap, Device Profile Linking and Player Device Assignement8019e0234192be6bdf16Looks great, Bab. Just a couple of small things and it's ready to merge.
@ -284,0 +419,4 @@(newConfig.ControllerType == ConfigControllerType.JoyconPair && _rightMotionInput == null) ||oldConfig.Motion.EnableMotion != newConfig.Motion.EnableMotion ||oldConfig.Motion.MotionBackend != newConfig.Motion.MotionBackend;}This is a pretty complex logic statement. Is there a way to split this up for readability? Maybe you can set the checks within parentheses as their own variables?
Good point. I've spli this into separate named variables to improve readability :
4f745b7649@ -592,0 +1080,4 @@_activeConfig = _keyboardConfig;GamepadDriver = _keyboardDriver;break;case DynamicInputSource.Controller:Can we wrap these in braces since they span multiple lines? You may consider upgrading to switch expressions https://www.c-sharpcorner.com/article/c-sharp-8-0-new-feature-swtich-expression/
I've upgraded to a switch expression
06523b6f05@ -133,0 +216,4 @@{if (AllowDuplicateDeviceAssignment == value){return;What are we returning here?
This is an early exit from the property setter, It prevents unnecessary work (setting the backing field and calling
KeepCurrentPlayerAssignedDevicesExclusive()) and avoids redundant property change notifications.@ -429,0 +580,4 @@{if (assignment == null){return null;Since this method can return null, it may be wise to perform a null check when calling it.
The call is already guarded by .Where(assignment => assignment != null) on line 574, which filters out nulls before ClonePlayerInputAssignment is invoked. The null check inside the method is defensive programming, but it's actually redundant given the filter. I could remove it if you prefer, but it doesn't hurt to have it as a safety net imo
nah its fine, it was just unclear to me. defensive maneuvers are kinda cool ngl, saved my ass a few times before
@ -473,0 +759,4 @@? PlayerInputDevices.ToDictionary(item => (item.DeviceType, item.Id)): null;Dictionary<(AssignedInputDeviceType Type, string Id), List<string>> deviceToOtherPlayers = GetOtherPlayerDeviceAssignments();I feel that this needs a more descriptive name. "OtherPlayers" implies either that these players are not player 1, or that they're not officially players. We shouldn't be prioritizing player 1 over player 2, 3, 4, etc.
I've renamed it to
deviceToOtherAssignedPlayers41f21597f3@ -473,0 +854,4 @@foreach (AssignedInputDevice device in normalizedOtherAssignment.Devices){var key = (device.Type, device.Id);sorry D:
f32642ff10@ -576,0 +1374,4 @@(_allowDuplicateDeviceAssignment.HasValue &&_allowDuplicateDeviceAssignment.Value != GetSavedAllowDuplicateDeviceAssignment()) ||!ConfigsMatch(GetSelectedDeviceConfig(), GetDisplayedInputConfig(GetPersistedInputConfig())) ||!PlayerAssignmentsMatch(GetEditedPlayerInputAssignment(), GetPersistedPlayerInputAssignment());Same as before, its a pretty big logic statement that would benefit from being broken up for readability.
50825bdbe1@ -829,0 +1641,4 @@// Avalonia bug: setting a newly instanced ComboBox to 0// causes the selected item to show up blank// Workaround: set the box to 1 and then 0Is there a reason that we dropped these?
idk at which point they got dropped, this is a mistake on my end,
My bad :3
c6f0aee1631fbe858546adf541af03adf541af0315f78b9b1515f78b9b1560113f94c8