Compare commits

..

4 Commits

Author SHA1 Message Date
TSRBerry
2de78a2d55 [Ryujinx.Input.SDL2] Address dotnet-format issues (#5385)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0052 warnings

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address most dotnet format whitespace warnings

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* Add trailing commas, log errors instead of throwing and remove redundant code
2023-06-26 01:55:25 +00:00
TSRBerry
b29ded1d60 [Ryujinx.SDL2.Common] Address dotnet-format issues (#5387)
* dotnet format style --severity info

Some changes were manually reverted.

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address most dotnet format whitespace warnings

* dotnet format whitespace after rebase
2023-06-26 01:51:16 +00:00
Mary
9860bfb2cd misc: memory: Migrate from OutOfMemoryException to SystemException entirely (#5399)
Fix a regression with address space allocation while providing more
information about the context of the exception.
2023-06-26 01:37:12 +00:00
TSRBerry
f6ada8d169 [Ryujinx.Graphics.Device] Address dotnet-format issues (#5363)
* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Address most dotnet format whitespace warnings

* dotnet format whitespace after rebase
2023-06-25 23:58:44 +02:00
10 changed files with 78 additions and 65 deletions

View File

@@ -199,7 +199,7 @@ namespace Ryujinx.Cpu
break;
}
catch (OutOfMemoryException)
catch (SystemException)
{
baseMemory?.Dispose();
mirrorMemory?.Dispose();

View File

@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Device
public TState State;
private uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
private static uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
private readonly Func<int>[] _readCallbacks;
private readonly Action<int>[] _writeCallbacks;

View File

@@ -57,13 +57,13 @@ namespace Ryujinx.Input.SDL2
private readonly object _userMappingLock = new();
private List<ButtonMappingEntry> _buttonsUserMapping;
private readonly List<ButtonMappingEntry> _buttonsUserMapping;
private StickInputId[] _stickUserMapping = new StickInputId[(int)StickInputId.Count]
private readonly StickInputId[] _stickUserMapping = new StickInputId[(int)StickInputId.Count]
{
StickInputId.Unbound,
StickInputId.Left,
StickInputId.Right
StickInputId.Right,
};
public GamepadFeaturesFlag Features { get; }
@@ -85,8 +85,15 @@ namespace Ryujinx.Input.SDL2
// Enable motion tracking
if (Features.HasFlag(GamepadFeaturesFlag.Motion))
{
SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL, SDL_bool.SDL_TRUE);
SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_GYRO, SDL_bool.SDL_TRUE);
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL, SDL_bool.SDL_TRUE) != 0)
{
Logger.Error?.Print(LogClass.Hid, $"Could not enable data reporting for SensorType {SDL_SensorType.SDL_SENSOR_ACCEL}.");
}
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_GYRO, SDL_bool.SDL_TRUE) != 0)
{
Logger.Error?.Print(LogClass.Hid, $"Could not enable data reporting for SensorType {SDL_SensorType.SDL_SENSOR_GYRO}.");
}
}
}
@@ -144,7 +151,10 @@ namespace Ryujinx.Input.SDL2
if (durationMs == uint.MaxValue)
{
SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, SDL_HAPTIC_INFINITY);
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, SDL_HAPTIC_INFINITY) != 0)
{
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
}
}
else if (durationMs > SDL_HAPTIC_INFINITY)
{
@@ -152,7 +162,10 @@ namespace Ryujinx.Input.SDL2
}
else
{
SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, durationMs);
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, durationMs) != 0)
{
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
}
}
}
}
@@ -182,13 +195,14 @@ namespace Ryujinx.Input.SDL2
if (result == 0)
{
Vector3 value = new Vector3(values[0], values[1], values[2]);
Vector3 value = new(values[0], values[1], values[2]);
if (inputId == MotionInputId.Gyroscope)
{
return RadToDegree(value);
}
else if (inputId == MotionInputId.Accelerometer)
if (inputId == MotionInputId.Accelerometer)
{
return GsToMs2(value);
}
@@ -359,18 +373,18 @@ namespace Ryujinx.Input.SDL2
{
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)) > _triggerThreshold;
}
else if (inputId == GamepadButtonInputId.RightTrigger)
if (inputId == GamepadButtonInputId.RightTrigger)
{
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) > _triggerThreshold;
}
else if (_buttonsDriverMapping[(int)inputId] == SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID)
if (_buttonsDriverMapping[(int)inputId] == SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_INVALID)
{
return false;
}
else
{
return SDL_GameControllerGetButton(_gamepadHandle, _buttonsDriverMapping[(int)inputId]) == 1;
}
return SDL_GameControllerGetButton(_gamepadHandle, _buttonsDriverMapping[(int)inputId]) == 1;
}
}
}

View File

@@ -7,8 +7,8 @@ namespace Ryujinx.Input.SDL2
{
public class SDL2GamepadDriver : IGamepadDriver
{
private Dictionary<int, string> _gamepadsInstanceIdsMapping;
private List<string> _gamepadsIds;
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
private readonly List<string> _gamepadsIds;
public ReadOnlySpan<string> GamepadsIds => _gamepadsIds.ToArray();
@@ -35,7 +35,7 @@ namespace Ryujinx.Input.SDL2
}
}
private string GenerateGamepadId(int joystickIndex)
private static string GenerateGamepadId(int joystickIndex)
{
Guid guid = SDL_JoystickGetDeviceGUID(joystickIndex);
@@ -44,10 +44,10 @@ namespace Ryujinx.Input.SDL2
return null;
}
return joystickIndex + "-" + guid.ToString();
return joystickIndex + "-" + guid;
}
private int GetJoystickIndexByGamepadId(string id)
private static int GetJoystickIndexByGamepadId(string id)
{
string[] data = id.Split("-");
@@ -118,6 +118,7 @@ namespace Ryujinx.Input.SDL2
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

View File

@@ -26,9 +26,11 @@ namespace Ryujinx.Input.SDL2
private readonly object _userMappingLock = new();
#pragma warning disable IDE0052 // Remove unread private member
private readonly SDL2KeyboardDriver _driver;
#pragma warning restore IDE0052
private StandardKeyboardInputConfig _configuration;
private List<ButtonMappingEntry> _buttonsUserMapping;
private readonly List<ButtonMappingEntry> _buttonsUserMapping;
private static readonly SDL_Keycode[] _keysDriverMapping = new SDL_Keycode[(int)Key.Count]
{
@@ -208,29 +210,19 @@ namespace Ryujinx.Input.SDL2
private static SDL_Keymod GetKeyboardModifierMask(Key key)
{
switch (key)
return key switch
{
case Key.ShiftLeft:
return SDL_Keymod.KMOD_LSHIFT;
case Key.ShiftRight:
return SDL_Keymod.KMOD_RSHIFT;
case Key.ControlLeft:
return SDL_Keymod.KMOD_LCTRL;
case Key.ControlRight:
return SDL_Keymod.KMOD_RCTRL;
case Key.AltLeft:
return SDL_Keymod.KMOD_LALT;
case Key.AltRight:
return SDL_Keymod.KMOD_RALT;
case Key.WinLeft:
return SDL_Keymod.KMOD_LGUI;
case Key.WinRight:
return SDL_Keymod.KMOD_RGUI;
Key.ShiftLeft => SDL_Keymod.KMOD_LSHIFT,
Key.ShiftRight => SDL_Keymod.KMOD_RSHIFT,
Key.ControlLeft => SDL_Keymod.KMOD_LCTRL,
Key.ControlRight => SDL_Keymod.KMOD_RCTRL,
Key.AltLeft => SDL_Keymod.KMOD_LALT,
Key.AltRight => SDL_Keymod.KMOD_RALT,
Key.WinLeft => SDL_Keymod.KMOD_LGUI,
Key.WinRight => SDL_Keymod.KMOD_RGUI,
// NOTE: Menu key isn't supported by SDL2.
case Key.Menu:
default:
return SDL_Keymod.KMOD_NONE;
}
_ => SDL_Keymod.KMOD_NONE,
};
}
public KeyboardStateSnapshot GetKeyboardStateSnapshot()
@@ -416,4 +408,4 @@ namespace Ryujinx.Input.SDL2
return Vector3.Zero;
}
}
}
}

View File

@@ -38,6 +38,7 @@ namespace Ryujinx.Input.SDL2
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
@@ -51,4 +52,4 @@ namespace Ryujinx.Input.SDL2
return new SDL2Keyboard(this, _keyboardIdentifers[0], "All keyboards");
}
}
}
}

View File

@@ -31,7 +31,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="size">Size of the memory block in bytes</param>
/// <param name="flags">Flags that controls memory block memory allocation</param>
/// <exception cref="OutOfMemoryException">Throw when there's no enough memory to allocate the requested size</exception>
/// <exception cref="SystemException">Throw when there's an error while allocating the requested size</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None)
{
@@ -66,7 +66,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="size">Size of the memory block in bytes</param>
/// <param name="sharedMemory">Shared memory to use as backing storage for this block</param>
/// <exception cref="OutOfMemoryException">Throw when there's no enough address space left to map the shared memory</exception>
/// <exception cref="SystemException">Throw when there's an error while mapping the shared memory</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
private MemoryBlock(ulong size, IntPtr sharedMemory)
{
@@ -82,7 +82,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <returns>A new memory block that shares storage with this one</returns>
/// <exception cref="NotSupportedException">Throw when the current memory block does not support mirroring</exception>
/// <exception cref="OutOfMemoryException">Throw when there's no enough address space left to map the shared memory</exception>
/// <exception cref="SystemException">Throw when there's an error while mapping the shared memory</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock CreateMirror()
{

View File

@@ -147,12 +147,12 @@ namespace Ryujinx.Memory
fd = shm_open((IntPtr)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600
if (fd == -1)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
if (shm_unlink((IntPtr)pMemName) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
}
@@ -165,22 +165,22 @@ namespace Ryujinx.Memory
fd = mkstemp((IntPtr)pFileName);
if (fd == -1)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
if (unlink((IntPtr)pFileName) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
}
if (ftruncate(fd, (IntPtr)size) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return (IntPtr)fd;
return fd;
}
public static void DestroySharedMemory(IntPtr handle)

View File

@@ -114,7 +114,7 @@ namespace Ryujinx.Memory
if (handle == IntPtr.Zero)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return handle;
@@ -134,7 +134,7 @@ namespace Ryujinx.Memory
if (ptr == IntPtr.Zero)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return ptr;

View File

@@ -19,10 +19,7 @@ namespace Ryujinx.SDL2.Common
{
get
{
if (_instance == null)
{
_instance = new SDL2Driver();
}
_instance ??= new SDL2Driver();
return _instance;
}
@@ -43,7 +40,7 @@ namespace Ryujinx.SDL2.Common
private readonly object _lock = new();
private SDL2Driver() {}
private SDL2Driver() { }
private const string SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS = "SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS";
@@ -80,8 +77,15 @@ namespace Ryujinx.SDL2.Common
}
// First ensure that we only enable joystick events (for connected/disconnected).
SDL_GameControllerEventState(SDL_DISABLE);
SDL_JoystickEventState(SDL_ENABLE);
if (SDL_GameControllerEventState(SDL_IGNORE) != SDL_IGNORE)
{
Logger.Error?.PrintMsg(LogClass.Application, "Couldn't change the state of game controller events.");
}
if (SDL_JoystickEventState(SDL_ENABLE) < 0)
{
Logger.Error?.PrintMsg(LogClass.Application, $"Failed to enable joystick event polling: {SDL_GetError()}");
}
// Disable all joysticks information, we don't need them no need to flood the event queue for that.
SDL_EventState(SDL_EventType.SDL_JOYAXISMOTION, SDL_DISABLE);
@@ -153,7 +157,7 @@ namespace Ryujinx.SDL2.Common
{
const int WaitTimeMs = 10;
using ManualResetEventSlim waitHandle = new ManualResetEventSlim(false);
using ManualResetEventSlim waitHandle = new(false);
while (_isRunning)
{
@@ -199,6 +203,7 @@ namespace Ryujinx.SDL2.Common
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
}