[Ryujinx.Headless.SDL2] Address dotnet-format issues (#5379)

* 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

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

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* 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

* First dotnet format pass

* Add trailing commas

* Fix naming and formatting issues
This commit is contained in:
TSRBerry 2023-06-28 19:03:27 +02:00 committed by GitHub
parent 981e0c082d
commit 40daca5684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 218 additions and 208 deletions

View File

@ -6,12 +6,10 @@ namespace Ryujinx.Headless.SDL2
{ {
public string FontFamily => "sans-serif"; public string FontFamily => "sans-serif";
public ThemeColor DefaultBackgroundColor => new ThemeColor(1, 0, 0, 0); public ThemeColor DefaultBackgroundColor => new(1, 0, 0, 0);
public ThemeColor DefaultForegroundColor => new ThemeColor(1, 1, 1, 1); public ThemeColor DefaultForegroundColor => new(1, 1, 1, 1);
public ThemeColor DefaultBorderColor => new ThemeColor(1, 1, 1, 1); public ThemeColor DefaultBorderColor => new(1, 1, 1, 1);
public ThemeColor SelectionBackgroundColor => new ThemeColor(1, 1, 1, 1); public ThemeColor SelectionBackgroundColor => new(1, 1, 1, 1);
public ThemeColor SelectionForegroundColor => new ThemeColor(1, 0, 0, 0); public ThemeColor SelectionForegroundColor => new(1, 0, 0, 0);
public HeadlessHostUiTheme() { }
} }
} }

View File

