input: LED rainbow now updates the LED with the normal gamepad update loop instead of subscribing to an updated event for the rainbow color in SetConfiguration.
Some checks are pending
Canary release job / Create tag (push) Waiting to run
Canary release job / Release for linux-arm64 (push) Waiting to run
Canary release job / Release for linux-x64 (push) Waiting to run
Canary release job / Release for win-x64 (push) Waiting to run
Canary release job / Release MacOS universal (push) Waiting to run

This commit is contained in:
Evan Husted 2025-01-25 23:13:51 -06:00
parent 8bfcebebf1
commit 3f12727ef8
2 changed files with 31 additions and 32 deletions

View file

@ -1,6 +1,7 @@
using Gommon; using Gommon;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Ryujinx.Common.Utilities namespace Ryujinx.Common.Utilities
@ -18,7 +19,7 @@ namespace Ryujinx.Common.Utilities
{ {
while (CyclingEnabled) while (CyclingEnabled)
{ {
await Task.Delay(15); await Task.Delay(20);
Tick(); Tick();
} }
}); });
@ -33,28 +34,46 @@ namespace Ryujinx.Common.Utilities
public static float Speed { get; set; } = 1; public static float Speed { get; set; } = 1;
public static Color Color { get; private set; } = Color.Blue; private static readonly Lock _lock = new();
private static Color _color = Color.Blue;
public static ref Color Color
{
get
{
lock (_lock)
{
return ref _color;
}
}
}
public static void Tick() public static void Tick()
{ {
Color = HsbToRgb((Color.GetHue() + Speed) / 360); lock (_lock)
{
_color = HsbToRgb((_color.GetHue() + Speed) / 360);
UpdatedHandler.Call(Color.ToArgb()); _updatedHandler.Call(_color.ToArgb());
}
} }
public static void Reset() public static void Reset()
{ {
Color = Color.Blue; _updatedHandler.Clear();
UpdatedHandler.Clear();
lock (_lock)
_color = Color.Blue;
} }
public static event Action<int> Updated public static event Action<int> Updated
{ {
add => UpdatedHandler.Add(value); add => _updatedHandler.Add(value);
remove => UpdatedHandler.Remove(value); remove => _updatedHandler.Remove(value);
} }
internal static Event<int> UpdatedHandler = new(); private static readonly Event<int> _updatedHandler = new();
private static Color HsbToRgb(float hue, float saturation = 1, float brightness = 1) private static Color HsbToRgb(float hue, float saturation = 1, float brightness = 1)
{ {

View file

@ -148,8 +148,6 @@ namespace Ryujinx.Input.SDL2
{ {
if (disposing && _gamepadHandle != nint.Zero) if (disposing && _gamepadHandle != nint.Zero)
{ {
Rainbow.Updated -= RainbowColorChanged;
SDL_GameControllerClose(_gamepadHandle); SDL_GameControllerClose(_gamepadHandle);
_gamepadHandle = nint.Zero; _gamepadHandle = nint.Zero;
@ -228,15 +226,6 @@ namespace Ryujinx.Input.SDL2
private static Vector3 GsToMs2(Vector3 gs) => gs / SDL_STANDARD_GRAVITY; private static Vector3 GsToMs2(Vector3 gs) => gs / SDL_STANDARD_GRAVITY;
private void RainbowColorChanged(int packedRgb)
{
if (!_configuration.Led.UseRainbow) return;
SetLed((uint)packedRgb);
}
private bool _rainbowColorEnabled;
public void SetConfiguration(InputConfig configuration) public void SetConfiguration(InputConfig configuration)
{ {
lock (_userMappingLock) lock (_userMappingLock)
@ -247,19 +236,10 @@ namespace Ryujinx.Input.SDL2
{ {
if (_configuration.Led.TurnOffLed) if (_configuration.Led.TurnOffLed)
(this as IGamepad).ClearLed(); (this as IGamepad).ClearLed();
else switch (_configuration.Led.UseRainbow) else if (_configuration.Led.UseRainbow)
{ SetLed((uint)Rainbow.Color.ToArgb());
case true when !_rainbowColorEnabled:
Rainbow.Updated += RainbowColorChanged;
_rainbowColorEnabled = true;
break;
case false when _rainbowColorEnabled:
Rainbow.Updated -= RainbowColorChanged;
_rainbowColorEnabled = false;
break;
}
if (!_configuration.Led.TurnOffLed && !_rainbowColorEnabled) if (!_configuration.Led.TurnOffLed && !_configuration.Led.UseRainbow)
SetLed(_configuration.Led.LedColor); SetLed(_configuration.Led.LedColor);
} }