mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-12-22 23:55:47 +00:00
misc: Small code improvements.
This commit is contained in:
parent
5f6d9eef6b
commit
b2a35ecf6c
6 changed files with 71 additions and 112 deletions
|
@ -31,7 +31,7 @@
|
||||||
alt="">
|
alt="">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://discord.gg/dHPrkBkkyA">
|
<a href="https://discord.gg/dHPrkBkkyA">
|
||||||
<img src="https://img.shields.io/discord/410208534861447168?color=5865F2&label=Ryujinx&logo=discord&logoColor=white"
|
<img src="https://img.shields.io/discord/1294443224030511104?color=5865F2&label=Ryujinx&logo=discord&logoColor=white"
|
||||||
alt="Discord">
|
alt="Discord">
|
||||||
</a>
|
</a>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -492,7 +492,7 @@ namespace Ryujinx.Common.Collections
|
||||||
Start = start;
|
Start = start;
|
||||||
End = end;
|
End = end;
|
||||||
Max = end;
|
Max = end;
|
||||||
Values = new List<RangeNode<TKey, TValue>> { new RangeNode<TKey, TValue>(start, end, value) };
|
Values = [ new RangeNode<TKey, TValue>(start, end, value) ];
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,7 @@ namespace Ryujinx.Headless.SDL2
|
||||||
|
|
||||||
public bool TextProcessingEnabled
|
public bool TextProcessingEnabled
|
||||||
{
|
{
|
||||||
get
|
get => Volatile.Read(ref _canProcessInput);
|
||||||
{
|
|
||||||
return Volatile.Read(ref _canProcessInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,10 @@ namespace Ryujinx.Input.SDL2
|
||||||
{
|
{
|
||||||
private bool HasConfiguration => _configuration != null;
|
private bool HasConfiguration => _configuration != null;
|
||||||
|
|
||||||
private record struct ButtonMappingEntry(GamepadButtonInputId To, GamepadButtonInputId From);
|
private readonly record struct ButtonMappingEntry(GamepadButtonInputId To, GamepadButtonInputId From)
|
||||||
|
{
|
||||||
|
public bool IsValid => To is not GamepadButtonInputId.Unbound && From is not GamepadButtonInputId.Unbound;
|
||||||
|
}
|
||||||
|
|
||||||
private StandardControllerInputConfig _configuration;
|
private StandardControllerInputConfig _configuration;
|
||||||
|
|
||||||
|
@ -144,18 +147,16 @@ namespace Ryujinx.Input.SDL2
|
||||||
|
|
||||||
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
|
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
|
||||||
{
|
{
|
||||||
if (Features.HasFlag(GamepadFeaturesFlag.Rumble))
|
if (!Features.HasFlag(GamepadFeaturesFlag.Rumble)) return;
|
||||||
{
|
|
||||||
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
|
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
|
||||||
ushort highFrequencyRaw = (ushort)(highFrequency * ushort.MaxValue);
|
ushort highFrequencyRaw = (ushort)(highFrequency * ushort.MaxValue);
|
||||||
|
|
||||||
if (durationMs == uint.MaxValue)
|
if (durationMs == uint.MaxValue)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, SDL_HAPTIC_INFINITY) != 0)
|
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, SDL_HAPTIC_INFINITY) != 0)
|
||||||
{
|
|
||||||
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
|
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (durationMs > SDL_HAPTIC_INFINITY)
|
else if (durationMs > SDL_HAPTIC_INFINITY)
|
||||||
{
|
{
|
||||||
Logger.Error?.Print(LogClass.Hid, $"Unsupported rumble duration {durationMs}");
|
Logger.Error?.Print(LogClass.Hid, $"Unsupported rumble duration {durationMs}");
|
||||||
|
@ -163,28 +164,22 @@ namespace Ryujinx.Input.SDL2
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, durationMs) != 0)
|
if (SDL_GameControllerRumble(_gamepadHandle, lowFrequencyRaw, highFrequencyRaw, durationMs) != 0)
|
||||||
{
|
|
||||||
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
|
Logger.Error?.Print(LogClass.Hid, "Rumble is not supported on this game controller.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3 GetMotionData(MotionInputId inputId)
|
public Vector3 GetMotionData(MotionInputId inputId)
|
||||||
{
|
{
|
||||||
SDL_SensorType sensorType = SDL_SensorType.SDL_SENSOR_INVALID;
|
SDL_SensorType sensorType = inputId switch
|
||||||
|
{
|
||||||
|
MotionInputId.Accelerometer => SDL_SensorType.SDL_SENSOR_ACCEL,
|
||||||
|
MotionInputId.Gyroscope => SDL_SensorType.SDL_SENSOR_GYRO,
|
||||||
|
_ => SDL_SensorType.SDL_SENSOR_INVALID
|
||||||
|
};
|
||||||
|
|
||||||
if (inputId == MotionInputId.Accelerometer)
|
if (!Features.HasFlag(GamepadFeaturesFlag.Motion) || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
|
||||||
{
|
return Vector3.Zero;
|
||||||
sensorType = SDL_SensorType.SDL_SENSOR_ACCEL;
|
|
||||||
}
|
|
||||||
else if (inputId == MotionInputId.Gyroscope)
|
|
||||||
{
|
|
||||||
sensorType = SDL_SensorType.SDL_SENSOR_GYRO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Features.HasFlag(GamepadFeaturesFlag.Motion) && sensorType != SDL_SensorType.SDL_SENSOR_INVALID)
|
|
||||||
{
|
|
||||||
const int ElementCount = 3;
|
const int ElementCount = 3;
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -193,37 +188,23 @@ namespace Ryujinx.Input.SDL2
|
||||||
|
|
||||||
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (IntPtr)values, ElementCount);
|
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (IntPtr)values, ElementCount);
|
||||||
|
|
||||||
if (result == 0)
|
if (result != 0)
|
||||||
{
|
return Vector3.Zero;
|
||||||
|
|
||||||
Vector3 value = new(values[0], values[1], values[2]);
|
Vector3 value = new(values[0], values[1], values[2]);
|
||||||
|
|
||||||
if (inputId == MotionInputId.Gyroscope)
|
return inputId switch
|
||||||
{
|
{
|
||||||
return RadToDegree(value);
|
MotionInputId.Gyroscope => RadToDegree(value),
|
||||||
}
|
MotionInputId.Accelerometer => GsToMs2(value),
|
||||||
|
_ => value
|
||||||
if (inputId == MotionInputId.Accelerometer)
|
};
|
||||||
{
|
|
||||||
return GsToMs2(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Vector3.Zero;
|
private static Vector3 RadToDegree(Vector3 rad) => rad * (180 / MathF.PI);
|
||||||
}
|
|
||||||
|
|
||||||
private static Vector3 RadToDegree(Vector3 rad)
|
private static Vector3 GsToMs2(Vector3 gs) => gs / SDL_STANDARD_GRAVITY;
|
||||||
{
|
|
||||||
return rad * (180 / MathF.PI);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Vector3 GsToMs2(Vector3 gs)
|
|
||||||
{
|
|
||||||
return gs / SDL_STANDARD_GRAVITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetConfiguration(InputConfig configuration)
|
public void SetConfiguration(InputConfig configuration)
|
||||||
{
|
{
|
||||||
|
@ -278,16 +259,13 @@ namespace Ryujinx.Input.SDL2
|
||||||
lock (_userMappingLock)
|
lock (_userMappingLock)
|
||||||
{
|
{
|
||||||
if (_buttonsUserMapping.Count == 0)
|
if (_buttonsUserMapping.Count == 0)
|
||||||
{
|
|
||||||
return rawState;
|
return rawState;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
|
||||||
foreach (ButtonMappingEntry entry in _buttonsUserMapping)
|
foreach (ButtonMappingEntry entry in _buttonsUserMapping)
|
||||||
{
|
{
|
||||||
if (entry.From == GamepadButtonInputId.Unbound || entry.To == GamepadButtonInputId.Unbound)
|
if (!entry.IsValid) continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not touch state of button already pressed
|
// Do not touch state of button already pressed
|
||||||
if (!result.IsPressed(entry.To))
|
if (!result.IsPressed(entry.To))
|
||||||
|
@ -316,9 +294,8 @@ namespace Ryujinx.Input.SDL2
|
||||||
public (float, float) GetStick(StickInputId inputId)
|
public (float, float) GetStick(StickInputId inputId)
|
||||||
{
|
{
|
||||||
if (inputId == StickInputId.Unbound)
|
if (inputId == StickInputId.Unbound)
|
||||||
{
|
|
||||||
return (0.0f, 0.0f);
|
return (0.0f, 0.0f);
|
||||||
}
|
|
||||||
|
|
||||||
(short stickX, short stickY) = GetStickXY(inputId);
|
(short stickX, short stickY) = GetStickXY(inputId);
|
||||||
|
|
||||||
|
@ -351,6 +328,7 @@ namespace Ryujinx.Input.SDL2
|
||||||
return (resultX, resultY);
|
return (resultX, resultY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once InconsistentNaming
|
||||||
private (short, short) GetStickXY(StickInputId inputId) =>
|
private (short, short) GetStickXY(StickInputId inputId) =>
|
||||||
inputId switch
|
inputId switch
|
||||||
{
|
{
|
||||||
|
@ -365,13 +343,11 @@ namespace Ryujinx.Input.SDL2
|
||||||
|
|
||||||
public bool IsPressed(GamepadButtonInputId inputId)
|
public bool IsPressed(GamepadButtonInputId inputId)
|
||||||
{
|
{
|
||||||
if (inputId == GamepadButtonInputId.LeftTrigger)
|
switch (inputId)
|
||||||
{
|
{
|
||||||
|
case GamepadButtonInputId.LeftTrigger:
|
||||||
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)) > _triggerThreshold;
|
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT)) > _triggerThreshold;
|
||||||
}
|
case GamepadButtonInputId.RightTrigger:
|
||||||
|
|
||||||
if (inputId == GamepadButtonInputId.RightTrigger)
|
|
||||||
{
|
|
||||||
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) > _triggerThreshold;
|
return ConvertRawStickValue(SDL_GameControllerGetAxis(_gamepadHandle, SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) > _triggerThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||||
public static string ActiveApplicationTitle(ProcessResult activeProcess, string applicationVersion, string pauseString = "")
|
public static string ActiveApplicationTitle(ProcessResult activeProcess, string applicationVersion, string pauseString = "")
|
||||||
{
|
{
|
||||||
if (activeProcess == null)
|
if (activeProcess == null)
|
||||||
{
|
return string.Empty;
|
||||||
return String.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
string titleNameSection = string.IsNullOrWhiteSpace(activeProcess.Name) ? string.Empty : $" {activeProcess.Name}";
|
string titleNameSection = string.IsNullOrWhiteSpace(activeProcess.Name) ? string.Empty : $" {activeProcess.Name}";
|
||||||
string titleVersionSection = string.IsNullOrWhiteSpace(activeProcess.DisplayVersion) ? string.Empty : $" v{activeProcess.DisplayVersion}";
|
string titleVersionSection = string.IsNullOrWhiteSpace(activeProcess.DisplayVersion) ? string.Empty : $" v{activeProcess.DisplayVersion}";
|
||||||
|
@ -19,12 +17,9 @@ namespace Ryujinx.UI.Common.Helper
|
||||||
|
|
||||||
string appTitle = $"Ryujinx {applicationVersion} -{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
|
string appTitle = $"Ryujinx {applicationVersion} -{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(pauseString))
|
return !string.IsNullOrEmpty(pauseString)
|
||||||
{
|
? appTitle + $" ({pauseString})"
|
||||||
appTitle += $" ({pauseString})";
|
: appTitle;
|
||||||
}
|
|
||||||
|
|
||||||
return appTitle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using FluentAvalonia.UI.Controls;
|
using FluentAvalonia.UI.Controls;
|
||||||
|
@ -64,21 +62,14 @@ namespace Ryujinx.Ava.UI.Windows
|
||||||
|
|
||||||
private void OpenLocation(object sender, RoutedEventArgs e)
|
private void OpenLocation(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Button button)
|
if (sender is Button { DataContext: TitleUpdateModel model })
|
||||||
{
|
|
||||||
if (button.DataContext is TitleUpdateModel model)
|
|
||||||
{
|
|
||||||
OpenHelper.LocateFile(model.Path);
|
OpenHelper.LocateFile(model.Path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RemoveUpdate(object sender, RoutedEventArgs e)
|
private void RemoveUpdate(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Button button)
|
if (sender is Button { DataContext: TitleUpdateModel model })
|
||||||
{
|
ViewModel.RemoveUpdate(model);
|
||||||
ViewModel.RemoveUpdate((TitleUpdateModel)button.DataContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveAll(object sender, RoutedEventArgs e)
|
private void RemoveAll(object sender, RoutedEventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue