Chore: Minor code cleanups

This commit is contained in:
Evan Husted 2024-10-10 18:17:46 -05:00
parent 602251be51
commit 92b29ae4a5
7 changed files with 53 additions and 60 deletions

View file

@ -15,6 +15,7 @@
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" /> <PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageVersion Include="DynamicData" Version="9.0.4" /> <PackageVersion Include="DynamicData" Version="9.0.4" />
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" /> <PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="LibHac" Version="0.19.0" /> <PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" /> <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" /> <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
@ -46,4 +47,4 @@
<PackageVersion Include="System.Management" Version="8.0.0" /> <PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" /> <PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -629,8 +629,8 @@ namespace Ryujinx.HLE.FileSystem
} }
private static readonly ExtraDataFixInfo[] _systemExtraDataFixInfo = private static readonly ExtraDataFixInfo[] _systemExtraDataFixInfo =
{ [
new ExtraDataFixInfo() new()
{ {
StaticSaveDataId = 0x8000000000000030, StaticSaveDataId = 0x8000000000000030,
OwnerId = 0x010000000000001F, OwnerId = 0x010000000000001F,
@ -638,15 +638,15 @@ namespace Ryujinx.HLE.FileSystem
DataSize = 0x10000, DataSize = 0x10000,
JournalSize = 0x10000, JournalSize = 0x10000,
}, },
new ExtraDataFixInfo() new()
{ {
StaticSaveDataId = 0x8000000000001040, StaticSaveDataId = 0x8000000000001040,
OwnerId = 0x0100000000001009, OwnerId = 0x0100000000001009,
Flags = SaveDataFlags.None, Flags = SaveDataFlags.None,
DataSize = 0xC000, DataSize = 0xC000,
JournalSize = 0xC000, JournalSize = 0xC000,
}, }
}; ];
public void Dispose() public void Dispose()
{ {

View file

@ -320,23 +320,7 @@ namespace Ryujinx.Input.SDL2
return (0.0f, 0.0f); return (0.0f, 0.0f);
} }
short stickX; (short stickX, short stickY) = GetStickXY(inputId);
short stickY;
if (inputId == StickInputId.Left)
{
stickX = SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX);
stickY = SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY);
}
else if (inputId == StickInputId.Right)
{
stickX = SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX);
stickY = SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY);
}
else
{
throw new NotSupportedException($"Unsupported stick {inputId}");
}
float resultX = ConvertRawStickValue(stickX); float resultX = ConvertRawStickValue(stickX);
float resultY = -ConvertRawStickValue(stickY); float resultY = -ConvertRawStickValue(stickY);
@ -367,6 +351,18 @@ namespace Ryujinx.Input.SDL2
return (resultX, resultY); return (resultX, resultY);
} }
private (short, short) GetStickXY(StickInputId inputId) =>
inputId switch
{
StickInputId.Left => (
SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX),
SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY)),
StickInputId.Right => (
SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX),
SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY)),
_ => throw new NotSupportedException($"Unsupported stick {inputId}")
};
public bool IsPressed(GamepadButtonInputId inputId) public bool IsPressed(GamepadButtonInputId inputId)
{ {
if (inputId == GamepadButtonInputId.LeftTrigger) if (inputId == GamepadButtonInputId.LeftTrigger)

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Input.SDL2
{ {
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping; private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
private readonly List<string> _gamepadsIds; private readonly List<string> _gamepadsIds;
private readonly object _lock = new object(); private readonly object _lock = new();
public ReadOnlySpan<string> GamepadsIds public ReadOnlySpan<string> GamepadsIds
{ {
@ -82,17 +82,15 @@ namespace Ryujinx.Input.SDL2
private void HandleJoyStickDisconnected(int joystickInstanceId) private void HandleJoyStickDisconnected(int joystickInstanceId)
{ {
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id)) if (!_gamepadsInstanceIdsMapping.Remove(joystickInstanceId, out string id))
return;
lock (_lock)
{ {
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId); _gamepadsIds.Remove(id);
lock (_lock)
{
_gamepadsIds.Remove(id);
}
OnGamepadDisconnected?.Invoke(id);
} }
OnGamepadDisconnected?.Invoke(id);
} }
private void HandleJoyStickConnected(int joystickDeviceId, int joystickInstanceId) private void HandleJoyStickConnected(int joystickDeviceId, int joystickInstanceId)

View file

@ -80,7 +80,7 @@ namespace Ryujinx.UI.App.Common
private static byte[] GetResourceBytes(string resourceName) private static byte[] GetResourceBytes(string resourceName)
{ {
Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName); Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName)!;
byte[] resourceByteArray = new byte[resourceStream.Length]; byte[] resourceByteArray = new byte[resourceStream.Length];
resourceStream.ReadExactly(resourceByteArray); resourceStream.ReadExactly(resourceByteArray);
@ -1081,7 +1081,7 @@ namespace Ryujinx.UI.App.Common
using FileStream file = new(applicationPath, FileMode.Open, FileAccess.Read); using FileStream file = new(applicationPath, FileMode.Open, FileAccess.Read);
if (extension == ".nsp" || extension == ".pfs0" || extension == ".xci") if (extension is ".nsp" or ".pfs0" or ".xci")
{ {
try try
{ {

View file

@ -527,36 +527,36 @@ namespace Ryujinx.UI.Common.Configuration
public GraphicsSection() public GraphicsSection()
{ {
BackendThreading = new ReactiveObject<BackendThreading>(); BackendThreading = new ReactiveObject<BackendThreading>();
BackendThreading.Event += static (sender, e) => LogValueChange(e, nameof(BackendThreading)); BackendThreading.Event += static (_, e) => LogValueChange(e, nameof(BackendThreading));
ResScale = new ReactiveObject<int>(); ResScale = new ReactiveObject<int>();
ResScale.Event += static (sender, e) => LogValueChange(e, nameof(ResScale)); ResScale.Event += static (_, e) => LogValueChange(e, nameof(ResScale));
ResScaleCustom = new ReactiveObject<float>(); ResScaleCustom = new ReactiveObject<float>();
ResScaleCustom.Event += static (sender, e) => LogValueChange(e, nameof(ResScaleCustom)); ResScaleCustom.Event += static (_, e) => LogValueChange(e, nameof(ResScaleCustom));
MaxAnisotropy = new ReactiveObject<float>(); MaxAnisotropy = new ReactiveObject<float>();
MaxAnisotropy.Event += static (sender, e) => LogValueChange(e, nameof(MaxAnisotropy)); MaxAnisotropy.Event += static (_, e) => LogValueChange(e, nameof(MaxAnisotropy));
AspectRatio = new ReactiveObject<AspectRatio>(); AspectRatio = new ReactiveObject<AspectRatio>();
AspectRatio.Event += static (sender, e) => LogValueChange(e, nameof(AspectRatio)); AspectRatio.Event += static (_, e) => LogValueChange(e, nameof(AspectRatio));
ShadersDumpPath = new ReactiveObject<string>(); ShadersDumpPath = new ReactiveObject<string>();
EnableVsync = new ReactiveObject<bool>(); EnableVsync = new ReactiveObject<bool>();
EnableVsync.Event += static (sender, e) => LogValueChange(e, nameof(EnableVsync)); EnableVsync.Event += static (_, e) => LogValueChange(e, nameof(EnableVsync));
EnableShaderCache = new ReactiveObject<bool>(); EnableShaderCache = new ReactiveObject<bool>();
EnableShaderCache.Event += static (sender, e) => LogValueChange(e, nameof(EnableShaderCache)); EnableShaderCache.Event += static (_, e) => LogValueChange(e, nameof(EnableShaderCache));
EnableTextureRecompression = new ReactiveObject<bool>(); EnableTextureRecompression = new ReactiveObject<bool>();
EnableTextureRecompression.Event += static (sender, e) => LogValueChange(e, nameof(EnableTextureRecompression)); EnableTextureRecompression.Event += static (_, e) => LogValueChange(e, nameof(EnableTextureRecompression));
GraphicsBackend = new ReactiveObject<GraphicsBackend>(); GraphicsBackend = new ReactiveObject<GraphicsBackend>();
GraphicsBackend.Event += static (sender, e) => LogValueChange(e, nameof(GraphicsBackend)); GraphicsBackend.Event += static (_, e) => LogValueChange(e, nameof(GraphicsBackend));
PreferredGpu = new ReactiveObject<string>(); PreferredGpu = new ReactiveObject<string>();
PreferredGpu.Event += static (sender, e) => LogValueChange(e, nameof(PreferredGpu)); PreferredGpu.Event += static (_, e) => LogValueChange(e, nameof(PreferredGpu));
EnableMacroHLE = new ReactiveObject<bool>(); EnableMacroHLE = new ReactiveObject<bool>();
EnableMacroHLE.Event += static (sender, e) => LogValueChange(e, nameof(EnableMacroHLE)); EnableMacroHLE.Event += static (_, e) => LogValueChange(e, nameof(EnableMacroHLE));
EnableColorSpacePassthrough = new ReactiveObject<bool>(); EnableColorSpacePassthrough = new ReactiveObject<bool>();
EnableColorSpacePassthrough.Event += static (sender, e) => LogValueChange(e, nameof(EnableColorSpacePassthrough)); EnableColorSpacePassthrough.Event += static (_, e) => LogValueChange(e, nameof(EnableColorSpacePassthrough));
AntiAliasing = new ReactiveObject<AntiAliasing>(); AntiAliasing = new ReactiveObject<AntiAliasing>();
AntiAliasing.Event += static (sender, e) => LogValueChange(e, nameof(AntiAliasing)); AntiAliasing.Event += static (_, e) => LogValueChange(e, nameof(AntiAliasing));
ScalingFilter = new ReactiveObject<ScalingFilter>(); ScalingFilter = new ReactiveObject<ScalingFilter>();
ScalingFilter.Event += static (sender, e) => LogValueChange(e, nameof(ScalingFilter)); ScalingFilter.Event += static (_, e) => LogValueChange(e, nameof(ScalingFilter));
ScalingFilterLevel = new ReactiveObject<int>(); ScalingFilterLevel = new ReactiveObject<int>();
ScalingFilterLevel.Event += static (sender, e) => LogValueChange(e, nameof(ScalingFilterLevel)); ScalingFilterLevel.Event += static (_, e) => LogValueChange(e, nameof(ScalingFilterLevel));
} }
} }
@ -766,8 +766,8 @@ namespace Ryujinx.UI.Common.Configuration
EnableKeyboard = Hid.EnableKeyboard, EnableKeyboard = Hid.EnableKeyboard,
EnableMouse = Hid.EnableMouse, EnableMouse = Hid.EnableMouse,
Hotkeys = Hid.Hotkeys, Hotkeys = Hid.Hotkeys,
KeyboardConfig = new List<JsonObject>(), KeyboardConfig = [],
ControllerConfig = new List<JsonObject>(), ControllerConfig = [],
InputConfig = Hid.InputConfig, InputConfig = Hid.InputConfig,
GraphicsBackend = Graphics.GraphicsBackend, GraphicsBackend = Graphics.GraphicsBackend,
PreferredGpu = Graphics.PreferredGpu, PreferredGpu = Graphics.PreferredGpu,
@ -880,8 +880,8 @@ namespace Ryujinx.UI.Common.Configuration
VolumeUp = Key.Unbound, VolumeUp = Key.Unbound,
VolumeDown = Key.Unbound, VolumeDown = Key.Unbound,
}; };
Hid.InputConfig.Value = new List<InputConfig> Hid.InputConfig.Value =
{ [
new StandardKeyboardInputConfig new StandardKeyboardInputConfig
{ {
Version = InputConfig.CurrentVersion, Version = InputConfig.CurrentVersion,
@ -929,15 +929,16 @@ namespace Ryujinx.UI.Common.Configuration
StickRight = Key.L, StickRight = Key.L,
StickButton = Key.H, StickButton = Key.H,
}, },
}, }
};
];
} }
public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath) public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
{ {
bool configurationFileUpdated = false; bool configurationFileUpdated = false;
if (configurationFileFormat.Version < 0 || configurationFileFormat.Version > ConfigurationFileFormat.CurrentVersion) if (configurationFileFormat.Version is < 0 or > ConfigurationFileFormat.CurrentVersion)
{ {
Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default."); Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Unsupported configuration version {configurationFileFormat.Version}, loading default.");

View file

@ -115,9 +115,6 @@ namespace Ryujinx.Ava.UI.Windows
base.OnClosed(e); base.OnClosed(e);
if (PlatformSettings != null) if (PlatformSettings != null)
{ {
/// <summary>
/// Unsubscribe to the ColorValuesChanged event
/// </summary>
PlatformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged; PlatformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged;
} }
} }