Skip to content

Commit

Permalink
Chore: Minor code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 10, 2024
1 parent 602251b commit 92b29ae
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageVersion Include="DynamicData" Version="9.0.4" />
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
Expand Down Expand Up @@ -46,4 +47,4 @@
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup>
</Project>
</Project>
10 changes: 5 additions & 5 deletions src/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,24 +629,24 @@ struct ExtraDataFixInfo
}

private static readonly ExtraDataFixInfo[] _systemExtraDataFixInfo =
{
new ExtraDataFixInfo()
[
new()
{
StaticSaveDataId = 0x8000000000000030,
OwnerId = 0x010000000000001F,
Flags = SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData,
DataSize = 0x10000,
JournalSize = 0x10000,
},
new ExtraDataFixInfo()
new()
{
StaticSaveDataId = 0x8000000000001040,
OwnerId = 0x0100000000001009,
Flags = SaveDataFlags.None,
DataSize = 0xC000,
JournalSize = 0xC000,
},
};
}
];

public void Dispose()
{
Expand Down
30 changes: 13 additions & 17 deletions src/Ryujinx.Input.SDL2/SDL2Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,7 @@ private static float ConvertRawStickValue(short value)
return (0.0f, 0.0f);
}

short stickX;
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}");
}
(short stickX, short stickY) = GetStickXY(inputId);

float resultX = ConvertRawStickValue(stickX);
float resultY = -ConvertRawStickValue(stickY);
Expand Down Expand Up @@ -367,6 +351,18 @@ private static float ConvertRawStickValue(short value)
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)
{
if (inputId == GamepadButtonInputId.LeftTrigger)
Expand Down
18 changes: 8 additions & 10 deletions src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SDL2GamepadDriver : IGamepadDriver
{
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
private readonly List<string> _gamepadsIds;
private readonly object _lock = new object();
private readonly object _lock = new();

public ReadOnlySpan<string> GamepadsIds
{
Expand Down Expand Up @@ -82,17 +82,15 @@ private int GetJoystickIndexByGamepadId(string id)

private void HandleJoyStickDisconnected(int joystickInstanceId)
{
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id))
{
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId);

lock (_lock)
{
_gamepadsIds.Remove(id);
}
if (!_gamepadsInstanceIdsMapping.Remove(joystickInstanceId, out string id))
return;

OnGamepadDisconnected?.Invoke(id);
lock (_lock)
{
_gamepadsIds.Remove(id);
}

OnGamepadDisconnected?.Invoke(id);
}

private void HandleJoyStickConnected(int joystickDeviceId, int joystickInstanceId)
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.UI.Common/App/ApplicationLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ApplicationLibrary(VirtualFileSystem virtualFileSystem, IntegrityCheckLev

private static byte[] GetResourceBytes(string resourceName)
{
Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName);
Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName)!;
byte[] resourceByteArray = new byte[resourceStream.Length];

resourceStream.ReadExactly(resourceByteArray);
Expand Down Expand Up @@ -1081,7 +1081,7 @@ public byte[] GetApplicationIcon(string applicationPath, Language desiredTitleLa

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
{
Expand Down
45 changes: 23 additions & 22 deletions src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,36 +527,36 @@ public class GraphicsSection
public GraphicsSection()
{
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.Event += static (sender, e) => LogValueChange(e, nameof(ResScale));
ResScale.Event += static (_, e) => LogValueChange(e, nameof(ResScale));
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.Event += static (sender, e) => LogValueChange(e, nameof(MaxAnisotropy));
MaxAnisotropy.Event += static (_, e) => LogValueChange(e, nameof(MaxAnisotropy));
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>();
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.Event += static (sender, e) => LogValueChange(e, nameof(EnableShaderCache));
EnableShaderCache.Event += static (_, e) => LogValueChange(e, nameof(EnableShaderCache));
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.Event += static (sender, e) => LogValueChange(e, nameof(GraphicsBackend));
GraphicsBackend.Event += static (_, e) => LogValueChange(e, nameof(GraphicsBackend));
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.Event += static (sender, e) => LogValueChange(e, nameof(EnableMacroHLE));
EnableMacroHLE.Event += static (_, e) => LogValueChange(e, nameof(EnableMacroHLE));
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.Event += static (sender, e) => LogValueChange(e, nameof(AntiAliasing));
AntiAliasing.Event += static (_, e) => LogValueChange(e, nameof(AntiAliasing));
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.Event += static (sender, e) => LogValueChange(e, nameof(ScalingFilterLevel));
ScalingFilterLevel.Event += static (_, e) => LogValueChange(e, nameof(ScalingFilterLevel));
}
}

Expand Down Expand Up @@ -766,8 +766,8 @@ public ConfigurationFileFormat ToFileFormat()
EnableKeyboard = Hid.EnableKeyboard,
EnableMouse = Hid.EnableMouse,
Hotkeys = Hid.Hotkeys,
KeyboardConfig = new List<JsonObject>(),
ControllerConfig = new List<JsonObject>(),
KeyboardConfig = [],
ControllerConfig = [],
InputConfig = Hid.InputConfig,
GraphicsBackend = Graphics.GraphicsBackend,
PreferredGpu = Graphics.PreferredGpu,
Expand Down Expand Up @@ -880,8 +880,8 @@ public void LoadDefault()
VolumeUp = Key.Unbound,
VolumeDown = Key.Unbound,
};
Hid.InputConfig.Value = new List<InputConfig>
{
Hid.InputConfig.Value =
[
new StandardKeyboardInputConfig
{
Version = InputConfig.CurrentVersion,
Expand Down Expand Up @@ -929,15 +929,16 @@ public void LoadDefault()
StickRight = Key.L,
StickButton = Key.H,
},
},
};
}

];
}

public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
{
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.");

Expand Down
3 changes: 0 additions & 3 deletions src/Ryujinx/UI/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ protected override void OnClosed(EventArgs e)
base.OnClosed(e);
if (PlatformSettings != null)
{
/// <summary>
/// Unsubscribe to the ColorValuesChanged event
/// </summary>
PlatformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged;
}
}
Expand Down

0 comments on commit 92b29ae

Please sign in to comment.