From 693c3bb00d96489218d66505e0ebdb2d1b365f02 Mon Sep 17 00:00:00 2001 From: madwind Date: Fri, 31 Jan 2025 23:16:08 +0800 Subject: [PATCH] Revert "misc: chore: Pass rainbow color by reference in the event instead of passing around a packed int." This reverts commit 71d8cfd23230a70092d464f546829d3de347330e. --- src/Ryujinx.Common/Helpers/RefEvent.cs | 58 ------------------- src/Ryujinx.Common/Utilities/Rainbow.cs | 7 +-- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- .../Input/ControllerInputViewModel.cs | 6 +- .../UI/ViewModels/Input/InputViewModel.cs | 4 +- 5 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 src/Ryujinx.Common/Helpers/RefEvent.cs diff --git a/src/Ryujinx.Common/Helpers/RefEvent.cs b/src/Ryujinx.Common/Helpers/RefEvent.cs deleted file mode 100644 index f339dfb7c..000000000 --- a/src/Ryujinx.Common/Helpers/RefEvent.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Gommon; -using System.Collections.Generic; -using System.Threading; - -namespace Ryujinx.Common.Helper -{ - public class RefEvent - { - public delegate void Handler(ref T arg); - - private readonly Lock _subLock = new(); - private readonly List _subscriptions = []; - - public bool HasSubscribers - { - get - { - lock (_subLock) - return _subscriptions.Count != 0; - } - } - - public IReadOnlyList Subscriptions - { - get - { - lock (_subLock) - return _subscriptions; - } - } - - public void Add(Handler subscriber) - { - Guard.Require(subscriber, nameof(subscriber)); - lock (_subLock) - _subscriptions.Add(subscriber); - } - - public void Remove(Handler subscriber) - { - Guard.Require(subscriber, nameof(subscriber)); - lock (_subLock) - _subscriptions.Remove(subscriber); - } - - public void Clear() - { - lock (_subLock) - _subscriptions.Clear(); - } - - public void Call(ref T arg) - { - foreach (Handler subscription in Subscriptions) - subscription(ref arg); - } - } -} diff --git a/src/Ryujinx.Common/Utilities/Rainbow.cs b/src/Ryujinx.Common/Utilities/Rainbow.cs index eb1c187c4..a3db94925 100644 --- a/src/Ryujinx.Common/Utilities/Rainbow.cs +++ b/src/Ryujinx.Common/Utilities/Rainbow.cs @@ -1,5 +1,4 @@ using Gommon; -using Ryujinx.Common.Helper; using System; using System.Drawing; using System.Threading; @@ -56,7 +55,7 @@ namespace Ryujinx.Common.Utilities { _color = HsbToRgb((_color.GetHue() + Speed) / 360); - _updatedHandler.Call(ref _color); + _updatedHandler.Call(_color.ToArgb()); } } @@ -68,13 +67,13 @@ namespace Ryujinx.Common.Utilities _color = Color.Blue; } - public static event RefEvent.Handler Updated + public static event Action Updated { add => _updatedHandler.Add(value); remove => _updatedHandler.Remove(value); } - private static readonly RefEvent _updatedHandler = new(); + private static readonly Event _updatedHandler = new(); private static Color HsbToRgb(float hue, float saturation = 1, float brightness = 1) { diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 3b243eed0..4c93d9d7b 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -111,7 +111,7 @@ namespace Ryujinx.Input.SDL2 byte blue = packedRgb > 0 ? (byte)(packedRgb % 256) : (byte)0; if (SDL_GameControllerSetLED(_gamepadHandle, red, green, blue) != 0) - Logger.Error?.Print(LogClass.Hid, "LED setting failed; probably in the middle of disconnecting."); + Logger.Error?.Print(LogClass.Hid, "LED is not supported on this game controller."); } private GamepadFeaturesFlag GetFeaturesFlag() diff --git a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs index 2b644cffa..42daa2f49 100644 --- a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -1,10 +1,12 @@ using Avalonia.Svg.Skia; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using FluentAvalonia.UI.Controls; +using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Views.Input; using Ryujinx.Common.Utilities; using Ryujinx.UI.Views.Input; -using System.Drawing; namespace Ryujinx.Ava.UI.ViewModels.Input { @@ -52,7 +54,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input if (args.PropertyName is nameof(Config.UseRainbowLed)) { if (Config is { UseRainbowLed: true, TurnOffLed: false, EnableLedChanging: true }) - Rainbow.Updated += (ref Color color) => ParentModel.SelectedGamepad.SetLed((uint)color.ToArgb()); + Rainbow.Updated += color => ParentModel.SelectedGamepad.SetLed((uint)color); else { Rainbow.Reset(); diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 5b7bcfd32..6cc7744d8 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -20,10 +20,10 @@ using Ryujinx.Common.Configuration.Hid.Keyboard; using Ryujinx.Common.Logging; using Ryujinx.Common.Utilities; using Ryujinx.Input; +using Ryujinx.Input.SDL2; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Drawing; using System.IO; using System.Linq; using System.Text.Json; @@ -69,7 +69,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input _selectedGamepad = value; if (ConfigViewModel is ControllerInputViewModel { Config.UseRainbowLed: true }) - Rainbow.Updated += (ref Color color) => _selectedGamepad.SetLed((uint)color.ToArgb()); + Rainbow.Updated += color => _selectedGamepad.SetLed((uint)color); OnPropertiesChanged(nameof(HasLed), nameof(CanClearLed)); }