@ -11,23 +11,31 @@ namespace Ryujinx.Headless.SDL2.OpenGL
{ {
class OpenGLWindow : WindowBase class OpenGLWindow : WindowBase
{ {
private static void CheckResult(int result)
{
if (result < 0)
{
throw new InvalidOperationException($"SDL_GL function returned an error: {SDL_GetError()}");
}
}
private static void SetupOpenGLAttributes(bool sharedContext, GraphicsDebugLevel debugLevel) private static void SetupOpenGLAttributes(bool sharedContext, GraphicsDebugLevel debugLevel)
{ {
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 3); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 3));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_FLAGS, debugLevel != GraphicsDebugLevel.None ? (int)SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG : 0); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_FLAGS, debugLevel != GraphicsDebugLevel.None ? (int)SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG : 0));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, sharedContext ? 1 : 0); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, sharedContext ? 1 : 0));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ACCELERATED_VISUAL, 1); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ACCELERATED_VISUAL, 1));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_RED_SIZE, 8); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_RED_SIZE, 8));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ALPHA_SIZE, 8); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ALPHA_SIZE, 8));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 16));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STENCIL_SIZE, 0); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STENCIL_SIZE, 0));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1));
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STEREO, 0); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STEREO, 0));
} }
private class OpenToolkitBindingsContext : IBindingsContext private class OpenToolkitBindingsContext : IBindingsContext
@ -40,9 +48,9 @@ namespace Ryujinx.Headless.SDL2.OpenGL
private class SDL2OpenGLContext : IOpenGLContext private class SDL2OpenGLContext : IOpenGLContext
{ {
private IntPtr _context; private readonly IntPtr _context;
private IntPtr _window; private readonly IntPtr _window;
private bool _shouldDisposeWindow; private readonly bool _shouldDisposeWindow;
public SDL2OpenGLContext(IntPtr context, IntPtr window, bool shouldDisposeWindow = true) public SDL2OpenGLContext(IntPtr context, IntPtr window, bool shouldDisposeWindow = true)
{ {
@ -62,9 +70,9 @@ namespace Ryujinx.Headless.SDL2.OpenGL
GL.LoadBindings(new OpenToolkitBindingsContext()); GL.LoadBindings(new OpenToolkitBindingsContext());
SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0));
SDL_GL_MakeCurrent(windowHandle, IntPtr.Zero); CheckResult(SDL_GL_MakeCurrent(windowHandle, IntPtr.Zero));
return new SDL2OpenGLContext(context, windowHandle); return new SDL2OpenGLContext(context, windowHandle);
} }
@ -99,7 +107,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL
} }
} }
private GraphicsDebugLevel _glLogLevel; private readonly GraphicsDebugLevel _glLogLevel;
private SDL2OpenGLContext _openGLContext; private SDL2OpenGLContext _openGLContext;
public OpenGLWindow( public OpenGLWindow(
@ -120,7 +128,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL
// Ensure to not share this context with other contexts before this point. // Ensure to not share this context with other contexts before this point.
SetupOpenGLAttributes(false, _glLogLevel); SetupOpenGLAttributes(false, _glLogLevel);
IntPtr context = SDL_GL_CreateContext(WindowHandle); IntPtr context = SDL_GL_CreateContext(WindowHandle);
SDL_GL_SetSwapInterval(1); CheckResult(SDL_GL_SetSwapInterval(1));
if (context == IntPtr.Zero) if (context == IntPtr.Zero)
{ {
@ -157,7 +165,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL
Device.DisposeGpu(); Device.DisposeGpu();
// Unbind context and destroy everything // Unbind context and destroy everything
SDL_GL_MakeCurrent(WindowHandle, IntPtr.Zero); CheckResult(SDL_GL_MakeCurrent(WindowHandle, IntPtr.Zero));
_openGLContext.Dispose(); _openGLContext.Dispose();
} }

View File

@ -88,7 +88,7 @@ namespace Ryujinx.Headless.SDL2
// System // System
[Option("disable-ptc", Required = false, HelpText = "Disables profiled persistent translation cache.")] [Option("disable-ptc", Required = false, HelpText = "Disables profiled persistent translation cache.")]
public bool DisablePtc { get; set; } public bool DisablePTC { get; set; }
[Option("enable-internet-connection", Required = false, Default = false, HelpText = "Enables guest Internet connection.")] [Option("enable-internet-connection", Required = false, Default = false, HelpText = "Enables guest Internet connection.")]
public bool EnableInternetAccess { get; set; } public bool EnableInternetAccess { get; set; }
@ -100,7 +100,7 @@ namespace Ryujinx.Headless.SDL2
public int FsGlobalAccessLogMode { get; set; } public int FsGlobalAccessLogMode { get; set; }
[Option("disable-vsync", Required = false, HelpText = "Disables Vertical Sync.")] [Option("disable-vsync", Required = false, HelpText = "Disables Vertical Sync.")]
public bool DisableVsync { get; set; } public bool DisableVSync { get; set; }
[Option("disable-shader-cache", Required = false, HelpText = "Disables Shader cache.")] [Option("disable-shader-cache", Required = false, HelpText = "Disables Shader cache.")]
public bool DisableShaderCache { get; set; } public bool DisableShaderCache { get; set; }
@ -191,12 +191,12 @@ namespace Ryujinx.Headless.SDL2
public GraphicsBackend GraphicsBackend { get; set; } public GraphicsBackend GraphicsBackend { get; set; }
[Option("preferred-gpu-vendor", Required = false, Default = "", HelpText = "When using the Vulkan backend, prefer using the GPU from the specified vendor.")] [Option("preferred-gpu-vendor", Required = false, Default = "", HelpText = "When using the Vulkan backend, prefer using the GPU from the specified vendor.")]
public string PreferredGpuVendor { get; set; } public string PreferredGPUVendor { get; set; }
// Hacks // Hacks
[Option("expand-ram", Required = false, Default = false, HelpText = "Expands the RAM amount on the emulated system from 4GiB to 6GiB.")] [Option("expand-ram", Required = false, Default = false, HelpText = "Expands the RAM amount on the emulated system from 4GiB to 6GiB.")]
public bool ExpandRam { get; set; } public bool ExpandRAM { get; set; }
[Option("ignore-missing-services", Required = false, Default = false, HelpText = "Enable ignoring missing services.")] [Option("ignore-missing-services", Required = false, Default = false, HelpText = "Enable ignoring missing services.")]
public bool IgnoreMissingServices { get; set; } public bool IgnoreMissingServices { get; set; }

View File

@ -28,6 +28,7 @@ using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.HLE; using Ryujinx.Input.HLE;
using Ryujinx.Input.SDL2; using Ryujinx.Input.SDL2;
using Ryujinx.SDL2.Common;
using Silk.NET.Vulkan; using Silk.NET.Vulkan;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -57,7 +58,7 @@ namespace Ryujinx.Headless.SDL2
private static bool _enableKeyboard; private static bool _enableKeyboard;
private static bool _enableMouse; private static bool _enableMouse;
private static readonly InputConfigJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
static void Main(string[] args) static void Main(string[] args)
{ {
@ -67,10 +68,10 @@ namespace Ryujinx.Headless.SDL2
if (OperatingSystem.IsMacOS() || OperatingSystem.IsLinux()) if (OperatingSystem.IsMacOS() || OperatingSystem.IsLinux())
{ {
AutoResetEvent invoked = new AutoResetEvent(false); AutoResetEvent invoked = new(false);
// MacOS must perform SDL polls from the main thread. // MacOS must perform SDL polls from the main thread.
Ryujinx.SDL2.Common.SDL2Driver.MainThreadDispatcher = (Action action) => SDL2Driver.MainThreadDispatcher = action =>
{ {
invoked.Reset(); invoked.Reset();
@ -154,7 +155,7 @@ namespace Ryujinx.Headless.SDL2
ButtonL = Key.E, ButtonL = Key.E,
ButtonZl = Key.Q, ButtonZl = Key.Q,
ButtonSl = Key.Unbound, ButtonSl = Key.Unbound,
ButtonSr = Key.Unbound ButtonSr = Key.Unbound,
}, },
LeftJoyconStick = new JoyconConfigKeyboardStick<Key> LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
@ -176,7 +177,7 @@ namespace Ryujinx.Headless.SDL2
ButtonR = Key.U, ButtonR = Key.U,
ButtonZr = Key.O, ButtonZr = Key.O,
ButtonSl = Key.Unbound, ButtonSl = Key.Unbound,
ButtonSr = Key.Unbound ButtonSr = Key.Unbound,
}, },
RightJoyconStick = new JoyconConfigKeyboardStick<Key> RightJoyconStick = new JoyconConfigKeyboardStick<Key>
@ -186,7 +187,7 @@ namespace Ryujinx.Headless.SDL2
StickLeft = Key.J, StickLeft = Key.J,
StickRight = Key.L, StickRight = Key.L,
StickButton = Key.H, StickButton = Key.H,
} },
}; };
} }
else else
@ -259,8 +260,8 @@ namespace Ryujinx.Headless.SDL2
{ {
StrongRumble = 1f, StrongRumble = 1f,
WeakRumble = 1f, WeakRumble = 1f,
EnableRumble = false EnableRumble = false,
} },
}; };
} }
} }
@ -288,7 +289,7 @@ namespace Ryujinx.Headless.SDL2
try try
{ {
config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig); config = JsonHelper.DeserializeFromFile(path, _serializerContext.InputConfig);
} }
catch (JsonException) catch (JsonException)
{ {
@ -387,7 +388,7 @@ namespace Ryujinx.Headless.SDL2
_enableKeyboard = option.EnableKeyboard; _enableKeyboard = option.EnableKeyboard;
_enableMouse = option.EnableMouse; _enableMouse = option.EnableMouse;
void LoadPlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index) static void LoadPlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index)
{ {
InputConfig inputConfig = HandlePlayerConfiguration(inputProfileName, inputId, index); InputConfig inputConfig = HandlePlayerConfiguration(inputProfileName, inputId, index);
@ -468,19 +469,12 @@ namespace Ryujinx.Headless.SDL2
private static void ProgressHandler<T>(T state, int current, int total) where T : Enum private static void ProgressHandler<T>(T state, int current, int total) where T : Enum
{ {
string label; string label = state switch
switch (state)
{ {
case LoadState ptcState: LoadState => $"PTC : {current}/{total}",
label = $"PTC : {current}/{total}"; ShaderCacheState => $"Shaders : {current}/{total}",
break; _ => throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}"),
case ShaderCacheState shaderCacheState: };
label = $"Shaders : {current}/{total}";
break;
default:
throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
}
Logger.Info?.Print(LogClass.Application, label); Logger.Info?.Print(LogClass.Application, label);
} }
@ -499,9 +493,9 @@ namespace Ryujinx.Headless.SDL2
string preferredGpuId = string.Empty; string preferredGpuId = string.Empty;
Vk api = Vk.GetApi(); Vk api = Vk.GetApi();
if (!string.IsNullOrEmpty(options.PreferredGpuVendor)) if (!string.IsNullOrEmpty(options.PreferredGPUVendor))
{ {
string preferredGpuVendor = options.PreferredGpuVendor.ToLowerInvariant(); string preferredGpuVendor = options.PreferredGPUVendor.ToLowerInvariant();
var devices = VulkanRenderer.GetPhysicalDevices(api); var devices = VulkanRenderer.GetPhysicalDevices(api);
foreach (var device in devices) foreach (var device in devices)
@ -520,11 +514,9 @@ namespace Ryujinx.Headless.SDL2
vulkanWindow.GetRequiredInstanceExtensions, vulkanWindow.GetRequiredInstanceExtensions,
preferredGpuId); preferredGpuId);
} }
else
{
return new OpenGLRenderer(); return new OpenGLRenderer();
} }
}
private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options) private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options)
{ {
@ -537,20 +529,20 @@ namespace Ryujinx.Headless.SDL2
renderer = new ThreadedRenderer(renderer); renderer = new ThreadedRenderer(renderer);
} }
HLEConfiguration configuration = new HLEConfiguration(_virtualFileSystem, HLEConfiguration configuration = new(_virtualFileSystem,
_libHacHorizonManager, _libHacHorizonManager,
_contentManager, _contentManager,
_accountManager, _accountManager,
_userChannelPersistence, _userChannelPersistence,
renderer, renderer,
new SDL2HardwareDeviceDriver(), new SDL2HardwareDeviceDriver(),
options.ExpandRam ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB, options.ExpandRAM ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB,
window, window,
options.SystemLanguage, options.SystemLanguage,
options.SystemRegion, options.SystemRegion,
!options.DisableVsync, !options.DisableVSync,
!options.DisableDockedMode, !options.DisableDockedMode,
!options.DisablePtc, !options.DisablePTC,
options.EnableInternetAccess, options.EnableInternetAccess,
!options.DisableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None, !options.DisableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None,
options.FsGlobalAccessLogMode, options.FsGlobalAccessLogMode,

View File

@ -1,4 +1,5 @@
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Input; using Ryujinx.Input;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
@ -14,7 +15,7 @@ namespace Ryujinx.Headless.SDL2
private const int CursorHideIdleTime = 5; // seconds private const int CursorHideIdleTime = 5; // seconds
private bool _isDisposed; private bool _isDisposed;
private HideCursorMode _hideCursorMode; private readonly HideCursorMode _hideCursorMode;
private bool _isHidden; private bool _isHidden;
private long _lastCursorMoveTime; private long _lastCursorMoveTime;
@ -22,7 +23,7 @@ namespace Ryujinx.Headless.SDL2
public Vector2 CurrentPosition { get; private set; } public Vector2 CurrentPosition { get; private set; }
public Vector2 Scroll { get; private set; } public Vector2 Scroll { get; private set; }
public Size _clientSize; public Size ClientSize;
public SDL2MouseDriver(HideCursorMode hideCursorMode) public SDL2MouseDriver(HideCursorMode hideCursorMode)
{ {
@ -31,7 +32,11 @@ namespace Ryujinx.Headless.SDL2
if (_hideCursorMode == HideCursorMode.Always) if (_hideCursorMode == HideCursorMode.Always)
{ {
SDL_ShowCursor(SDL_DISABLE); if (SDL_ShowCursor(SDL_DISABLE) != SDL_DISABLE)
{
Logger.Error?.PrintMsg(LogClass.Application, "Failed to disable the cursor.");
}
_isHidden = true; _isHidden = true;
} }
} }
@ -46,7 +51,7 @@ namespace Ryujinx.Headless.SDL2
public void UpdatePosition() public void UpdatePosition()
{ {
SDL_GetMouseState(out int posX, out int posY); _ = SDL_GetMouseState(out int posX, out int posY);
Vector2 position = new(posX, posY); Vector2 position = new(posX, posY);
if (CurrentPosition != position) if (CurrentPosition != position)
@ -71,7 +76,11 @@ namespace Ryujinx.Headless.SDL2
{ {
if (!_isHidden) if (!_isHidden)
{ {
SDL_ShowCursor(SDL_DISABLE); if (SDL_ShowCursor(SDL_DISABLE) != SDL_DISABLE)
{
Logger.Error?.PrintMsg(LogClass.Application, "Failed to disable the cursor.");
}
_isHidden = true; _isHidden = true;
} }
} }
@ -79,7 +88,11 @@ namespace Ryujinx.Headless.SDL2
{ {
if (_isHidden) if (_isHidden)
{ {
SDL_ShowCursor(SDL_ENABLE); if (SDL_ShowCursor(SDL_ENABLE) != SDL_ENABLE)
{
Logger.Error?.PrintMsg(LogClass.Application, "Failed to enable the cursor.");
}
_isHidden = false; _isHidden = false;
} }
} }
@ -118,7 +131,7 @@ namespace Ryujinx.Headless.SDL2
public void SetClientSize(int width, int height) public void SetClientSize(int width, int height)
{ {
_clientSize = new Size(width, height); ClientSize = new Size(width, height);
} }
public bool IsButtonPressed(MouseButton button) public bool IsButtonPressed(MouseButton button)
@ -128,7 +141,7 @@ namespace Ryujinx.Headless.SDL2
public Size GetClientSize() public Size GetClientSize()
{ {
return _clientSize; return ClientSize;
} }
public string DriverName => "SDL2"; public string DriverName => "SDL2";

View File

@ -10,7 +10,7 @@ namespace Ryujinx.Headless.SDL2.Vulkan
{ {
class VulkanWindow : WindowBase class VulkanWindow : WindowBase
{ {
private GraphicsDebugLevel _glLogLevel; private readonly GraphicsDebugLevel _glLogLevel;
public VulkanWindow( public VulkanWindow(
InputManager inputManager, InputManager inputManager,
@ -33,16 +33,16 @@ namespace Ryujinx.Headless.SDL2.Vulkan
MouseDriver.SetClientSize(DefaultWidth, DefaultHeight); MouseDriver.SetClientSize(DefaultWidth, DefaultHeight);
} }
private void BasicInvoke(Action action) private static void BasicInvoke(Action action)
{ {
action(); action();
} }
public unsafe IntPtr CreateWindowSurface(IntPtr instance) public IntPtr CreateWindowSurface(IntPtr instance)
{ {
ulong surfaceHandle = 0; ulong surfaceHandle = 0;
Action createSurface = () => void CreateSurface()
{ {
if (SDL_Vulkan_CreateSurface(WindowHandle, instance, out surfaceHandle) == SDL_bool.SDL_FALSE) if (SDL_Vulkan_CreateSurface(WindowHandle, instance, out surfaceHandle) == SDL_bool.SDL_FALSE)
{ {
@ -52,15 +52,15 @@ namespace Ryujinx.Headless.SDL2.Vulkan
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
}; }
if (SDL2Driver.MainThreadDispatcher != null) if (SDL2Driver.MainThreadDispatcher != null)
{ {
SDL2Driver.MainThreadDispatcher(createSurface); SDL2Driver.MainThreadDispatcher(CreateSurface);
} }
else else
{ {
createSurface(); CreateSurface();
} }
return (IntPtr)surfaceHandle; return (IntPtr)surfaceHandle;

View File

@ -4,6 +4,8 @@ using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Multithreading; using Ryujinx.Graphics.GAL.Multithreading;
using Ryujinx.Graphics.Gpu;
using Ryujinx.Graphics.OpenGL;
using Ryujinx.HLE.HOS.Applets; using Ryujinx.HLE.HOS.Applets;
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types; using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
using Ryujinx.HLE.Ui; using Ryujinx.HLE.Ui;
@ -30,7 +32,7 @@ namespace Ryujinx.Headless.SDL2
private const SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN; private const SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN;
private const int TargetFps = 60; private const int TargetFps = 60;
private static ConcurrentQueue<Action> MainThreadActions = new ConcurrentQueue<Action>(); private static readonly ConcurrentQueue<Action> _mainThreadActions = new();
[LibraryImport("SDL2")] [LibraryImport("SDL2")]
// TODO: Remove this as soon as SDL2-CS was updated to expose this method publicly // TODO: Remove this as soon as SDL2-CS was updated to expose this method publicly
@ -38,7 +40,7 @@ namespace Ryujinx.Headless.SDL2
public static void QueueMainThreadAction(Action action) public static void QueueMainThreadAction(Action action)
{ {
MainThreadActions.Enqueue(action); _mainThreadActions.Enqueue(action);
} }
public NpadManager NpadManager { get; } public NpadManager NpadManager { get; }
@ -55,9 +57,9 @@ namespace Ryujinx.Headless.SDL2
public int Height { get; private set; } public int Height { get; private set; }
protected SDL2MouseDriver MouseDriver; protected SDL2MouseDriver MouseDriver;
private InputManager _inputManager; private readonly InputManager _inputManager;
private IKeyboard _keyboardInterface; private readonly IKeyboard _keyboardInterface;
private GraphicsDebugLevel _glLogLevel; private readonly GraphicsDebugLevel _glLogLevel;
private readonly Stopwatch _chrono; private readonly Stopwatch _chrono;
private readonly long _ticksPerFrame; private readonly long _ticksPerFrame;
private readonly CancellationTokenSource _gpuCancellationTokenSource; private readonly CancellationTokenSource _gpuCancellationTokenSource;
@ -71,8 +73,8 @@ namespace Ryujinx.Headless.SDL2
private string _gpuVendorName; private string _gpuVendorName;
private AspectRatio _aspectRatio; private readonly AspectRatio _aspectRatio;
private bool _enableMouse; private readonly bool _enableMouse;
public WindowBase( public WindowBase(
InputManager inputManager, InputManager inputManager,
@ -192,9 +194,6 @@ namespace Ryujinx.Headless.SDL2
case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE:
Exit(); Exit();
break; break;
default:
break;
} }
} }
else else
@ -260,7 +259,7 @@ namespace Ryujinx.Headless.SDL2
if (_ticks >= _ticksPerFrame) if (_ticks >= _ticksPerFrame)
{ {
string dockedMode = Device.System.State.DockedMode ? "Docked" : "Handheld"; string dockedMode = Device.System.State.DockedMode ? "Docked" : "Handheld";
float scale = Graphics.Gpu.GraphicsConfig.ResScale; float scale = GraphicsConfig.ResScale;
if (scale != 1) if (scale != 1)
{ {
dockedMode += $" ({scale}x)"; dockedMode += $" ({scale}x)";
@ -309,9 +308,9 @@ namespace Ryujinx.Headless.SDL2
_exitEvent.Dispose(); _exitEvent.Dispose();
} }
public void ProcessMainThreadQueue() public static void ProcessMainThreadQueue()
{ {
while (MainThreadActions.TryDequeue(out Action action)) while (_mainThreadActions.TryDequeue(out Action action))
{ {
action(); action();
} }
@ -334,7 +333,7 @@ namespace Ryujinx.Headless.SDL2
_exitEvent.Set(); _exitEvent.Set();
} }
private void NVStutterWorkaround() private void NvidiaStutterWorkaround()
{ {
while (_isActive) while (_isActive)
{ {
@ -348,7 +347,7 @@ namespace Ryujinx.Headless.SDL2
// TODO: This should be removed when the issue with the GateThread is resolved. // TODO: This should be removed when the issue with the GateThread is resolved.
ThreadPool.QueueUserWorkItem((state) => { }); ThreadPool.QueueUserWorkItem(state => { });
Thread.Sleep(300); Thread.Sleep(300);
} }
} }
@ -396,20 +395,20 @@ namespace Ryujinx.Headless.SDL2
InitializeWindow(); InitializeWindow();
Thread renderLoopThread = new Thread(Render) Thread renderLoopThread = new(Render)
{ {
Name = "GUI.RenderLoop" Name = "GUI.RenderLoop",
}; };
renderLoopThread.Start(); renderLoopThread.Start();
Thread nvStutterWorkaround = null; Thread nvidiaStutterWorkaround = null;
if (Renderer is Graphics.OpenGL.OpenGLRenderer) if (Renderer is OpenGLRenderer)
{ {
nvStutterWorkaround = new Thread(NVStutterWorkaround) nvidiaStutterWorkaround = new Thread(NvidiaStutterWorkaround)
{ {
Name = "GUI.NVStutterWorkaround" Name = "GUI.NvidiaStutterWorkaround",
}; };
nvStutterWorkaround.Start(); nvidiaStutterWorkaround.Start();
} }
MainLoop(); MainLoop();
@ -418,7 +417,7 @@ namespace Ryujinx.Headless.SDL2
// We only need to wait for all commands submitted during the main gpu loop to be processed. // We only need to wait for all commands submitted during the main gpu loop to be processed.
_gpuDoneEvent.WaitOne(); _gpuDoneEvent.WaitOne();
_gpuDoneEvent.Dispose(); _gpuDoneEvent.Dispose();
nvStutterWorkaround?.Join(); nvidiaStutterWorkaround?.Join();
Exit(); Exit();
} }
@ -465,13 +464,13 @@ namespace Ryujinx.Headless.SDL2
public bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText) public bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText)
{ {
SDL_MessageBoxData data = new SDL_MessageBoxData SDL_MessageBoxData data = new()
{ {
title = title, title = title,
message = message, message = message,
buttons = new SDL_MessageBoxButtonData[buttonsText.Length], buttons = new SDL_MessageBoxButtonData[buttonsText.Length],
numbuttons = buttonsText.Length, numbuttons = buttonsText.Length,
window = WindowHandle window = WindowHandle,
}; };
for (int i = 0; i < buttonsText.Length; i++) for (int i = 0; i < buttonsText.Length; i++)
@ -479,7 +478,7 @@ namespace Ryujinx.Headless.SDL2
data.buttons[i] = new SDL_MessageBoxButtonData data.buttons[i] = new SDL_MessageBoxButtonData
{ {
buttonid = i, buttonid = i,
text = buttonsText[i] text = buttonsText[i],
}; };
} }