diff --git a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs index 43f238ef..387ae772 100644 --- a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs +++ b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs @@ -1,9 +1,10 @@ -using OpenTK.Audio; +using OpenTK.Audio.OpenAL; using Ryujinx.Audio.Common; using Ryujinx.Audio.Integration; using Ryujinx.Memory; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; @@ -12,8 +13,8 @@ namespace Ryujinx.Audio.Backends.OpenAL public class OpenALHardwareDeviceDriver : IHardwareDeviceDriver { private object _lock = new object(); - - private AudioContext _context; + private ALDevice _device; + private ALContext _context; private ManualResetEvent _updateRequiredEvent; private List _sessions; private bool _stillRunning; @@ -21,7 +22,8 @@ namespace Ryujinx.Audio.Backends.OpenAL public OpenALHardwareDeviceDriver() { - _context = new AudioContext(); + _device = ALC.OpenDevice(""); + _context = ALC.CreateContext(_device, new ALContextAttributes()); _updateRequiredEvent = new ManualResetEvent(false); _sessions = new List(); @@ -40,7 +42,7 @@ namespace Ryujinx.Audio.Backends.OpenAL { try { - return AudioContext.AvailableDevices.Count > 0; + return ALC.GetStringList(GetEnumerationStringList.DeviceSpecifier).Any(); } catch { @@ -95,6 +97,8 @@ namespace Ryujinx.Audio.Backends.OpenAL private void Update() { + ALC.MakeContextCurrent(_context); + while (_stillRunning) { bool updateRequired = false; @@ -143,7 +147,8 @@ namespace Ryujinx.Audio.Backends.OpenAL } } - _context.Dispose(); + ALC.DestroyContext(_context); + ALC.CloseDevice(_device); } } diff --git a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs index 055c608b..f0227bf8 100644 --- a/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs +++ b/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs @@ -71,11 +71,11 @@ namespace Ryujinx.Audio.Backends.OpenAL OpenALAudioBuffer driverBuffer = new OpenALAudioBuffer { DriverIdentifier = buffer.DataPointer, - BufferId = AL.GenBuffer(), - SampleCount = GetSampleCount(buffer) + BufferId = AL.GenBuffer(), + SampleCount = GetSampleCount(buffer) }; - AL.BufferData(driverBuffer.BufferId, _targetFormat, buffer.Data, (int)buffer.DataSize, (int)RequestedSampleRate); + AL.BufferData(driverBuffer.BufferId, _targetFormat, buffer.Data, (int)RequestedSampleRate); _queuedBuffers.Enqueue(driverBuffer); @@ -125,7 +125,7 @@ namespace Ryujinx.Audio.Backends.OpenAL } } - public override void UnregisterBuffer(AudioBuffer buffer) {} + public override void UnregisterBuffer(AudioBuffer buffer) { } public override bool WasBufferFullyConsumed(AudioBuffer buffer) { diff --git a/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj b/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj index 187fe0fe..4619d73d 100644 --- a/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj +++ b/Ryujinx.Audio.Backends.OpenAL/Ryujinx.Audio.Backends.OpenAL.csproj @@ -5,7 +5,7 @@ - + diff --git a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs index 32e76375..1d47051a 100644 --- a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs +++ b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 23; + public const int CurrentVersion = 24; public int Version { get; set; } @@ -224,14 +224,23 @@ namespace Ryujinx.Configuration public KeyboardHotkeys Hotkeys { get; set; } /// - /// Keyboard control bindings + /// Legacy keyboard control bindings /// - public List KeyboardConfig { get; set; } + /// Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions) + /// TODO: Remove this when those older versions aren't in use anymore. + public List KeyboardConfig { get; set; } /// - /// Controller control bindings + /// Legacy controller control bindings /// - public List ControllerConfig { get; set; } + /// Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions) + /// TODO: Remove this when those older versions aren't in use anymore. + public List ControllerConfig { get; set; } + + /// + /// Input configurations + /// + public List InputConfig { get; set; } /// /// Loads a configuration file from disk diff --git a/Ryujinx.Common/Configuration/ConfigurationState.cs b/Ryujinx.Common/Configuration/ConfigurationState.cs index 1e26b4f4..7063110f 100644 --- a/Ryujinx.Common/Configuration/ConfigurationState.cs +++ b/Ryujinx.Common/Configuration/ConfigurationState.cs @@ -1,8 +1,8 @@ using Ryujinx.Common; using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Configuration.Hid.Keyboard; using Ryujinx.Common.Logging; -using Ryujinx.Configuration.Hid; using Ryujinx.Configuration.System; using Ryujinx.Configuration.Ui; using System; @@ -405,21 +405,6 @@ namespace Ryujinx.Configuration public ConfigurationFileFormat ToFileFormat() { - List controllerConfigList = new List(); - List keyboardConfigList = new List(); - - foreach (InputConfig inputConfig in Hid.InputConfig.Value) - { - if (inputConfig is ControllerConfig controllerConfig) - { - controllerConfigList.Add(controllerConfig); - } - else if (inputConfig is KeyboardConfig keyboardConfig) - { - keyboardConfigList.Add(keyboardConfig); - } - } - ConfigurationFileFormat configurationFile = new ConfigurationFileFormat { Version = ConfigurationFileFormat.CurrentVersion, @@ -479,8 +464,9 @@ namespace Ryujinx.Configuration StartFullscreen = Ui.StartFullscreen, EnableKeyboard = Hid.EnableKeyboard, Hotkeys = Hid.Hotkeys, - KeyboardConfig = keyboardConfigList, - ControllerConfig = controllerConfigList + KeyboardConfig = new List(), + ControllerConfig = new List(), + InputConfig = Hid.InputConfig, }; return configurationFile; @@ -543,54 +529,57 @@ namespace Ryujinx.Configuration }; Hid.InputConfig.Value = new List { - new KeyboardConfig - { - Index = 0, - ControllerType = ControllerType.JoyconPair, - PlayerIndex = PlayerIndex.Player1, - LeftJoycon = new NpadKeyboardLeft - { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, - DPadUp = Key.Up, - DPadDown = Key.Down, - DPadLeft = Key.Left, - DPadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Home, - ButtonSr = Key.End - }, - RightJoycon = new NpadKeyboardRight - { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.PageUp, - ButtonSr = Key.PageDown - }, - EnableMotion = false, - MirrorInput = false, - Slot = 0, - AltSlot = 0, - Sensitivity = 100, - GyroDeadzone = 1, - DsuServerHost = "127.0.0.1", - DsuServerPort = 26760 - } + new StandardKeyboardInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.WindowKeyboard, + Id = "0", + PlayerIndex = PlayerIndex.Player1, + ControllerType = ControllerType.JoyconPair, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = Key.Up, + DpadDown = Key.Down, + DpadLeft = Key.Left, + DpadRight = Key.Right, + ButtonMinus = Key.Minus, + ButtonL = Key.E, + ButtonZl = Key.Q, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + LeftJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.W, + StickDown = Key.S, + StickLeft = Key.A, + StickRight = Key.D, + StickButton = Key.F, + }, + + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = Key.Z, + ButtonB = Key.X, + ButtonX = Key.C, + ButtonY = Key.V, + ButtonPlus = Key.Plus, + ButtonR = Key.U, + ButtonZr = Key.O, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.I, + StickDown = Key.K, + StickLeft = Key.J, + StickRight = Key.L, + StickButton = Key.H, + } + } }; } @@ -643,80 +632,6 @@ namespace Ryujinx.Configuration configurationFileUpdated = true; } - if (configurationFileFormat.Version < 6) - { - Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 6."); - - configurationFileFormat.ControllerConfig = new List(); - configurationFileFormat.KeyboardConfig = new List - { - new KeyboardConfig - { - Index = 0, - ControllerType = ControllerType.JoyconPair, - PlayerIndex = PlayerIndex.Player1, - LeftJoycon = new NpadKeyboardLeft - { - StickUp = Key.W, - StickDown = Key.S, - StickLeft = Key.A, - StickRight = Key.D, - StickButton = Key.F, - DPadUp = Key.Up, - DPadDown = Key.Down, - DPadLeft = Key.Left, - DPadRight = Key.Right, - ButtonMinus = Key.Minus, - ButtonL = Key.E, - ButtonZl = Key.Q, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound - }, - RightJoycon = new NpadKeyboardRight - { - StickUp = Key.I, - StickDown = Key.K, - StickLeft = Key.J, - StickRight = Key.L, - StickButton = Key.H, - ButtonA = Key.Z, - ButtonB = Key.X, - ButtonX = Key.C, - ButtonY = Key.V, - ButtonPlus = Key.Plus, - ButtonR = Key.U, - ButtonZr = Key.O, - ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound - }, - EnableMotion = false, - MirrorInput = false, - Slot = 0, - AltSlot = 0, - Sensitivity = 100, - GyroDeadzone = 1, - DsuServerHost = "127.0.0.1", - DsuServerPort = 26760 - } - }; - - configurationFileUpdated = true; - } - - // Only needed for version 6 configurations. - if (configurationFileFormat.Version == 6) - { - Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 7."); - - for (int i = 0; i < configurationFileFormat.KeyboardConfig.Count; i++) - { - if (configurationFileFormat.KeyboardConfig[i].Index != KeyboardConfig.AllKeyboardsIndex) - { - configurationFileFormat.KeyboardConfig[i].Index++; - } - } - } - if (configurationFileFormat.Version < 8) { Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 8."); @@ -826,9 +741,67 @@ namespace Ryujinx.Configuration configurationFileUpdated = true; } - List inputConfig = new List(); - inputConfig.AddRange(configurationFileFormat.ControllerConfig); - inputConfig.AddRange(configurationFileFormat.KeyboardConfig); + if (configurationFileFormat.Version < 24) + { + Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 24."); + + configurationFileFormat.InputConfig = new List + { + new StandardKeyboardInputConfig + { + Version = InputConfig.CurrentVersion, + Backend = InputBackendType.WindowKeyboard, + Id = "0", + PlayerIndex = PlayerIndex.Player1, + ControllerType = ControllerType.JoyconPair, + LeftJoycon = new LeftJoyconCommonConfig + { + DpadUp = Key.Up, + DpadDown = Key.Down, + DpadLeft = Key.Left, + DpadRight = Key.Right, + ButtonMinus = Key.Minus, + ButtonL = Key.E, + ButtonZl = Key.Q, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + LeftJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.W, + StickDown = Key.S, + StickLeft = Key.A, + StickRight = Key.D, + StickButton = Key.F, + }, + + RightJoycon = new RightJoyconCommonConfig + { + ButtonA = Key.Z, + ButtonB = Key.X, + ButtonX = Key.C, + ButtonY = Key.V, + ButtonPlus = Key.Plus, + ButtonR = Key.U, + ButtonZr = Key.O, + ButtonSl = Key.Unbound, + ButtonSr = Key.Unbound + }, + + RightJoyconStick = new JoyconConfigKeyboardStick + { + StickUp = Key.I, + StickDown = Key.K, + StickLeft = Key.J, + StickRight = Key.L, + StickButton = Key.H, + } + } + }; + + configurationFileUpdated = true; + } Graphics.ResScale.Value = configurationFileFormat.ResScale; Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom; @@ -880,7 +853,12 @@ namespace Ryujinx.Configuration Ui.StartFullscreen.Value = configurationFileFormat.StartFullscreen; Hid.EnableKeyboard.Value = configurationFileFormat.EnableKeyboard; Hid.Hotkeys.Value = configurationFileFormat.Hotkeys; - Hid.InputConfig.Value = inputConfig; + Hid.InputConfig.Value = configurationFileFormat.InputConfig; + + if (Hid.InputConfig.Value == null) + { + Hid.InputConfig.Value = new List(); + } if (configurationFileUpdated) { diff --git a/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs b/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs new file mode 100644 index 00000000..cae65fc9 --- /dev/null +++ b/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs @@ -0,0 +1,54 @@ +namespace Ryujinx.Common.Configuration.Hid.Controller +{ + public enum GamepadInputId : byte + { + Unbound, + A, + B, + X, + Y, + LeftStick, + RightStick, + LeftShoulder, + RightShoulder, + + // Likely axis + LeftTrigger, + // Likely axis + RightTrigger, + + DpadUp, + DpadDown, + DpadLeft, + DpadRight, + + // Special buttons + + Minus, + Plus, + + Back = Minus, + Start = Plus, + + Guide, + Misc1, + + // Xbox Elite paddle + Paddle1, + Paddle2, + Paddle3, + Paddle4, + + // PS5 touchpad button + Touchpad, + + // Virtual buttons for single joycon + SingleLeftTrigger0, + SingleRightTrigger0, + + SingleLeftTrigger1, + SingleRightTrigger1, + + Count + } +} diff --git a/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs b/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs new file mode 100644 index 00000000..e3423bb5 --- /dev/null +++ b/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs @@ -0,0 +1,37 @@ +using Ryujinx.Common.Configuration.Hid.Controller.Motion; + +namespace Ryujinx.Common.Configuration.Hid.Controller +{ + public class GenericControllerInputConfig : GenericInputConfigurationCommon False @@ -682,7 +667,7 @@ 80 True False - LStick Lt/Rt + LStick 0 @@ -691,20 +676,7 @@ - - 80 - True - False - LStick Up/Dn - 0 - - - 0 - 1 - - - - + 65 True @@ -716,22 +688,9 @@ 0 - - - - 65 - True - True - True - - - 1 - 1 - - - Invert + Invert Stick X True True False @@ -744,7 +703,7 @@ - Invert + Invert Stick Y True True False @@ -1501,7 +1460,7 @@ 80 True False - RStick Lt/Rt + RStick 0 @@ -1510,20 +1469,7 @@ - - 80 - True - False - RStick Up/Dn - 0 - - - 0 - 1 - - - - + 65 True @@ -1535,22 +1481,9 @@ 0 - - - - 65 - True - True - True - - - 1 - 1 - - - Invert + Invert Stick X True True False @@ -1563,7 +1496,7 @@ - Invert + Invert Stick Y True True False @@ -1640,7 +1573,7 @@ - + True False 10 @@ -1679,7 +1612,21 @@ - + + Use CemuHook compatible motion + True + True + False + True + + + False + True + 2 + + + + True False 10 @@ -1718,7 +1665,7 @@ False True 5 - 2 + 3 @@ -1761,11 +1708,11 @@ False True 5 - 3 + 4 - + True False vertical @@ -1829,11 +1776,11 @@ False True - 4 + 5 - + True False 30 @@ -1866,11 +1813,11 @@ False True 5 - 5 + 6 - + True False 30 @@ -1903,7 +1850,7 @@ False True 5 - 6 + 7 @@ -1916,7 +1863,7 @@ False True - 7 + 8 @@ -1930,7 +1877,7 @@ True True - 8 + 9 diff --git a/Ryujinx/Ui/Windows/SettingsWindow.cs b/Ryujinx/Ui/Windows/SettingsWindow.cs index 4cd5eb72..be9dc271 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.cs +++ b/Ryujinx/Ui/Windows/SettingsWindow.cs @@ -578,7 +578,7 @@ namespace Ryujinx.Ui.Windows { ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true); - ControllerWindow controllerWindow = new ControllerWindow(playerIndex); + ControllerWindow controllerWindow = new ControllerWindow(_parent, playerIndex); controllerWindow.SetSizeRequest((int)(controllerWindow.DefaultWidth * Program.WindowScaleFactor), (int)(controllerWindow.DefaultHeight * Program.WindowScaleFactor)); controllerWindow.Show();