diff --git a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs index eb018aec9..02ea0b25e 100644 --- a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs @@ -48,8 +48,7 @@ namespace Ryujinx.Audio.Backends.SDL3 private static bool IsSupportedInternal() { - nint device = OpenStream(SampleFormat.PcmInt16, Constants.TargetSampleRate, Constants.ChannelCountMax, - Constants.TargetSampleCount, null); + nint device = OpenStream(SampleFormat.PcmInt16, Constants.TargetSampleRate, Constants.ChannelCountMax, null); if (device != 0) { @@ -100,7 +99,7 @@ namespace Ryujinx.Audio.Backends.SDL3 } private static SDL_AudioSpec GetSDL3Spec(SampleFormat requestedSampleFormat, uint requestedSampleRate, - uint requestedChannelCount, uint sampleCount) + uint requestedChannelCount) { return new SDL_AudioSpec { @@ -123,10 +122,9 @@ namespace Ryujinx.Audio.Backends.SDL3 } internal static nint OpenStream(SampleFormat requestedSampleFormat, uint requestedSampleRate, - uint requestedChannelCount, uint sampleCount, SDL_AudioStreamCallback callback) + uint requestedChannelCount, SDL_AudioStreamCallback callback) { - SDL_AudioSpec desired = GetSDL3Spec(requestedSampleFormat, requestedSampleRate, requestedChannelCount, - sampleCount); + SDL_AudioSpec desired = GetSDL3Spec(requestedSampleFormat, requestedSampleRate, requestedChannelCount); nint stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, ref desired, callback, nint.Zero); @@ -139,16 +137,6 @@ namespace Ryujinx.Audio.Backends.SDL3 return 0; } - // bool isValid = got.format == desired.format && got.freq == desired.freq && got.channels == desired.channels; - // - // if (!isValid) - // { - // Logger.Error?.Print(LogClass.Application, "SDL3 open audio device is not valid"); - // SDL_DestroyAudioStream(stream); - // - // return 0; - // } - return stream; } diff --git a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs index f40d1452b..845908a7c 100644 --- a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs @@ -4,7 +4,6 @@ using Ryujinx.Common.Logging; using Ryujinx.Common.Memory; using Ryujinx.Memory; using System; -using System.Buffers; using System.Collections.Concurrent; using System.Threading; using static SDL3.SDL; @@ -22,7 +21,6 @@ namespace Ryujinx.Audio.Backends.SDL3 private bool _hasSetupError; private readonly SDL_AudioStreamCallback _callbackDelegate; private readonly int _bytesPerFrame; - private uint _sampleCount; private bool _started; private float _volume; private readonly SDL_AudioFormat _nativeSampleFormat; @@ -38,7 +36,6 @@ namespace Ryujinx.Audio.Backends.SDL3 _callbackDelegate = Update; _bytesPerFrame = BackendHelper.GetSampleSize(RequestedSampleFormat) * (int)RequestedChannelCount; _nativeSampleFormat = SDL3HardwareDeviceDriver.GetSDL3Format(RequestedSampleFormat); - _sampleCount = uint.MaxValue; _started = false; _volume = 1f; } @@ -47,15 +44,12 @@ namespace Ryujinx.Audio.Backends.SDL3 { uint bufferSampleCount = (uint)GetSampleCount(buffer); bool needAudioSetup = (_outputStream == 0 && !_hasSetupError) || - (bufferSampleCount >= Constants.TargetSampleCount && - bufferSampleCount < _sampleCount); + (bufferSampleCount >= Constants.TargetSampleCount); if (needAudioSetup) { - _sampleCount = Math.Max(Constants.TargetSampleCount, bufferSampleCount); - nint newOutputStream = SDL3HardwareDeviceDriver.OpenStream(RequestedSampleFormat, RequestedSampleRate, - RequestedChannelCount, _sampleCount, _callbackDelegate); + RequestedChannelCount, _callbackDelegate); _hasSetupError = newOutputStream == 0; @@ -68,18 +62,21 @@ namespace Ryujinx.Audio.Backends.SDL3 _outputStream = newOutputStream; - // SDL_PauseAudioDevice(_outputStream, _started ? 0 : 1); - SDL_ResumeAudioStreamDevice(_outputStream); - - Logger.Info?.Print(LogClass.Audio, - $"New audio stream setup with a target sample count of {_sampleCount}"); + if (_started) + { + SDL_ResumeAudioStreamDevice(_outputStream); + } + else + { + SDL_PauseAudioStreamDevice(_outputStream); + } } } } - private unsafe void Update(nint userdata, nint stream, int additional_amount, int total_amount) + private unsafe void Update(nint userdata, nint stream, int additionalAmount, int totalAmount) { - int maxFrameCount = (int)GetSampleCount(additional_amount); + int maxFrameCount = (int)GetSampleCount(additionalAmount); int bufferedFrames = _ringBuffer.Length / _bytesPerFrame; int frameCount = Math.Min(bufferedFrames, maxFrameCount); @@ -90,24 +87,22 @@ namespace Ryujinx.Audio.Backends.SDL3 } using SpanOwner samplesOwner = SpanOwner.Rent(frameCount * _bytesPerFrame); - using SpanOwner destinationOwner = SpanOwner.Rent(frameCount * _bytesPerFrame); Span samples = samplesOwner.Span; - Span destinationBuffer = destinationOwner.Span; + int samplesLength = samples.Length; + _ringBuffer.Read(samples, 0, samplesLength); - _ringBuffer.Read(samples, 0, samples.Length); - - fixed (byte* pSrc = samples, pDst = destinationBuffer) + fixed (byte* p = samples) { - nint pStreamSrc = (nint)pSrc; - nint pStreamDst = (nint)pDst; - + nint pStreamSrc = (nint)p; + nint pStreamDst = SDL_calloc(1,samplesLength); // Apply volume to written data - SDL_MixAudio(pStreamDst, pStreamSrc, _nativeSampleFormat, (uint)samples.Length, _driver.Volume); - SDL_PutAudioStreamData(stream, pStreamSrc, samples.Length); + SDL_MixAudio(pStreamDst, pStreamSrc, _nativeSampleFormat, (uint)samplesLength, _driver.Volume); + SDL_PutAudioStreamData(stream, pStreamDst, samplesLength); + SDL_free(pStreamDst); } - ulong sampleCount = GetSampleCount(samples.Length); + ulong sampleCount = GetSampleCount(samplesLength); ulong availaibleSampleCount = sampleCount; diff --git a/src/Ryujinx.Input.SDL3/SDL3Gamepad.cs b/src/Ryujinx.Input.SDL3/SDL3Gamepad.cs index b1162cdb8..2d805e3a5 100644 --- a/src/Ryujinx.Input.SDL3/SDL3Gamepad.cs +++ b/src/Ryujinx.Input.SDL3/SDL3Gamepad.cs @@ -60,7 +60,7 @@ namespace Ryujinx.Input.SDL3 private float _triggerThreshold; - public SDL3Gamepad(SDL_JoystickID joystickId, string driverId) + public SDL3Gamepad(uint joystickId, string driverId) { _gamepadHandle = SDL_OpenGamepad(joystickId); _buttonsUserMapping = new List(20); diff --git a/src/Ryujinx.Input.SDL3/SDL3GamepadDriver.cs b/src/Ryujinx.Input.SDL3/SDL3GamepadDriver.cs index 3f18aad57..b0167896d 100644 --- a/src/Ryujinx.Input.SDL3/SDL3GamepadDriver.cs +++ b/src/Ryujinx.Input.SDL3/SDL3GamepadDriver.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Input.SDl3 { public class SDL3GamepadDriver : IGamepadDriver { - private readonly Dictionary _gamepadsInstanceIdsMapping; + private readonly Dictionary _gamepadsInstanceIdsMapping; private readonly List _gamepadsIds; private readonly Lock _lock = new(); @@ -34,7 +34,7 @@ namespace Ryujinx.Input.SDl3 public SDL3GamepadDriver() { - _gamepadsInstanceIdsMapping = new Dictionary(); + _gamepadsInstanceIdsMapping = new Dictionary(); _gamepadsIds = new List(); SDL3Driver.Instance.Initialize(); @@ -43,7 +43,7 @@ namespace Ryujinx.Input.SDl3 SDL3Driver.Instance.OnJoyBatteryUpdated += HandleJoyBatteryUpdated; } - private string GenerateGamepadId(SDL_JoystickID joystickId) + private string GenerateGamepadId(uint joystickId) { int bufferSize = 33; Span pszGuid = stackalloc byte[bufferSize]; @@ -65,7 +65,7 @@ namespace Ryujinx.Input.SDl3 return id; } - private KeyValuePair GetGamepadInfoByGamepadId(string id) + private KeyValuePair GetGamepadInfoByGamepadId(string id) { lock (_lock) { @@ -73,7 +73,7 @@ namespace Ryujinx.Input.SDl3 } } - private void HandleJoyStickDisconnected(SDL_JoystickID joystickId) + private void HandleJoyStickDisconnected(uint joystickId) { bool joyConPairDisconnected = false; if (!_gamepadsInstanceIdsMapping.Remove(joystickId, out string id)) @@ -96,7 +96,7 @@ namespace Ryujinx.Input.SDl3 } } - private void HandleJoyStickConnected(SDL_JoystickID joystickId) + private void HandleJoyStickConnected(uint joystickId) { bool joyConPairConnected = false; @@ -135,7 +135,7 @@ namespace Ryujinx.Input.SDl3 } } - private void HandleJoyBatteryUpdated(SDL_JoystickID joystickId, SDL_JoyBatteryEvent joyBatteryEvent) + private void HandleJoyBatteryUpdated(uint joystickId, SDL_JoyBatteryEvent joyBatteryEvent) { Logger.Info?.Print(LogClass.Hid, $"{SDL_GetGamepadNameForID(joystickId)}, Battery percent: {joyBatteryEvent.percent}"); diff --git a/src/Ryujinx.Input.SDL3/SDL3JoyCon.cs b/src/Ryujinx.Input.SDL3/SDL3JoyCon.cs index f6067faff..cad3c3457 100644 --- a/src/Ryujinx.Input.SDL3/SDL3JoyCon.cs +++ b/src/Ryujinx.Input.SDL3/SDL3JoyCon.cs @@ -63,17 +63,9 @@ namespace Ryujinx.Input.SDL3 private nint _gamepadHandle; - private enum JoyConType - { - Left, Right - } + private readonly SDL_GamepadType _gamepadType; - public const string LeftName = "Nintendo Switch Joy-Con (L)"; - public const string RightName = "Nintendo Switch Joy-Con (R)"; - - private readonly JoyConType _joyConType; - - public SDL3JoyCon(SDL_JoystickID joystickId, string driverId) + public SDL3JoyCon(uint joystickId, string driverId) { _gamepadHandle = SDL_OpenGamepad(joystickId); _buttonsUserMapping = new List(10); @@ -98,24 +90,15 @@ namespace Ryujinx.Input.SDL3 } } - switch (Name) + _gamepadType = SDL_GetGamepadType(_gamepadHandle); + _buttonsDriverMapping = _gamepadType switch { - case LeftName: - { - _buttonsDriverMapping = ToSDLButtonMapping(_leftButtonsDriverMapping); - _joyConType = JoyConType.Left; - break; - } - case RightName: - { - _buttonsDriverMapping = ToSDLButtonMapping(_rightButtonsDriverMapping); - _joyConType = JoyConType.Right; - break; - } - default: - throw new InvalidOperationException( - $"Unexpected Name: {Name}. Expected '{LeftName}' or '{RightName}'."); - } + SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT => ToSDLButtonMapping( + _leftButtonsDriverMapping), + SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT => ToSDLButtonMapping( + _rightButtonsDriverMapping), + _ => throw new InvalidOperationException($"Unexpected JoyConType value: {_gamepadType}") + }; } private static SDL_GamepadButton[] ToSDLButtonMapping( @@ -205,11 +188,11 @@ namespace Ryujinx.Input.SDL3 return Vector3.Zero; } - Vector3 value = _joyConType switch + Vector3 value = _gamepadType switch { - JoyConType.Left => new Vector3(-values[2], values[1], values[0]), - JoyConType.Right => new Vector3(values[2], values[1], -values[0]), - _ => throw new ArgumentOutOfRangeException($"Unexpected JoyConType value: {_joyConType}") + SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT => new Vector3(-values[2], values[1], values[0]), + SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT => new Vector3(values[2], values[1], -values[0]), + _ => throw new ArgumentOutOfRangeException($"Unexpected JoyConType value: {_gamepadType}") }; return inputId switch @@ -237,9 +220,9 @@ namespace Ryujinx.Input.SDL3 _stickUserMapping[(int)StickInputId.Right] = (StickInputId)_configuration.RightJoyconStick.Joystick; - switch (_joyConType) + switch (_gamepadType) { - case JoyConType.Left: + case SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT: _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, (GamepadButtonInputId)_configuration.LeftJoyconStick.StickButton)); _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, @@ -261,7 +244,7 @@ namespace Ryujinx.Input.SDL3 _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, (GamepadButtonInputId)_configuration.LeftJoycon.ButtonSl)); break; - case JoyConType.Right: + case SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT: _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, (GamepadButtonInputId)_configuration.RightJoyconStick.StickButton)); _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, @@ -316,7 +299,6 @@ namespace Ryujinx.Input.SDL3 // Do not touch state of button already pressed if (!result.IsPressed(entry.To)) { - result.SetPressed(entry.To, rawState.IsPressed(entry.From)); } } @@ -367,8 +349,8 @@ namespace Ryujinx.Input.SDL3 if (inputId == StickInputId.Unbound) return (0.0f, 0.0f); - if (inputId == StickInputId.Left && _joyConType == JoyConType.Right || - inputId == StickInputId.Right && _joyConType == JoyConType.Left) + if (inputId == StickInputId.Left && _gamepadType == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT || + inputId == StickInputId.Right && _gamepadType == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT) { return (0.0f, 0.0f); } @@ -401,8 +383,8 @@ namespace Ryujinx.Input.SDL3 return inputId switch { - StickInputId.Left when _joyConType == JoyConType.Left => (resultY, -resultX), - StickInputId.Right when _joyConType == JoyConType.Right => (-resultY, resultX), + StickInputId.Left when _gamepadType == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT => (resultY, -resultX), + StickInputId.Right when _gamepadType == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT => (-resultY, resultX), _ => (0.0f, 0.0f) }; } @@ -421,18 +403,14 @@ namespace Ryujinx.Input.SDL3 { return false; } - - // if (SDL_GetGamepadButton(_gamepadHandle, button)) - // { - // Console.WriteLine(inputId+", "+button); - // } return SDL_GetGamepadButton(_gamepadHandle, button); } - public static bool IsJoyCon(SDL_JoystickID joystickId) + public static bool IsJoyCon(uint joystickId) { - var gamepadName = SDL_GetGamepadNameForID(joystickId); - return gamepadName is LeftName or RightName; + var gamepadName = SDL_GetGamepadTypeForID(joystickId); + return gamepadName is SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT + or SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT; } } } diff --git a/src/Ryujinx.Input.SDL3/SDL3JoyConPair.cs b/src/Ryujinx.Input.SDL3/SDL3JoyConPair.cs index a99536e5a..ce8fc603f 100644 --- a/src/Ryujinx.Input.SDL3/SDL3JoyConPair.cs +++ b/src/Ryujinx.Input.SDL3/SDL3JoyConPair.cs @@ -11,21 +11,24 @@ namespace Ryujinx.Input.SDL3 class SDL3JoyConPair(SDL3JoyCon left, SDL3JoyCon right) : IGamepad { private StandardControllerInputConfig _configuration; + private readonly record struct ButtonMappingEntry(GamepadButtonInputId To, GamepadButtonInputId From) { public bool IsValid => To is not GamepadButtonInputId.Unbound && From is not GamepadButtonInputId.Unbound; } + private readonly StickInputId[] _stickUserMapping = new StickInputId[(int)StickInputId.Count] { StickInputId.Unbound, StickInputId.Left, StickInputId.Right, }; + public GamepadFeaturesFlag Features => (left?.Features ?? GamepadFeaturesFlag.None) | (right?.Features ?? GamepadFeaturesFlag.None); public const string Id = "JoyConPair"; private readonly Lock _userMappingLock = new(); - private readonly List _buttonsUserMapping = new List(20); + private readonly List _buttonsUserMapping = new List(20); string IGamepad.Id => Id; public string Name => "* Nintendo Switch Joy-Con (L/R)"; @@ -185,20 +188,21 @@ namespace Ryujinx.Input.SDL3 { } - public static bool IsCombinable(Dictionary gamepadsInstanceIdsMapping) + public static bool IsCombinable(Dictionary gamepadsInstanceIdsMapping) { - var gamepadNames = gamepadsInstanceIdsMapping.Keys.Select(id => SDL_GetGamepadNameForID(id)).ToArray(); - return gamepadNames.Contains(SDL3JoyCon.LeftName) && gamepadNames.Contains(SDL3JoyCon.RightName); + var gamepadTypes = gamepadsInstanceIdsMapping.Keys.Select(SDL_GetGamepadTypeForID).ToArray(); + return gamepadTypes.Contains(SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT) && + gamepadTypes.Contains(SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT); } - public static IGamepad GetGamepad(Dictionary gamepadsInstanceIdsMapping) + public static IGamepad GetGamepad(Dictionary gamepadsInstanceIdsMapping) { var leftPair = gamepadsInstanceIdsMapping.FirstOrDefault(pair => - SDL_GetGamepadNameForID(pair.Key) == SDL3JoyCon.LeftName); + SDL_GetGamepadTypeForID(pair.Key) == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT); var rightPair = gamepadsInstanceIdsMapping.FirstOrDefault(pair => - SDL_GetGamepadNameForID(pair.Key) == SDL3JoyCon.RightName); + SDL_GetGamepadTypeForID(pair.Key) == SDL_GamepadType.SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT); if (leftPair.Key == 0 || rightPair.Key == 0) { return null; diff --git a/src/Ryujinx.SDL3-CS/SDL3.cs b/src/Ryujinx.SDL3-CS/SDL3.cs index 8afa0a94c..d5699c2a9 100644 --- a/src/Ryujinx.SDL3-CS/SDL3.cs +++ b/src/Ryujinx.SDL3-CS/SDL3.cs @@ -82,6 +82,10 @@ public static unsafe partial class SDL [LibraryImport(nativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial IntPtr SDL_malloc(UIntPtr size); + + [LibraryImport(nativeLibName)] + [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] + public static partial IntPtr SDL_calloc(int nmemb, int size); [LibraryImport(nativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] @@ -752,6 +756,7 @@ public static unsafe partial class SDL public static partial SDLBool SDL_WriteS64BE(IntPtr dst, long value); // /usr/local/include/SDL3/SDL_audio.h + public const uint SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK = 0xFFFFFFFFu; public enum SDL_AudioFormat { @@ -2615,6 +2620,7 @@ public static unsafe partial class SDL public static partial SDL_PowerState SDL_GetPowerInfo(out int seconds, out int percent); // /usr/local/include/SDL3/SDL_sensor.h + public const float SDL_STANDARD_GRAVITY = 9.80665f; public enum SDL_SensorType { @@ -2693,7 +2699,7 @@ public static unsafe partial class SDL public const string SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN = "SDL.joystick.cap.player_led"; public const string SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN = "SDL.joystick.cap.rumble"; public const string SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN = "SDL.joystick.cap.trigger_rumble"; - + public enum SDL_JoystickType { SDL_JOYSTICK_TYPE_UNKNOWN = 0, @@ -2749,7 +2755,7 @@ public static unsafe partial class SDL [LibraryImport(nativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] - public static partial SDL_GUID SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id); + public static partial SDL_GUID SDL_GetJoystickGUIDForID(uint instance_id); [LibraryImport(nativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] @@ -4620,7 +4626,7 @@ public static unsafe partial class SDL public SDL_EventType type; public uint reserved; public ulong timestamp; - public SDL_JoystickID which; + public uint which; } [StructLayout(LayoutKind.Sequential)] @@ -4629,7 +4635,7 @@ public static unsafe partial class SDL public SDL_EventType type; public uint reserved; public ulong timestamp; - public SDL_JoystickID which; + public uint which; public SDL_PowerState state; public int percent; } @@ -8048,19 +8054,4 @@ public static unsafe partial class SDL [LibraryImport(nativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial int SDL_EnterAppMainCallbacks(int argc, IntPtr argv, SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit); - - public const uint SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK = 0xFFFFFFFFu; - public const float SDL_STANDARD_GRAVITY = 9.80665f; - public record struct SDL_JoystickID - { - public uint Value; - - public SDL_JoystickID(uint value) - { - Value = value; - } - - public static implicit operator uint(SDL_JoystickID id) => id.Value; - public static implicit operator SDL_JoystickID(uint value) => new SDL_JoystickID(value); - } } diff --git a/src/Ryujinx.SDL3.Common/SDL3Driver.cs b/src/Ryujinx.SDL3.Common/SDL3Driver.cs index 52d7240bb..0f56e4cda 100644 --- a/src/Ryujinx.SDL3.Common/SDL3Driver.cs +++ b/src/Ryujinx.SDL3.Common/SDL3Driver.cs @@ -33,9 +33,9 @@ namespace Ryujinx.SDL3.Common private uint _refereceCount; private Thread _worker; - public event Action OnJoyStickConnected; - public event Action OnJoystickDisconnected; - public event Action OnJoyBatteryUpdated; + public event Action OnJoyStickConnected; + public event Action OnJoystickDisconnected; + public event Action OnJoyBatteryUpdated; private ConcurrentDictionary> _registeredWindowHandlers; @@ -123,8 +123,7 @@ namespace Ryujinx.SDL3.Common private void HandleSDLEvent(ref SDL_Event evnt) { - var type = (SDL_EventType)evnt.type; - if (type == SDL_EventType.SDL_EVENT_GAMEPAD_ADDED) + if (evnt.type == (uint)SDL_EventType.SDL_EVENT_GAMEPAD_ADDED) { var instanceId = evnt.jdevice.which; @@ -132,7 +131,7 @@ namespace Ryujinx.SDL3.Common OnJoyStickConnected?.Invoke(instanceId); } - else if (type == SDL_EventType.SDL_EVENT_GAMEPAD_REMOVED) + else if (evnt.type == (uint)SDL_EventType.SDL_EVENT_GAMEPAD_REMOVED) { var instanceId = evnt.jdevice.which; @@ -140,13 +139,13 @@ namespace Ryujinx.SDL3.Common OnJoystickDisconnected?.Invoke(instanceId); } - else if (type == SDL_EventType.SDL_EVENT_JOYSTICK_BATTERY_UPDATED) + else if (evnt.type == (uint)SDL_EventType.SDL_EVENT_JOYSTICK_BATTERY_UPDATED) { OnJoyBatteryUpdated?.Invoke(evnt.jbattery.which, evnt.jbattery); } - else if (type is >= SDL_EventType.SDL_EVENT_WINDOW_FIRST and <= SDL_EventType.SDL_EVENT_WINDOW_LAST - or SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN - or SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP) + else if (evnt.type is >= (uint)SDL_EventType.SDL_EVENT_WINDOW_FIRST and <= (uint)SDL_EventType.SDL_EVENT_WINDOW_LAST + or (uint)SDL_EventType.SDL_EVENT_MOUSE_BUTTON_DOWN + or (uint)SDL_EventType.SDL_EVENT_MOUSE_BUTTON_UP) { if (_registeredWindowHandlers.TryGetValue(evnt.window.windowID, out Action handler)) {