aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Headless.SDL2/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Headless.SDL2/Program.cs')
-rw-r--r--src/Ryujinx.Headless.SDL2/Program.cs234
1 files changed, 113 insertions, 121 deletions
diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs
index 6e6b4a7f..39eae14a 100644
--- a/src/Ryujinx.Headless.SDL2/Program.cs
+++ b/src/Ryujinx.Headless.SDL2/Program.cs
@@ -28,6 +28,7 @@ using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.Input;
using Ryujinx.Input.HLE;
using Ryujinx.Input.SDL2;
+using Ryujinx.SDL2.Common;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
@@ -57,7 +58,7 @@ namespace Ryujinx.Headless.SDL2
private static bool _enableKeyboard;
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)
{
@@ -67,10 +68,10 @@ namespace Ryujinx.Headless.SDL2
if (OperatingSystem.IsMacOS() || OperatingSystem.IsLinux())
{
- AutoResetEvent invoked = new AutoResetEvent(false);
+ AutoResetEvent invoked = new(false);
// MacOS must perform SDL polls from the main thread.
- Ryujinx.SDL2.Common.SDL2Driver.MainThreadDispatcher = (Action action) =>
+ SDL2Driver.MainThreadDispatcher = action =>
{
invoked.Reset();
@@ -140,53 +141,53 @@ namespace Ryujinx.Headless.SDL2
{
config = new StandardKeyboardInputConfig
{
- Version = InputConfig.CurrentVersion,
- Backend = InputBackendType.WindowKeyboard,
- Id = null,
- ControllerType = ControllerType.JoyconPair,
- LeftJoycon = new LeftJoyconCommonConfig<Key>
+ Version = InputConfig.CurrentVersion,
+ Backend = InputBackendType.WindowKeyboard,
+ Id = null,
+ ControllerType = ControllerType.JoyconPair,
+ LeftJoycon = new LeftJoyconCommonConfig<Key>
{
- DpadUp = Key.Up,
- DpadDown = Key.Down,
- DpadLeft = Key.Left,
- DpadRight = Key.Right,
- ButtonMinus = Key.Minus,
- ButtonL = Key.E,
- ButtonZl = Key.Q,
- ButtonSl = Key.Unbound,
- ButtonSr = Key.Unbound
+ DpadUp = Key.Up,
+ DpadDown = Key.Down,
+ DpadLeft = Key.Left,
+ DpadRight = Key.Right,
+ ButtonMinus = Key.Minus,
+ ButtonL = Key.E,
+ ButtonZl = Key.Q,
+ ButtonSl = Key.Unbound,
+ ButtonSr = Key.Unbound,
},
- LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
+ LeftJoyconStick = new JoyconConfigKeyboardStick<Key>
{
- StickUp = Key.W,
- StickDown = Key.S,
- StickLeft = Key.A,
- StickRight = Key.D,
- StickButton = Key.F,
+ StickUp = Key.W,
+ StickDown = Key.S,
+ StickLeft = Key.A,
+ StickRight = Key.D,
+ StickButton = Key.F,
},
- RightJoycon = new RightJoyconCommonConfig<Key>
+ RightJoycon = new RightJoyconCommonConfig<Key>
{
- ButtonA = Key.Z,
- ButtonB = Key.X,
- ButtonX = Key.C,
- ButtonY = Key.V,
- ButtonPlus = Key.Plus,
- ButtonR = Key.U,
- ButtonZr = Key.O,
- ButtonSl = Key.Unbound,
- ButtonSr = Key.Unbound
+ ButtonA = Key.Z,
+ ButtonB = Key.X,
+ ButtonX = Key.C,
+ ButtonY = Key.V,
+ ButtonPlus = Key.Plus,
+ ButtonR = Key.U,
+ ButtonZr = Key.O,
+ ButtonSl = Key.Unbound,
+ ButtonSr = Key.Unbound,
},
RightJoyconStick = new JoyconConfigKeyboardStick<Key>
{
- StickUp = Key.I,
- StickDown = Key.K,
- StickLeft = Key.J,
- StickRight = Key.L,
- StickButton = Key.H,
- }
+ StickUp = Key.I,
+ StickDown = Key.K,
+ StickLeft = Key.J,
+ StickRight = Key.L,
+ StickButton = Key.H,
+ },
};
}
else
@@ -195,72 +196,72 @@ namespace Ryujinx.Headless.SDL2
config = new StandardControllerInputConfig
{
- Version = InputConfig.CurrentVersion,
- Backend = InputBackendType.GamepadSDL2,
- Id = null,
- ControllerType = ControllerType.JoyconPair,
- DeadzoneLeft = 0.1f,
- DeadzoneRight = 0.1f,
- RangeLeft = 1.0f,
- RangeRight = 1.0f,
+ Version = InputConfig.CurrentVersion,
+ Backend = InputBackendType.GamepadSDL2,
+ Id = null,
+ ControllerType = ControllerType.JoyconPair,
+ DeadzoneLeft = 0.1f,
+ DeadzoneRight = 0.1f,
+ RangeLeft = 1.0f,
+ RangeRight = 1.0f,
TriggerThreshold = 0.5f,
LeftJoycon = new LeftJoyconCommonConfig<ConfigGamepadInputId>
{
- DpadUp = ConfigGamepadInputId.DpadUp,
- DpadDown = ConfigGamepadInputId.DpadDown,
- DpadLeft = ConfigGamepadInputId.DpadLeft,
- DpadRight = ConfigGamepadInputId.DpadRight,
- ButtonMinus = ConfigGamepadInputId.Minus,
- ButtonL = ConfigGamepadInputId.LeftShoulder,
- ButtonZl = ConfigGamepadInputId.LeftTrigger,
- ButtonSl = ConfigGamepadInputId.Unbound,
- ButtonSr = ConfigGamepadInputId.Unbound,
+ DpadUp = ConfigGamepadInputId.DpadUp,
+ DpadDown = ConfigGamepadInputId.DpadDown,
+ DpadLeft = ConfigGamepadInputId.DpadLeft,
+ DpadRight = ConfigGamepadInputId.DpadRight,
+ ButtonMinus = ConfigGamepadInputId.Minus,
+ ButtonL = ConfigGamepadInputId.LeftShoulder,
+ ButtonZl = ConfigGamepadInputId.LeftTrigger,
+ ButtonSl = ConfigGamepadInputId.Unbound,
+ ButtonSr = ConfigGamepadInputId.Unbound,
},
LeftJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
{
- Joystick = ConfigStickInputId.Left,
- StickButton = ConfigGamepadInputId.LeftStick,
+ Joystick = ConfigStickInputId.Left,
+ StickButton = ConfigGamepadInputId.LeftStick,
InvertStickX = false,
InvertStickY = false,
- Rotate90CW = false,
+ Rotate90CW = false,
},
RightJoycon = new RightJoyconCommonConfig<ConfigGamepadInputId>
{
- ButtonA = isNintendoStyle ? ConfigGamepadInputId.A : ConfigGamepadInputId.B,
- ButtonB = isNintendoStyle ? ConfigGamepadInputId.B : ConfigGamepadInputId.A,
- ButtonX = isNintendoStyle ? ConfigGamepadInputId.X : ConfigGamepadInputId.Y,
- ButtonY = isNintendoStyle ? ConfigGamepadInputId.Y : ConfigGamepadInputId.X,
- ButtonPlus = ConfigGamepadInputId.Plus,
- ButtonR = ConfigGamepadInputId.RightShoulder,
- ButtonZr = ConfigGamepadInputId.RightTrigger,
- ButtonSl = ConfigGamepadInputId.Unbound,
- ButtonSr = ConfigGamepadInputId.Unbound,
+ ButtonA = isNintendoStyle ? ConfigGamepadInputId.A : ConfigGamepadInputId.B,
+ ButtonB = isNintendoStyle ? ConfigGamepadInputId.B : ConfigGamepadInputId.A,
+ ButtonX = isNintendoStyle ? ConfigGamepadInputId.X : ConfigGamepadInputId.Y,
+ ButtonY = isNintendoStyle ? ConfigGamepadInputId.Y : ConfigGamepadInputId.X,
+ ButtonPlus = ConfigGamepadInputId.Plus,
+ ButtonR = ConfigGamepadInputId.RightShoulder,
+ ButtonZr = ConfigGamepadInputId.RightTrigger,
+ ButtonSl = ConfigGamepadInputId.Unbound,
+ ButtonSr = ConfigGamepadInputId.Unbound,
},
RightJoyconStick = new JoyconConfigControllerStick<ConfigGamepadInputId, ConfigStickInputId>
{
- Joystick = ConfigStickInputId.Right,
- StickButton = ConfigGamepadInputId.RightStick,
+ Joystick = ConfigStickInputId.Right,
+ StickButton = ConfigGamepadInputId.RightStick,
InvertStickX = false,
InvertStickY = false,
- Rotate90CW = false,
+ Rotate90CW = false,
},
Motion = new StandardMotionConfigController
{
MotionBackend = MotionInputBackendType.GamepadDriver,
EnableMotion = true,
- Sensitivity = 100,
+ Sensitivity = 100,
GyroDeadzone = 1,
},
Rumble = new RumbleConfigController
{
StrongRumble = 1f,
WeakRumble = 1f,
- EnableRumble = false
- }
+ EnableRumble = false,
+ },
};
}
}
@@ -288,7 +289,7 @@ namespace Ryujinx.Headless.SDL2
try
{
- config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig);
+ config = JsonHelper.DeserializeFromFile(path, _serializerContext.InputConfig);
}
catch (JsonException)
{
@@ -310,7 +311,7 @@ namespace Ryujinx.Headless.SDL2
{
if (controllerConfig.RangeLeft <= 0.0f && controllerConfig.RangeRight <= 0.0f)
{
- controllerConfig.RangeLeft = 1.0f;
+ controllerConfig.RangeLeft = 1.0f;
controllerConfig.RangeRight = 1.0f;
Logger.Info?.Print(LogClass.Application, $"{config.PlayerIndex} stick range reset. Save the profile now to update your configuration");
@@ -387,7 +388,7 @@ namespace Ryujinx.Headless.SDL2
_enableKeyboard = option.EnableKeyboard;
_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);
@@ -468,19 +469,12 @@ namespace Ryujinx.Headless.SDL2
private static void ProgressHandler<T>(T state, int current, int total) where T : Enum
{
- string label;
-
- switch (state)
+ string label = state switch
{
- case LoadState ptcState:
- label = $"PTC : {current}/{total}";
- break;
- case ShaderCacheState shaderCacheState:
- label = $"Shaders : {current}/{total}";
- break;
- default:
- throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}");
- }
+ LoadState => $"PTC : {current}/{total}",
+ ShaderCacheState => $"Shaders : {current}/{total}",
+ _ => throw new ArgumentException($"Unknown Progress Handler type {typeof(T)}"),
+ };
Logger.Info?.Print(LogClass.Application, label);
}
@@ -499,9 +493,9 @@ namespace Ryujinx.Headless.SDL2
string preferredGpuId = string.Empty;
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);
foreach (var device in devices)
@@ -520,10 +514,8 @@ namespace Ryujinx.Headless.SDL2
vulkanWindow.GetRequiredInstanceExtensions,
preferredGpuId);
}
- else
- {
- return new OpenGLRenderer();
- }
+
+ return new OpenGLRenderer();
}
private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options)
@@ -537,31 +529,31 @@ namespace Ryujinx.Headless.SDL2
renderer = new ThreadedRenderer(renderer);
}
- HLEConfiguration configuration = new HLEConfiguration(_virtualFileSystem,
- _libHacHorizonManager,
- _contentManager,
- _accountManager,
- _userChannelPersistence,
- renderer,
- new SDL2HardwareDeviceDriver(),
- options.ExpandRam ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB,
- window,
- options.SystemLanguage,
- options.SystemRegion,
- !options.DisableVsync,
- !options.DisableDockedMode,
- !options.DisablePtc,
- options.EnableInternetAccess,
- !options.DisableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None,
- options.FsGlobalAccessLogMode,
- options.SystemTimeOffset,
- options.SystemTimeZone,
- options.MemoryManagerMode,
- options.IgnoreMissingServices,
- options.AspectRatio,
- options.AudioVolume,
- options.UseHypervisor ?? true,
- options.MultiplayerLanInterfaceId);
+ HLEConfiguration configuration = new(_virtualFileSystem,
+ _libHacHorizonManager,
+ _contentManager,
+ _accountManager,
+ _userChannelPersistence,
+ renderer,
+ new SDL2HardwareDeviceDriver(),
+ options.ExpandRAM ? MemoryConfiguration.MemoryConfiguration6GiB : MemoryConfiguration.MemoryConfiguration4GiB,
+ window,
+ options.SystemLanguage,
+ options.SystemRegion,
+ !options.DisableVSync,
+ !options.DisableDockedMode,
+ !options.DisablePTC,
+ options.EnableInternetAccess,
+ !options.DisableFsIntegrityChecks ? IntegrityCheckLevel.ErrorOnInvalid : IntegrityCheckLevel.None,
+ options.FsGlobalAccessLogMode,
+ options.SystemTimeOffset,
+ options.SystemTimeZone,
+ options.MemoryManagerMode,
+ options.IgnoreMissingServices,
+ options.AspectRatio,
+ options.AudioVolume,
+ options.UseHypervisor ?? true,
+ options.MultiplayerLanInterfaceId);
return new Switch(configuration);
}
@@ -713,4 +705,4 @@ namespace Ryujinx.Headless.SDL2
return true;
}
}
-} \ No newline at end of file
+}