From 7e511dacd3e3f1171787b9ce5c3fa13ed14fbf18 Mon Sep 17 00:00:00 2001 From: madwind Date: Fri, 7 Feb 2025 16:55:38 +0800 Subject: [PATCH] Follow DPA advice. --- .../SDL3HardwareDeviceSession.cs | 2 -- src/Ryujinx.Input/HLE/NpadManager.cs | 24 ++++++++++++------- src/Ryujinx.SDL3.Common/SDL3Driver.cs | 22 ++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs index 8fc305586..663968fff 100644 --- a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs @@ -22,7 +22,6 @@ namespace Ryujinx.Audio.Backends.SDL3 private readonly int _bytesPerFrame; private bool _started; private float _volume; - private readonly SDL_AudioFormat _nativeSampleFormat; public SDL3HardwareDeviceSession(SDL3HardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount) : base( @@ -34,7 +33,6 @@ namespace Ryujinx.Audio.Backends.SDL3 _ringBuffer = new DynamicRingBuffer(); _callbackDelegate = Update; _bytesPerFrame = BackendHelper.GetSampleSize(RequestedSampleFormat) * (int)RequestedChannelCount; - _nativeSampleFormat = SDL3HardwareDeviceDriver.GetSDL3Format(RequestedSampleFormat); _started = false; _volume = 1f; } diff --git a/src/Ryujinx.Input/HLE/NpadManager.cs b/src/Ryujinx.Input/HLE/NpadManager.cs index 4a54b7ead..c8902b9bc 100644 --- a/src/Ryujinx.Input/HLE/NpadManager.cs +++ b/src/Ryujinx.Input/HLE/NpadManager.cs @@ -37,6 +37,8 @@ namespace Ryujinx.Input.HLE private bool _enableKeyboard; private bool _enableMouse; private Switch _device; + private readonly List _hleInputStates; + private readonly List _hleMotionStates; public NpadManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver, IGamepadDriver mouseDriver) { @@ -48,6 +50,9 @@ namespace Ryujinx.Input.HLE _mouseDriver = mouseDriver; _inputConfig = []; + _hleInputStates = []; + _hleMotionStates = new List(NpadDevices.MaxControllers); + _gamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _gamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; } @@ -205,8 +210,8 @@ namespace Ryujinx.Input.HLE { lock (_lock) { - List hleInputStates = []; - List hleMotionStates = new(NpadDevices.MaxControllers); + _hleInputStates.Clear(); + _hleMotionStates.Clear(); KeyboardInput? hleKeyboardInput = null; @@ -248,14 +253,14 @@ namespace Ryujinx.Input.HLE inputState.PlayerId = playerIndex; motionState.Item1.PlayerId = playerIndex; - hleInputStates.Add(inputState); - hleMotionStates.Add(motionState.Item1); + _hleInputStates.Add(inputState); + _hleMotionStates.Add(motionState.Item1); if (isJoyconPair && !motionState.Item2.Equals(default)) { motionState.Item2.PlayerId = playerIndex; - hleMotionStates.Add(motionState.Item2); + _hleMotionStates.Add(motionState.Item2); } } @@ -264,8 +269,8 @@ namespace Ryujinx.Input.HLE hleKeyboardInput = NpadController.GetHLEKeyboardInput(_keyboardDriver); } - _device.Hid.Npads.Update(hleInputStates); - _device.Hid.Npads.UpdateSixAxis(hleMotionStates); + _device.Hid.Npads.Update(_hleInputStates); + _device.Hid.Npads.UpdateSixAxis(_hleMotionStates); if (hleKeyboardInput.HasValue) { @@ -307,14 +312,15 @@ namespace Ryujinx.Input.HLE Vector2 position = IMouse.GetScreenPosition(mouseInput.Position, mouse.ClientSize, aspectRatio); - _device.Hid.Mouse.Update((int)position.X, (int)position.Y, buttons, (int)mouseInput.Scroll.X, (int)mouseInput.Scroll.Y, true); + _device.Hid.Mouse.Update((int)position.X, (int)position.Y, buttons, (int)mouseInput.Scroll.X, + (int)mouseInput.Scroll.Y, true); } else { _device.Hid.Mouse.Update(0, 0); } - _device.TamperMachine.UpdateInput(hleInputStates); + _device.TamperMachine.UpdateInput(_hleInputStates); } } diff --git a/src/Ryujinx.SDL3.Common/SDL3Driver.cs b/src/Ryujinx.SDL3.Common/SDL3Driver.cs index 0f56e4cda..ac8a48d76 100644 --- a/src/Ryujinx.SDL3.Common/SDL3Driver.cs +++ b/src/Ryujinx.SDL3.Common/SDL3Driver.cs @@ -143,7 +143,8 @@ namespace Ryujinx.SDL3.Common { OnJoyBatteryUpdated?.Invoke(evnt.jbattery.which, evnt.jbattery); } - else if (evnt.type is >= (uint)SDL_EventType.SDL_EVENT_WINDOW_FIRST and <= (uint)SDL_EventType.SDL_EVENT_WINDOW_LAST + 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) { @@ -153,23 +154,22 @@ namespace Ryujinx.SDL3.Common } } } - + private void PollEventAction() + { + while (SDL_PollEvent(out SDL_Event evnt)) + { + HandleSDLEvent(ref evnt); + } + } private void EventWorker() { const int WaitTimeMs = 10; - using ManualResetEventSlim waitHandle = new(false); while (_isRunning) { - MainThreadDispatcher?.Invoke(() => - { - while (SDL_PollEvent(out SDL_Event evnt)) - { - HandleSDLEvent(ref evnt); - } - }); + MainThreadDispatcher?.Invoke(PollEventAction); - waitHandle.Wait(WaitTimeMs); + Thread.Sleep(WaitTimeMs); } }