Compare commits

...

2 Commits

Author SHA1 Message Date
TSRBerry
46b7c905f5 [Ryujinx.Input] Address dotnet-format issues (#5384)
* 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 dotnet format CA1816 warnings

* 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

* 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

* Remove redundant code, convert to auto-properties and fix naming rule violations

* Remove bogus change

* Address review feedback
2023-06-28 18:23:00 +02:00
TSRBerry
40f2bd37e3 [Ryujinx.Graphics.OpenGL] Address dotnet-format issues (#5372)
* 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 IDE0060 warnings

* Address or silence dotnet format IDE1006 warnings

* Fix IDE0090 after rebase

* 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

* Format if-blocks correctly

* Another rebase, another dotnet format run

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Add comments to disabled warnings

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

* Start working on disabled warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* 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

* Address review feedback
2023-06-28 18:10:55 +02:00
57 changed files with 542 additions and 540 deletions

View File

@@ -9,12 +9,12 @@ namespace Ryujinx.Graphics.OpenGL
{
[ThreadStatic]
public static bool InBackground;
private Thread _thread;
private readonly Thread _thread;
private bool _running;
private AutoResetEvent _signal;
private Queue<Action> _work;
private ObjectPool<ManualResetEventSlim> _invokePool;
private readonly AutoResetEvent _signal;
private readonly Queue<Action> _work;
private readonly ObjectPool<ManualResetEventSlim> _invokePool;
private readonly IOpenGLContext _backgroundContext;
public BackgroundContextWorker(IOpenGLContext backgroundContext)

View File

@@ -63,10 +63,18 @@ namespace Ryujinx.Graphics.OpenGL
switch (type)
{
case DebugType.DebugTypeError : Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR"); break;
case DebugType.DebugTypePerformance: Logger.Warning?.Print(LogClass.Gpu, $"{severity}: {msg}", "GLPERF"); break;
case DebugType.DebugTypePushGroup : Logger.Info?.Print(LogClass.Gpu, $"{{ ({id}) {severity}: {msg}", "GLINFO"); break;
case DebugType.DebugTypePopGroup : Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO"); break;
case DebugType.DebugTypeError:
Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR");
break;
case DebugType.DebugTypePerformance:
Logger.Warning?.Print(LogClass.Gpu, $"{severity}: {msg}", "GLPERF");
break;
case DebugType.DebugTypePushGroup:
Logger.Info?.Print(LogClass.Gpu, $"{{ ({id}) {severity}: {msg}", "GLINFO");
break;
case DebugType.DebugTypePopGroup:
Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO");
break;
default:
if (source == DebugSource.DebugSourceApplication)
{

View File

@@ -65,16 +65,12 @@ void main()
if (x0 > x1)
{
float temp = s0;
s0 = s1;
s1 = temp;
(s1, s0) = (s0, s1);
}
if (y0 > y1)
{
float temp = t0;
t0 = t1;
t1 = temp;
(t1, t0) = (t0, t1);
}
GL.Uniform1(_uniformSrcX0Location, s0);

View File

@@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
}
}
public FsrScalingFilter(OpenGLRenderer renderer, IPostProcessingEffect filter)
public FsrScalingFilter(OpenGLRenderer renderer)
{
Initialize();

View File

@@ -1,5 +1,4 @@
using OpenTK.Graphics.OpenGL;
using System;
namespace Ryujinx.Graphics.OpenGL.Effects
{

View File

@@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
private int[] _neighbourShaderPrograms;
private TextureStorage _edgeOutputTexture;
private TextureStorage _blendOutputTexture;
private string[] _qualities;
private readonly string[] _qualities;
private int _inputUniform;
private int _outputUniform;
private int _samplerAreaUniform;

View File

@@ -4,10 +4,10 @@ using System;
namespace Ryujinx.Graphics.OpenGL
{
struct FormatTable
readonly struct FormatTable
{
private static FormatInfo[] _table;
private static SizedInternalFormat[] _tableImage;
private static readonly FormatInfo[] _table;
private static readonly SizedInternalFormat[] _tableImage;
static FormatTable()
{
@@ -16,6 +16,7 @@ namespace Ryujinx.Graphics.OpenGL
_table = new FormatInfo[tableSize];
_tableImage = new SizedInternalFormat[tableSize];
#pragma warning disable IDE0055 // Disable formatting
Add(Format.R8Unorm, new FormatInfo(1, true, false, All.R8, PixelFormat.Red, PixelType.UnsignedByte));
Add(Format.R8Snorm, new FormatInfo(1, true, false, All.R8Snorm, PixelFormat.Red, PixelType.Byte));
Add(Format.R8Uint, new FormatInfo(1, false, false, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte));
@@ -200,6 +201,7 @@ namespace Ryujinx.Graphics.OpenGL
Add(Format.R10G10B10A2Unorm, (SizedInternalFormat)All.Rgb10A2);
Add(Format.R10G10B10A2Uint, (SizedInternalFormat)All.Rgb10A2ui);
Add(Format.R11G11B10Float, (SizedInternalFormat)All.R11fG11fB10f);
#pragma warning restore IDE0055
}
private static void Add(Format format, FormatInfo info)

View File

@@ -105,7 +105,7 @@ namespace Ryujinx.Graphics.OpenGL
_colorsCount = colorsCount;
}
private void SetDrawBuffersImpl(int colorsCount)
private static void SetDrawBuffersImpl(int colorsCount)
{
DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount];

View File

@@ -5,30 +5,30 @@ namespace Ryujinx.Graphics.OpenGL
{
static class HwCapabilities
{
private static readonly Lazy<bool> _supportsAlphaToCoverageDitherControl = new Lazy<bool>(() => HasExtension("GL_NV_alpha_to_coverage_dither_control"));
private static readonly Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
private static readonly Lazy<bool> _supportsBlendEquationAdvanced = new Lazy<bool>(() => HasExtension("GL_NV_blend_equation_advanced"));
private static readonly Lazy<bool> _supportsDrawTexture = new Lazy<bool>(() => HasExtension("GL_NV_draw_texture"));
private static readonly Lazy<bool> _supportsFragmentShaderInterlock = new Lazy<bool>(() => HasExtension("GL_ARB_fragment_shader_interlock"));
private static readonly Lazy<bool> _supportsFragmentShaderOrdering = new Lazy<bool>(() => HasExtension("GL_INTEL_fragment_shader_ordering"));
private static readonly Lazy<bool> _supportsGeometryShaderPassthrough = new Lazy<bool>(() => HasExtension("GL_NV_geometry_shader_passthrough"));
private static readonly Lazy<bool> _supportsImageLoadFormatted = new Lazy<bool>(() => HasExtension("GL_EXT_shader_image_load_formatted"));
private static readonly Lazy<bool> _supportsIndirectParameters = new Lazy<bool>(() => HasExtension("GL_ARB_indirect_parameters"));
private static readonly Lazy<bool> _supportsParallelShaderCompile = new Lazy<bool>(() => HasExtension("GL_ARB_parallel_shader_compile"));
private static readonly Lazy<bool> _supportsPolygonOffsetClamp = new Lazy<bool>(() => HasExtension("GL_EXT_polygon_offset_clamp"));
private static readonly Lazy<bool> _supportsQuads = new Lazy<bool>(SupportsQuadsCheck);
private static readonly Lazy<bool> _supportsSeamlessCubemapPerTexture = new Lazy<bool>(() => HasExtension("GL_ARB_seamless_cubemap_per_texture"));
private static readonly Lazy<bool> _supportsShaderBallot = new Lazy<bool>(() => HasExtension("GL_ARB_shader_ballot"));
private static readonly Lazy<bool> _supportsShaderViewportLayerArray = new Lazy<bool>(() => HasExtension("GL_ARB_shader_viewport_layer_array"));
private static readonly Lazy<bool> _supportsViewportArray2 = new Lazy<bool>(() => HasExtension("GL_NV_viewport_array2"));
private static readonly Lazy<bool> _supportsTextureCompressionBptc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_bptc"));
private static readonly Lazy<bool> _supportsTextureCompressionRgtc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_rgtc"));
private static readonly Lazy<bool> _supportsTextureCompressionS3tc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_s3tc"));
private static readonly Lazy<bool> _supportsTextureShadowLod = new Lazy<bool>(() => HasExtension("GL_EXT_texture_shadow_lod"));
private static readonly Lazy<bool> _supportsViewportSwizzle = new Lazy<bool>(() => HasExtension("GL_NV_viewport_swizzle"));
private static readonly Lazy<bool> _supportsAlphaToCoverageDitherControl = new(() => HasExtension("GL_NV_alpha_to_coverage_dither_control"));
private static readonly Lazy<bool> _supportsAstcCompression = new(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
private static readonly Lazy<bool> _supportsBlendEquationAdvanced = new(() => HasExtension("GL_NV_blend_equation_advanced"));
private static readonly Lazy<bool> _supportsDrawTexture = new(() => HasExtension("GL_NV_draw_texture"));
private static readonly Lazy<bool> _supportsFragmentShaderInterlock = new(() => HasExtension("GL_ARB_fragment_shader_interlock"));
private static readonly Lazy<bool> _supportsFragmentShaderOrdering = new(() => HasExtension("GL_INTEL_fragment_shader_ordering"));
private static readonly Lazy<bool> _supportsGeometryShaderPassthrough = new(() => HasExtension("GL_NV_geometry_shader_passthrough"));
private static readonly Lazy<bool> _supportsImageLoadFormatted = new(() => HasExtension("GL_EXT_shader_image_load_formatted"));
private static readonly Lazy<bool> _supportsIndirectParameters = new(() => HasExtension("GL_ARB_indirect_parameters"));
private static readonly Lazy<bool> _supportsParallelShaderCompile = new(() => HasExtension("GL_ARB_parallel_shader_compile"));
private static readonly Lazy<bool> _supportsPolygonOffsetClamp = new(() => HasExtension("GL_EXT_polygon_offset_clamp"));
private static readonly Lazy<bool> _supportsQuads = new(SupportsQuadsCheck);
private static readonly Lazy<bool> _supportsSeamlessCubemapPerTexture = new(() => HasExtension("GL_ARB_seamless_cubemap_per_texture"));
private static readonly Lazy<bool> _supportsShaderBallot = new(() => HasExtension("GL_ARB_shader_ballot"));
private static readonly Lazy<bool> _supportsShaderViewportLayerArray = new(() => HasExtension("GL_ARB_shader_viewport_layer_array"));
private static readonly Lazy<bool> _supportsViewportArray2 = new(() => HasExtension("GL_NV_viewport_array2"));
private static readonly Lazy<bool> _supportsTextureCompressionBptc = new(() => HasExtension("GL_EXT_texture_compression_bptc"));
private static readonly Lazy<bool> _supportsTextureCompressionRgtc = new(() => HasExtension("GL_EXT_texture_compression_rgtc"));
private static readonly Lazy<bool> _supportsTextureCompressionS3tc = new(() => HasExtension("GL_EXT_texture_compression_s3tc"));
private static readonly Lazy<bool> _supportsTextureShadowLod = new(() => HasExtension("GL_EXT_texture_shadow_lod"));
private static readonly Lazy<bool> _supportsViewportSwizzle = new(() => HasExtension("GL_NV_viewport_swizzle"));
private static readonly Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
private static readonly Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
private static readonly Lazy<int> _maximumComputeSharedMemorySize = new(() => GetLimit(All.MaxComputeSharedMemorySize));
private static readonly Lazy<int> _storageBufferOffsetAlignment = new(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
public enum GpuVendor
{
@@ -40,14 +40,13 @@ namespace Ryujinx.Graphics.OpenGL
Nvidia
}
private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor);
private static readonly Lazy<GpuVendor> _gpuVendor = new(GetGpuVendor);
private static bool _isAMD => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.AmdUnix;
private static bool _isIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix;
private static bool IsIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix;
public static GpuVendor Vendor => _gpuVendor.Value;
private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
private static readonly Lazy<float> _maxSupportedAnisotropy = new(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia;
@@ -75,7 +74,7 @@ namespace Ryujinx.Graphics.OpenGL
public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.AmdWindows && _gpuVendor.Value != GpuVendor.IntelWindows;
public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _isIntel;
public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || IsIntel;
public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;

View File

@@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureBuffer : TextureBase, ITexture
{
private OpenGLRenderer _renderer;
private readonly OpenGLRenderer _renderer;
private int _bufferOffset;
private int _bufferSize;
private int _bufferCount;
@@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
var dataSpan = data.AsSpan();
Buffer.SetData(_buffer, _bufferOffset, dataSpan.Slice(0, Math.Min(dataSpan.Length, _bufferSize)));
Buffer.SetData(_buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]);
}
public void SetData(SpanOrArray<byte> data, int layer, int level)

View File

@@ -1,5 +1,4 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -81,9 +80,6 @@ void main()
public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels)
{
TextureCreateInfo srcInfo = src.Info;
TextureCreateInfo dstInfo = dst.Info;
int srcBpp = src.Info.BytesPerPixel;
int dstBpp = dst.Info.BytesPerPixel;
@@ -176,7 +172,7 @@ void main()
return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
}
private int GetShader(
private static int GetShader(
string code,
Dictionary<int, int> programHandles,
int componentSize,

View File

@@ -94,8 +94,8 @@ void main()
}";
private readonly OpenGLRenderer _renderer;
private int[] _msToNonMSProgramHandles;
private int[] _nonMSToMSProgramHandles;
private readonly int[] _msToNonMSProgramHandles;
private readonly int[] _nonMSToMSProgramHandles;
public TextureCopyMS(OpenGLRenderer renderer)
{
@@ -219,7 +219,7 @@ void main()
return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel);
}
private int GetShader(string code, int[] programHandles, int bytesPerPixel)
private static int GetShader(string code, int[] programHandles, int bytesPerPixel)
{
int index = BitOperations.Log2((uint)bytesPerPixel);

View File

@@ -88,9 +88,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
// Swap B <-> R for BGRA formats, as OpenGL has no support for them
// and we need to manually swap the components on read/write on the GPU.
int temp = swizzleRgba[0];
swizzleRgba[0] = swizzleRgba[2];
swizzleRgba[2] = temp;
(swizzleRgba[2], swizzleRgba[0]) = (swizzleRgba[0], swizzleRgba[2]);
}
GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, swizzleRgba);
@@ -186,8 +184,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
// This approach uses blit, which causes a resolution loss since some samples will be lost
// in the process.
Extents2D srcRegion = new Extents2D(0, 0, Width, Height);
Extents2D dstRegion = new Extents2D(0, 0, destinationView.Width, destinationView.Height);
Extents2D srcRegion = new(0, 0, Width, Height);
Extents2D dstRegion = new(0, 0, destinationView.Width, destinationView.Height);
if (destinationView.Target.IsMultisample())
{

View File

@@ -21,13 +21,13 @@ namespace Ryujinx.Graphics.OpenGL
public IWindow Window => _window;
private TextureCopy _textureCopy;
private TextureCopy _backgroundTextureCopy;
private readonly TextureCopy _textureCopy;
private readonly TextureCopy _backgroundTextureCopy;
internal TextureCopy TextureCopy => BackgroundContextWorker.InBackground ? _backgroundTextureCopy : _textureCopy;
internal TextureCopyIncompatible TextureCopyIncompatible { get; }
internal TextureCopyMS TextureCopyMS { get; }
private Sync _sync;
private readonly Sync _sync;
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;

View File

@@ -11,10 +11,10 @@ namespace Ryujinx.Graphics.OpenGL
{
class PersistentBuffers : IDisposable
{
private PersistentBuffer _main = new PersistentBuffer();
private PersistentBuffer _background = new PersistentBuffer();
private readonly PersistentBuffer _main = new();
private readonly PersistentBuffer _background = new();
private Dictionary<BufferHandle, IntPtr> _maps = new Dictionary<BufferHandle, IntPtr>();
private readonly Dictionary<BufferHandle, IntPtr> _maps = new();
public PersistentBuffer Default => BackgroundContextWorker.InBackground ? _background : _main;
@@ -91,7 +91,7 @@ namespace Ryujinx.Graphics.OpenGL
return _dataMap;
}
private void Sync()
private static void Sync()
{
GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit);
@@ -133,7 +133,7 @@ namespace Ryujinx.Graphics.OpenGL
Sync();
return new ReadOnlySpan<byte>(_bufferMap.ToPointer(), size).Slice(offset);
return new ReadOnlySpan<byte>(_bufferMap.ToPointer(), size)[offset..];
}
public unsafe ReadOnlySpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)

View File

@@ -44,11 +44,11 @@ namespace Ryujinx.Graphics.OpenGL
private CounterQueueEvent _activeConditionalRender;
private Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
private Vector4<float>[] _renderScale = new Vector4<float>[73];
private readonly Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
private readonly Vector4<float>[] _renderScale = new Vector4<float>[73];
private int _fragmentScaleCount;
private (TextureBase, Format)[] _images;
private readonly (TextureBase, Format)[] _images;
private TextureBase _unit0Texture;
private Sampler _unit0Sampler;
@@ -260,7 +260,7 @@ namespace Ryujinx.Graphics.OpenGL
PostDraw();
}
private void DrawQuadsImpl(
private static void DrawQuadsImpl(
int vertexCount,
int instanceCount,
int firstVertex,
@@ -285,7 +285,7 @@ namespace Ryujinx.Graphics.OpenGL
quadsCount);
}
private void DrawQuadStripImpl(
private static void DrawQuadStripImpl(
int vertexCount,
int instanceCount,
int firstVertex,
@@ -366,8 +366,12 @@ namespace Ryujinx.Graphics.OpenGL
switch (_elementsType)
{
case DrawElementsType.UnsignedShort: indexElemSize = 2; break;
case DrawElementsType.UnsignedInt: indexElemSize = 4; break;
case DrawElementsType.UnsignedShort:
indexElemSize = 2;
break;
case DrawElementsType.UnsignedInt:
indexElemSize = 4;
break;
}
IntPtr indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize;
@@ -1471,7 +1475,7 @@ namespace Ryujinx.Graphics.OpenGL
GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit);
}
private void SetBuffers(ReadOnlySpan<BufferAssignment> buffers, bool isStorage)
private static void SetBuffers(ReadOnlySpan<BufferAssignment> buffers, bool isStorage)
{
BufferRangeTarget target = isStorage ? BufferRangeTarget.ShaderStorageBuffer : BufferRangeTarget.UniformBuffer;
@@ -1700,12 +1704,10 @@ namespace Ryujinx.Graphics.OpenGL
}
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
{
if (value is CounterQueueEvent)
{
// Compare an event and a constant value.
CounterQueueEvent evt = (CounterQueueEvent)value;
if (value is CounterQueueEvent evt)
{
// Easy host conditional rendering when the check matches what GL can do:
// - Event is of type samples passed.
// - Result is not a combination of multiple queries.

View File

@@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.OpenGL
if (log.Length > MaxShaderLogLength)
{
log = log.Substring(0, MaxShaderLogLength) + "...";
log = log[..MaxShaderLogLength] + "...";
}
Logger.Warning?.Print(LogClass.Gpu, $"Shader linking failed: \n{log}");

View File

@@ -14,9 +14,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public int Query { get; }
private int _buffer;
private IntPtr _bufferMap;
private QueryTarget _type;
private readonly int _buffer;
private readonly IntPtr _bufferMap;
private readonly QueryTarget _type;
public BufferedQuery(QueryTarget type)
{
@@ -64,7 +64,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
}
}
private bool WaitingForValue(long data)
private static bool WaitingForValue(long data)
{
return data == DefaultValue ||
((ulong)data & HighMask) == (unchecked((ulong)DefaultValue) & HighMask);

View File

@@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private readonly Pipeline _pipeline;
private Queue<CounterQueueEvent> _events = new Queue<CounterQueueEvent>();
private readonly Queue<CounterQueueEvent> _events = new();
private CounterQueueEvent _current;
private ulong _accumulatedCounter;
@@ -23,12 +23,12 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private readonly object _lock = new();
private Queue<BufferedQuery> _queryPool;
private AutoResetEvent _queuedEvent = new AutoResetEvent(false);
private AutoResetEvent _wakeSignal = new AutoResetEvent(false);
private AutoResetEvent _eventConsumed = new AutoResetEvent(false);
private readonly Queue<BufferedQuery> _queryPool;
private readonly AutoResetEvent _queuedEvent = new(false);
private readonly AutoResetEvent _wakeSignal = new(false);
private readonly AutoResetEvent _eventConsumed = new(false);
private Thread _consumerThread;
private readonly Thread _consumerThread;
internal CounterQueue(Pipeline pipeline, CounterType type)
{
@@ -148,14 +148,13 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private static QueryTarget GetTarget(CounterType type)
{
switch (type)
return type switch
{
case CounterType.SamplesPassed: return QueryTarget.SamplesPassed;
case CounterType.PrimitivesGenerated: return QueryTarget.PrimitivesGenerated;
case CounterType.TransformFeedbackPrimitivesWritten: return QueryTarget.TransformFeedbackPrimitivesWritten;
}
return QueryTarget.SamplesPassed;
CounterType.SamplesPassed => QueryTarget.SamplesPassed,
CounterType.PrimitivesGenerated => QueryTarget.PrimitivesGenerated,
CounterType.TransformFeedbackPrimitivesWritten => QueryTarget.TransformFeedbackPrimitivesWritten,
_ => QueryTarget.SamplesPassed,
};
}
public void Flush(bool blocking)

View File

@@ -18,8 +18,8 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public ulong DrawIndex { get; }
private CounterQueue _queue;
private BufferedQuery _counter;
private readonly CounterQueue _queue;
private readonly BufferedQuery _counter;
private bool _hostAccessReserved = false;
private int _refCount = 1; // Starts with a reference from the counter queue.

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
{
class Counters : IDisposable
{
private CounterQueue[] _counterQueues;
private readonly CounterQueue[] _counterQueues;
public Counters()
{

View File

@@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL
private const int DisposedLiveFrames = 2;
private readonly object _lock = new();
private readonly Dictionary<TextureCreateInfo, List<DisposedTexture>> _textures = new Dictionary<TextureCreateInfo, List<DisposedTexture>>();
private readonly Dictionary<TextureCreateInfo, List<DisposedTexture>> _textures = new();
/// <summary>
/// Add a texture that is not being used anymore to the resource pool to be used later.
@@ -32,8 +32,7 @@ namespace Ryujinx.Graphics.OpenGL
{
lock (_lock)
{
List<DisposedTexture> list;
if (!_textures.TryGetValue(view.Info, out list))
if (!_textures.TryGetValue(view.Info, out List<DisposedTexture> list))
{
list = new List<DisposedTexture>();
_textures.Add(view.Info, list);
@@ -59,8 +58,7 @@ namespace Ryujinx.Graphics.OpenGL
{
lock (_lock)
{
List<DisposedTexture> list;
if (!_textures.TryGetValue(info, out list))
if (!_textures.TryGetValue(info, out List<DisposedTexture> list))
{
return null;
}

View File

@@ -15,13 +15,13 @@ namespace Ryujinx.Graphics.OpenGL
}
private ulong _firstHandle = 0;
private ClientWaitSyncFlags _syncFlags => HwCapabilities.RequiresSyncFlush ? ClientWaitSyncFlags.None : ClientWaitSyncFlags.SyncFlushCommandsBit;
private static ClientWaitSyncFlags SyncFlags => HwCapabilities.RequiresSyncFlush ? ClientWaitSyncFlags.None : ClientWaitSyncFlags.SyncFlushCommandsBit;
private List<SyncHandle> _handles = new List<SyncHandle>();
private readonly List<SyncHandle> _handles = new();
public void Create(ulong id)
{
SyncHandle handle = new SyncHandle
SyncHandle handle = new()
{
ID = id,
Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None)
@@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.OpenGL
if (handle.ID > lastHandle)
{
WaitSyncStatus syncResult = GL.ClientWaitSync(handle.Handle, _syncFlags, 0);
WaitSyncStatus syncResult = GL.ClientWaitSync(handle.Handle, SyncFlags, 0);
if (syncResult == WaitSyncStatus.AlreadySignaled)
{
@@ -101,7 +101,7 @@ namespace Ryujinx.Graphics.OpenGL
return;
}
WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, _syncFlags, 1000000000);
WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, SyncFlags, 1000000000);
if (syncResult == WaitSyncStatus.TimeoutExpired)
{
@@ -123,9 +123,12 @@ namespace Ryujinx.Graphics.OpenGL
first = _handles.FirstOrDefault();
}
if (first == null) break;
if (first == null)
{
break;
}
WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, _syncFlags, 0);
WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, SyncFlags, 0);
if (syncResult == WaitSyncStatus.AlreadySignaled)
{
@@ -140,7 +143,8 @@ namespace Ryujinx.Graphics.OpenGL
first.Handle = IntPtr.Zero;
}
}
} else
}
else
{
// This sync handle and any following have not been reached yet.
break;

View File

@@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.OpenGL
private uint _vertexBuffersLimited;
private BufferRange _indexBuffer;
private BufferHandle _tempIndexBuffer;
private readonly BufferHandle _tempIndexBuffer;
private BufferHandle _tempVertexBuffer;
private int _tempVertexBufferSize;

View File

@@ -375,7 +375,7 @@ namespace Ryujinx.Graphics.OpenGL
if (_scalingFilter is not FsrScalingFilter)
{
_scalingFilter?.Dispose();
_scalingFilter = new FsrScalingFilter(_renderer, _antiAliasing);
_scalingFilter = new FsrScalingFilter(_renderer);
}
_isLinear = false;
_scalingFilter.Level = _scalingFilterLevel;

View File

@@ -10,15 +10,15 @@ namespace Ryujinx.Input.Assigner
/// </summary>
public class GamepadButtonAssigner : IButtonAssigner
{
private IGamepad _gamepad;
private readonly IGamepad _gamepad;
private GamepadStateSnapshot _currState;
private GamepadStateSnapshot _prevState;
private JoystickButtonDetector _detector;
private readonly JoystickButtonDetector _detector;
private bool _forStick;
private readonly bool _forStick;
public GamepadButtonAssigner(IGamepad gamepad, float triggerThreshold, bool forStick)
{
@@ -116,7 +116,7 @@ namespace Ryujinx.Input.Assigner
private class JoystickButtonDetector
{
private Dictionary<GamepadButtonInputId, InputSummary> _stats;
private readonly Dictionary<GamepadButtonInputId, InputSummary> _stats;
public JoystickButtonDetector()
{
@@ -135,9 +135,8 @@ namespace Ryujinx.Input.Assigner
public void AddInput(GamepadButtonInputId button, float value)
{
InputSummary inputSummary;
if (!_stats.TryGetValue(button, out inputSummary))
if (!_stats.TryGetValue(button, out InputSummary inputSummary))
{
inputSummary = new InputSummary();
_stats.Add(button, inputSummary);
@@ -148,7 +147,7 @@ namespace Ryujinx.Input.Assigner
public override string ToString()
{
StringWriter writer = new StringWriter();
StringWriter writer = new();
foreach (var kvp in _stats)
{

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Input.Assigner
/// </summary>
public class KeyboardKeyAssigner : IButtonAssigner
{
private IKeyboard _keyboard;
private readonly IKeyboard _keyboard;
private KeyboardStateSnapshot _keyboardState;

View File

@@ -52,6 +52,6 @@
SingleLeftTrigger1,
SingleRightTrigger1,
Count
Count,
}
}

View File

@@ -23,6 +23,6 @@ namespace Ryujinx.Input
/// Motion
/// <remarks>Also named sixaxis</remarks>
/// </summary>
Motion
Motion,
}
}

View File

@@ -48,6 +48,7 @@ namespace Ryujinx.Input.HLE
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
}

View File

@@ -8,7 +8,6 @@ using System;
using System.Collections.Concurrent;
using System.Numerics;
using System.Runtime.CompilerServices;
using CemuHookClient = Ryujinx.Input.Motion.CemuHook.Client;
using ConfigControllerType = Ryujinx.Common.Configuration.Hid.ControllerType;
@@ -28,29 +27,28 @@ namespace Ryujinx.Input.HLE
}
}
private static readonly HLEButtonMappingEntry[] _hleButtonMapping = new HLEButtonMappingEntry[]
{
new HLEButtonMappingEntry(GamepadButtonInputId.A, ControllerKeys.A),
new HLEButtonMappingEntry(GamepadButtonInputId.B, ControllerKeys.B),
new HLEButtonMappingEntry(GamepadButtonInputId.X, ControllerKeys.X),
new HLEButtonMappingEntry(GamepadButtonInputId.Y, ControllerKeys.Y),
new HLEButtonMappingEntry(GamepadButtonInputId.LeftStick, ControllerKeys.LStick),
new HLEButtonMappingEntry(GamepadButtonInputId.RightStick, ControllerKeys.RStick),
new HLEButtonMappingEntry(GamepadButtonInputId.LeftShoulder, ControllerKeys.L),
new HLEButtonMappingEntry(GamepadButtonInputId.RightShoulder, ControllerKeys.R),
new HLEButtonMappingEntry(GamepadButtonInputId.LeftTrigger, ControllerKeys.Zl),
new HLEButtonMappingEntry(GamepadButtonInputId.RightTrigger, ControllerKeys.Zr),
new HLEButtonMappingEntry(GamepadButtonInputId.DpadUp, ControllerKeys.DpadUp),
new HLEButtonMappingEntry(GamepadButtonInputId.DpadDown, ControllerKeys.DpadDown),
new HLEButtonMappingEntry(GamepadButtonInputId.DpadLeft, ControllerKeys.DpadLeft),
new HLEButtonMappingEntry(GamepadButtonInputId.DpadRight, ControllerKeys.DpadRight),
new HLEButtonMappingEntry(GamepadButtonInputId.Minus, ControllerKeys.Minus),
new HLEButtonMappingEntry(GamepadButtonInputId.Plus, ControllerKeys.Plus),
private static readonly HLEButtonMappingEntry[] _hleButtonMapping = {
new(GamepadButtonInputId.A, ControllerKeys.A),
new(GamepadButtonInputId.B, ControllerKeys.B),
new(GamepadButtonInputId.X, ControllerKeys.X),
new(GamepadButtonInputId.Y, ControllerKeys.Y),
new(GamepadButtonInputId.LeftStick, ControllerKeys.LStick),
new(GamepadButtonInputId.RightStick, ControllerKeys.RStick),
new(GamepadButtonInputId.LeftShoulder, ControllerKeys.L),
new(GamepadButtonInputId.RightShoulder, ControllerKeys.R),
new(GamepadButtonInputId.LeftTrigger, ControllerKeys.Zl),
new(GamepadButtonInputId.RightTrigger, ControllerKeys.Zr),
new(GamepadButtonInputId.DpadUp, ControllerKeys.DpadUp),
new(GamepadButtonInputId.DpadDown, ControllerKeys.DpadDown),
new(GamepadButtonInputId.DpadLeft, ControllerKeys.DpadLeft),
new(GamepadButtonInputId.DpadRight, ControllerKeys.DpadRight),
new(GamepadButtonInputId.Minus, ControllerKeys.Minus),
new(GamepadButtonInputId.Plus, ControllerKeys.Plus),
new HLEButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, ControllerKeys.SlLeft),
new HLEButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, ControllerKeys.SrLeft),
new HLEButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, ControllerKeys.SlRight),
new HLEButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, ControllerKeys.SrRight),
new(GamepadButtonInputId.SingleLeftTrigger0, ControllerKeys.SlLeft),
new(GamepadButtonInputId.SingleRightTrigger0, ControllerKeys.SrLeft),
new(GamepadButtonInputId.SingleLeftTrigger1, ControllerKeys.SlRight),
new(GamepadButtonInputId.SingleRightTrigger1, ControllerKeys.SrRight),
};
private class HLEKeyboardMappingEntry
@@ -65,150 +63,147 @@ namespace Ryujinx.Input.HLE
}
}
private static readonly HLEKeyboardMappingEntry[] KeyMapping = new HLEKeyboardMappingEntry[]
{
new HLEKeyboardMappingEntry(Key.A, 0x4),
new HLEKeyboardMappingEntry(Key.B, 0x5),
new HLEKeyboardMappingEntry(Key.C, 0x6),
new HLEKeyboardMappingEntry(Key.D, 0x7),
new HLEKeyboardMappingEntry(Key.E, 0x8),
new HLEKeyboardMappingEntry(Key.F, 0x9),
new HLEKeyboardMappingEntry(Key.G, 0xA),
new HLEKeyboardMappingEntry(Key.H, 0xB),
new HLEKeyboardMappingEntry(Key.I, 0xC),
new HLEKeyboardMappingEntry(Key.J, 0xD),
new HLEKeyboardMappingEntry(Key.K, 0xE),
new HLEKeyboardMappingEntry(Key.L, 0xF),
new HLEKeyboardMappingEntry(Key.M, 0x10),
new HLEKeyboardMappingEntry(Key.N, 0x11),
new HLEKeyboardMappingEntry(Key.O, 0x12),
new HLEKeyboardMappingEntry(Key.P, 0x13),
new HLEKeyboardMappingEntry(Key.Q, 0x14),
new HLEKeyboardMappingEntry(Key.R, 0x15),
new HLEKeyboardMappingEntry(Key.S, 0x16),
new HLEKeyboardMappingEntry(Key.T, 0x17),
new HLEKeyboardMappingEntry(Key.U, 0x18),
new HLEKeyboardMappingEntry(Key.V, 0x19),
new HLEKeyboardMappingEntry(Key.W, 0x1A),
new HLEKeyboardMappingEntry(Key.X, 0x1B),
new HLEKeyboardMappingEntry(Key.Y, 0x1C),
new HLEKeyboardMappingEntry(Key.Z, 0x1D),
private static readonly HLEKeyboardMappingEntry[] _keyMapping = {
new(Key.A, 0x4),
new(Key.B, 0x5),
new(Key.C, 0x6),
new(Key.D, 0x7),
new(Key.E, 0x8),
new(Key.F, 0x9),
new(Key.G, 0xA),
new(Key.H, 0xB),
new(Key.I, 0xC),
new(Key.J, 0xD),
new(Key.K, 0xE),
new(Key.L, 0xF),
new(Key.M, 0x10),
new(Key.N, 0x11),
new(Key.O, 0x12),
new(Key.P, 0x13),
new(Key.Q, 0x14),
new(Key.R, 0x15),
new(Key.S, 0x16),
new(Key.T, 0x17),
new(Key.U, 0x18),
new(Key.V, 0x19),
new(Key.W, 0x1A),
new(Key.X, 0x1B),
new(Key.Y, 0x1C),
new(Key.Z, 0x1D),
new HLEKeyboardMappingEntry(Key.Number1, 0x1E),
new HLEKeyboardMappingEntry(Key.Number2, 0x1F),
new HLEKeyboardMappingEntry(Key.Number3, 0x20),
new HLEKeyboardMappingEntry(Key.Number4, 0x21),
new HLEKeyboardMappingEntry(Key.Number5, 0x22),
new HLEKeyboardMappingEntry(Key.Number6, 0x23),
new HLEKeyboardMappingEntry(Key.Number7, 0x24),
new HLEKeyboardMappingEntry(Key.Number8, 0x25),
new HLEKeyboardMappingEntry(Key.Number9, 0x26),
new HLEKeyboardMappingEntry(Key.Number0, 0x27),
new(Key.Number1, 0x1E),
new(Key.Number2, 0x1F),
new(Key.Number3, 0x20),
new(Key.Number4, 0x21),
new(Key.Number5, 0x22),
new(Key.Number6, 0x23),
new(Key.Number7, 0x24),
new(Key.Number8, 0x25),
new(Key.Number9, 0x26),
new(Key.Number0, 0x27),
new HLEKeyboardMappingEntry(Key.Enter, 0x28),
new HLEKeyboardMappingEntry(Key.Escape, 0x29),
new HLEKeyboardMappingEntry(Key.BackSpace, 0x2A),
new HLEKeyboardMappingEntry(Key.Tab, 0x2B),
new HLEKeyboardMappingEntry(Key.Space, 0x2C),
new HLEKeyboardMappingEntry(Key.Minus, 0x2D),
new HLEKeyboardMappingEntry(Key.Plus, 0x2E),
new HLEKeyboardMappingEntry(Key.BracketLeft, 0x2F),
new HLEKeyboardMappingEntry(Key.BracketRight, 0x30),
new HLEKeyboardMappingEntry(Key.BackSlash, 0x31),
new HLEKeyboardMappingEntry(Key.Tilde, 0x32),
new HLEKeyboardMappingEntry(Key.Semicolon, 0x33),
new HLEKeyboardMappingEntry(Key.Quote, 0x34),
new HLEKeyboardMappingEntry(Key.Grave, 0x35),
new HLEKeyboardMappingEntry(Key.Comma, 0x36),
new HLEKeyboardMappingEntry(Key.Period, 0x37),
new HLEKeyboardMappingEntry(Key.Slash, 0x38),
new HLEKeyboardMappingEntry(Key.CapsLock, 0x39),
new(Key.Enter, 0x28),
new(Key.Escape, 0x29),
new(Key.BackSpace, 0x2A),
new(Key.Tab, 0x2B),
new(Key.Space, 0x2C),
new(Key.Minus, 0x2D),
new(Key.Plus, 0x2E),
new(Key.BracketLeft, 0x2F),
new(Key.BracketRight, 0x30),
new(Key.BackSlash, 0x31),
new(Key.Tilde, 0x32),
new(Key.Semicolon, 0x33),
new(Key.Quote, 0x34),
new(Key.Grave, 0x35),
new(Key.Comma, 0x36),
new(Key.Period, 0x37),
new(Key.Slash, 0x38),
new(Key.CapsLock, 0x39),
new HLEKeyboardMappingEntry(Key.F1, 0x3a),
new HLEKeyboardMappingEntry(Key.F2, 0x3b),
new HLEKeyboardMappingEntry(Key.F3, 0x3c),
new HLEKeyboardMappingEntry(Key.F4, 0x3d),
new HLEKeyboardMappingEntry(Key.F5, 0x3e),
new HLEKeyboardMappingEntry(Key.F6, 0x3f),
new HLEKeyboardMappingEntry(Key.F7, 0x40),
new HLEKeyboardMappingEntry(Key.F8, 0x41),
new HLEKeyboardMappingEntry(Key.F9, 0x42),
new HLEKeyboardMappingEntry(Key.F10, 0x43),
new HLEKeyboardMappingEntry(Key.F11, 0x44),
new HLEKeyboardMappingEntry(Key.F12, 0x45),
new(Key.F1, 0x3a),
new(Key.F2, 0x3b),
new(Key.F3, 0x3c),
new(Key.F4, 0x3d),
new(Key.F5, 0x3e),
new(Key.F6, 0x3f),
new(Key.F7, 0x40),
new(Key.F8, 0x41),
new(Key.F9, 0x42),
new(Key.F10, 0x43),
new(Key.F11, 0x44),
new(Key.F12, 0x45),
new HLEKeyboardMappingEntry(Key.PrintScreen, 0x46),
new HLEKeyboardMappingEntry(Key.ScrollLock, 0x47),
new HLEKeyboardMappingEntry(Key.Pause, 0x48),
new HLEKeyboardMappingEntry(Key.Insert, 0x49),
new HLEKeyboardMappingEntry(Key.Home, 0x4A),
new HLEKeyboardMappingEntry(Key.PageUp, 0x4B),
new HLEKeyboardMappingEntry(Key.Delete, 0x4C),
new HLEKeyboardMappingEntry(Key.End, 0x4D),
new HLEKeyboardMappingEntry(Key.PageDown, 0x4E),
new HLEKeyboardMappingEntry(Key.Right, 0x4F),
new HLEKeyboardMappingEntry(Key.Left, 0x50),
new HLEKeyboardMappingEntry(Key.Down, 0x51),
new HLEKeyboardMappingEntry(Key.Up, 0x52),
new(Key.PrintScreen, 0x46),
new(Key.ScrollLock, 0x47),
new(Key.Pause, 0x48),
new(Key.Insert, 0x49),
new(Key.Home, 0x4A),
new(Key.PageUp, 0x4B),
new(Key.Delete, 0x4C),
new(Key.End, 0x4D),
new(Key.PageDown, 0x4E),
new(Key.Right, 0x4F),
new(Key.Left, 0x50),
new(Key.Down, 0x51),
new(Key.Up, 0x52),
new HLEKeyboardMappingEntry(Key.NumLock, 0x53),
new HLEKeyboardMappingEntry(Key.KeypadDivide, 0x54),
new HLEKeyboardMappingEntry(Key.KeypadMultiply, 0x55),
new HLEKeyboardMappingEntry(Key.KeypadSubtract, 0x56),
new HLEKeyboardMappingEntry(Key.KeypadAdd, 0x57),
new HLEKeyboardMappingEntry(Key.KeypadEnter, 0x58),
new HLEKeyboardMappingEntry(Key.Keypad1, 0x59),
new HLEKeyboardMappingEntry(Key.Keypad2, 0x5A),
new HLEKeyboardMappingEntry(Key.Keypad3, 0x5B),
new HLEKeyboardMappingEntry(Key.Keypad4, 0x5C),
new HLEKeyboardMappingEntry(Key.Keypad5, 0x5D),
new HLEKeyboardMappingEntry(Key.Keypad6, 0x5E),
new HLEKeyboardMappingEntry(Key.Keypad7, 0x5F),
new HLEKeyboardMappingEntry(Key.Keypad8, 0x60),
new HLEKeyboardMappingEntry(Key.Keypad9, 0x61),
new HLEKeyboardMappingEntry(Key.Keypad0, 0x62),
new HLEKeyboardMappingEntry(Key.KeypadDecimal, 0x63),
new(Key.NumLock, 0x53),
new(Key.KeypadDivide, 0x54),
new(Key.KeypadMultiply, 0x55),
new(Key.KeypadSubtract, 0x56),
new(Key.KeypadAdd, 0x57),
new(Key.KeypadEnter, 0x58),
new(Key.Keypad1, 0x59),
new(Key.Keypad2, 0x5A),
new(Key.Keypad3, 0x5B),
new(Key.Keypad4, 0x5C),
new(Key.Keypad5, 0x5D),
new(Key.Keypad6, 0x5E),
new(Key.Keypad7, 0x5F),
new(Key.Keypad8, 0x60),
new(Key.Keypad9, 0x61),
new(Key.Keypad0, 0x62),
new(Key.KeypadDecimal, 0x63),
new HLEKeyboardMappingEntry(Key.F13, 0x68),
new HLEKeyboardMappingEntry(Key.F14, 0x69),
new HLEKeyboardMappingEntry(Key.F15, 0x6A),
new HLEKeyboardMappingEntry(Key.F16, 0x6B),
new HLEKeyboardMappingEntry(Key.F17, 0x6C),
new HLEKeyboardMappingEntry(Key.F18, 0x6D),
new HLEKeyboardMappingEntry(Key.F19, 0x6E),
new HLEKeyboardMappingEntry(Key.F20, 0x6F),
new HLEKeyboardMappingEntry(Key.F21, 0x70),
new HLEKeyboardMappingEntry(Key.F22, 0x71),
new HLEKeyboardMappingEntry(Key.F23, 0x72),
new HLEKeyboardMappingEntry(Key.F24, 0x73),
new(Key.F13, 0x68),
new(Key.F14, 0x69),
new(Key.F15, 0x6A),
new(Key.F16, 0x6B),
new(Key.F17, 0x6C),
new(Key.F18, 0x6D),
new(Key.F19, 0x6E),
new(Key.F20, 0x6F),
new(Key.F21, 0x70),
new(Key.F22, 0x71),
new(Key.F23, 0x72),
new(Key.F24, 0x73),
new HLEKeyboardMappingEntry(Key.ControlLeft, 0xE0),
new HLEKeyboardMappingEntry(Key.ShiftLeft, 0xE1),
new HLEKeyboardMappingEntry(Key.AltLeft, 0xE2),
new HLEKeyboardMappingEntry(Key.WinLeft, 0xE3),
new HLEKeyboardMappingEntry(Key.ControlRight, 0xE4),
new HLEKeyboardMappingEntry(Key.ShiftRight, 0xE5),
new HLEKeyboardMappingEntry(Key.AltRight, 0xE6),
new HLEKeyboardMappingEntry(Key.WinRight, 0xE7),
new(Key.ControlLeft, 0xE0),
new(Key.ShiftLeft, 0xE1),
new(Key.AltLeft, 0xE2),
new(Key.WinLeft, 0xE3),
new(Key.ControlRight, 0xE4),
new(Key.ShiftRight, 0xE5),
new(Key.AltRight, 0xE6),
new(Key.WinRight, 0xE7),
};
private static readonly HLEKeyboardMappingEntry[] KeyModifierMapping = new HLEKeyboardMappingEntry[]
{
new HLEKeyboardMappingEntry(Key.ControlLeft, 0),
new HLEKeyboardMappingEntry(Key.ShiftLeft, 1),
new HLEKeyboardMappingEntry(Key.AltLeft, 2),
new HLEKeyboardMappingEntry(Key.WinLeft, 3),
new HLEKeyboardMappingEntry(Key.ControlRight, 4),
new HLEKeyboardMappingEntry(Key.ShiftRight, 5),
new HLEKeyboardMappingEntry(Key.AltRight, 6),
new HLEKeyboardMappingEntry(Key.WinRight, 7),
new HLEKeyboardMappingEntry(Key.CapsLock, 8),
new HLEKeyboardMappingEntry(Key.ScrollLock, 9),
new HLEKeyboardMappingEntry(Key.NumLock, 10),
private static readonly HLEKeyboardMappingEntry[] _keyModifierMapping = {
new(Key.ControlLeft, 0),
new(Key.ShiftLeft, 1),
new(Key.AltLeft, 2),
new(Key.WinLeft, 3),
new(Key.ControlRight, 4),
new(Key.ShiftRight, 5),
new(Key.AltRight, 6),
new(Key.WinRight, 7),
new(Key.CapsLock, 8),
new(Key.ScrollLock, 9),
new(Key.NumLock, 10),
};
private bool _isValid;
private string _id;
private MotionInput _leftMotionInput;
private MotionInput _rightMotionInput;
@@ -219,14 +214,14 @@ namespace Ryujinx.Input.HLE
public IGamepadDriver GamepadDriver { get; private set; }
public GamepadStateSnapshot State { get; private set; }
public string Id => _id;
public string Id { get; private set; }
private CemuHookClient _cemuHookClient;
private readonly CemuHookClient _cemuHookClient;
public NpadController(CemuHookClient cemuHookClient)
{
State = default;
_id = null;
Id = null;
_isValid = false;
_cemuHookClient = cemuHookClient;
}
@@ -237,8 +232,8 @@ namespace Ryujinx.Input.HLE
_gamepad?.Dispose();
_id = config.Id;
_gamepad = GamepadDriver.GetGamepad(_id);
Id = config.Id;
_gamepad = GamepadDriver.GetGamepad(Id);
_isValid = _gamepad != null;
UpdateUserConfiguration(config);
@@ -347,7 +342,7 @@ namespace Ryujinx.Input.HLE
public GamepadInput GetHLEInputState()
{
GamepadInput state = new GamepadInput();
GamepadInput state = new();
// First update all buttons
foreach (HLEButtonMappingEntry entry in _hleButtonMapping)
@@ -366,13 +361,13 @@ namespace Ryujinx.Input.HLE
state.LStick = new JoystickPosition
{
Dx = ClampAxis(leftAxisX),
Dy = ClampAxis(leftAxisY)
Dy = ClampAxis(leftAxisY),
};
state.RStick = new JoystickPosition
{
Dx = ClampAxis(rightAxisX),
Dy = ClampAxis(rightAxisY)
Dy = ClampAxis(rightAxisY),
};
}
else if (_config is StandardControllerInputConfig controllerConfig)
@@ -394,13 +389,13 @@ namespace Ryujinx.Input.HLE
if (magnitudeClamped <= deadzone)
{
return new JoystickPosition() {Dx = 0, Dy = 0};
return new JoystickPosition { Dx = 0, Dy = 0 };
}
return new JoystickPosition()
return new JoystickPosition
{
Dx = ClampAxis((x / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone))),
Dy = ClampAxis((y / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone)))
Dy = ClampAxis((y / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone))),
};
}
@@ -428,7 +423,7 @@ namespace Ryujinx.Input.HLE
return new JoystickPosition
{
Dx = (int)point.X,
Dy = (int)point.Y
Dy = (int)point.Y,
};
}
@@ -476,12 +471,12 @@ namespace Ryujinx.Input.HLE
rotation = new Vector3();
}
return new SixAxisInput()
return new SixAxisInput
{
Accelerometer = accelerometer,
Gyroscope = gyroscope,
Rotation = rotation,
Orientation = orientationForHLE
Orientation = orientationForHLE,
};
}
@@ -502,20 +497,20 @@ namespace Ryujinx.Input.HLE
{
KeyboardStateSnapshot keyboardState = keyboard.GetKeyboardStateSnapshot();
KeyboardInput hidKeyboard = new KeyboardInput
KeyboardInput hidKeyboard = new()
{
Modifier = 0,
Keys = new ulong[0x4]
Keys = new ulong[0x4],
};
foreach (HLEKeyboardMappingEntry entry in KeyMapping)
foreach (HLEKeyboardMappingEntry entry in _keyMapping)
{
ulong value = keyboardState.IsPressed(entry.TargetKey) ? 1UL : 0UL;
hidKeyboard.Keys[entry.Target / 0x40] |= (value << (entry.Target % 0x40));
}
foreach (HLEKeyboardMappingEntry entry in KeyModifierMapping)
foreach (HLEKeyboardMappingEntry entry in _keyModifierMapping)
{
int value = keyboardState.IsPressed(entry.TargetKey) ? 1 : 0;
@@ -539,6 +534,7 @@ namespace Ryujinx.Input.HLE
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

View File

@@ -7,13 +7,15 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using CemuHookClient = Ryujinx.Input.Motion.CemuHook.Client;
using ControllerType = Ryujinx.Common.Configuration.Hid.ControllerType;
using PlayerIndex = Ryujinx.HLE.HOS.Services.Hid.PlayerIndex;
using Switch = Ryujinx.HLE.Switch;
namespace Ryujinx.Input.HLE
{
public class NpadManager : IDisposable
{
private CemuHookClient _cemuHookClient;
private readonly CemuHookClient _cemuHookClient;
private readonly object _lock = new();
@@ -21,7 +23,7 @@ namespace Ryujinx.Input.HLE
private const int MaxControllers = 9;
private NpadController[] _controllers;
private readonly NpadController[] _controllers;
private readonly IGamepadDriver _keyboardDriver;
private readonly IGamepadDriver _gamepadDriver;
@@ -51,7 +53,7 @@ namespace Ryujinx.Input.HLE
{
lock (_lock)
{
List<InputConfig> validInputs = new List<InputConfig>();
List<InputConfig> validInputs = new();
foreach (var inputConfigEntry in _inputConfig)
{
if (_controllers[(int)inputConfigEntry.PlayerIndex] != null)
@@ -96,11 +98,9 @@ namespace Ryujinx.Input.HLE
{
return controller.UpdateDriverConfiguration(targetDriver, config);
}
else
{
return controller.GamepadDriver != null;
}
}
public void ReloadConfiguration(List<InputConfig> inputConfig, bool enableKeyboard, bool enableMouse)
{
@@ -112,11 +112,11 @@ namespace Ryujinx.Input.HLE
_controllers[i] = null;
}
List<InputConfig> validInputs = new List<InputConfig>();
List<InputConfig> validInputs = new();
foreach (InputConfig inputConfigEntry in inputConfig)
{
NpadController controller = new NpadController(_cemuHookClient);
NpadController controller = new(_cemuHookClient);
bool isValid = DriverConfigurationUpdate(ref controller, inputConfigEntry);
@@ -167,8 +167,8 @@ namespace Ryujinx.Input.HLE
{
lock (_lock)
{
List<GamepadInput> hleInputStates = new List<GamepadInput>();
List<SixAxisInput> hleMotionStates = new List<SixAxisInput>(NpadDevices.MaxControllers);
List<GamepadInput> hleInputStates = new();
List<SixAxisInput> hleMotionStates = new(NpadDevices.MaxControllers);
KeyboardInput? hleKeyboardInput = null;
@@ -178,7 +178,7 @@ namespace Ryujinx.Input.HLE
(SixAxisInput, SixAxisInput) motionState = default;
NpadController controller = _controllers[(int)inputConfig.PlayerIndex];
Ryujinx.HLE.HOS.Services.Hid.PlayerIndex playerIndex = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex;
PlayerIndex playerIndex = (PlayerIndex)inputConfig.PlayerIndex;
bool isJoyconPair = false;
@@ -195,7 +195,7 @@ namespace Ryujinx.Input.HLE
inputState.Buttons |= _device.Hid.UpdateStickButtons(inputState.LStick, inputState.RStick);
isJoyconPair = inputConfig.ControllerType == Common.Configuration.Hid.ControllerType.JoyconPair;
isJoyconPair = inputConfig.ControllerType == ControllerType.JoyconPair;
var altMotionState = isJoyconPair ? controller.GetHLEMotionState(true) : default;
@@ -284,7 +284,7 @@ namespace Ryujinx.Input.HLE
{
lock (_lock)
{
return _inputConfig.Find(x => x.PlayerIndex == (Ryujinx.Common.Configuration.Hid.PlayerIndex)index);
return _inputConfig.Find(x => x.PlayerIndex == (Common.Configuration.Hid.PlayerIndex)index);
}
}
@@ -314,6 +314,7 @@ namespace Ryujinx.Input.HLE
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
}

View File

@@ -31,7 +31,7 @@ namespace Ryujinx.Input.HLE
MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse);
var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);
TouchPoint currentPoint = new TouchPoint
TouchPoint currentPoint = new()
{
Attribute = TouchAttribute.End,
@@ -41,7 +41,7 @@ namespace Ryujinx.Input.HLE
// Placeholder values till more data is acquired
DiameterX = 10,
DiameterY = 10,
Angle = 90
Angle = 90,
};
_device.Hid.Touchscreen.Update(currentPoint);
@@ -71,7 +71,7 @@ namespace Ryujinx.Input.HLE
attribute = TouchAttribute.End;
}
TouchPoint currentPoint = new TouchPoint
TouchPoint currentPoint = new()
{
Attribute = attribute,
@@ -81,7 +81,7 @@ namespace Ryujinx.Input.HLE
// Placeholder values till more data is acquired
DiameterX = 10,
DiameterY = 10,
Angle = 90
Angle = 90,
};
_device.Hid.Touchscreen.Update(currentPoint);
@@ -94,6 +94,9 @@ namespace Ryujinx.Input.HLE
return false;
}
public void Dispose() { }
public void Dispose()
{
GC.SuppressFinalize(this);
}
}
}

View File

@@ -8,7 +8,9 @@ namespace Ryujinx.Input
/// </summary>
public interface IMouse : IGamepad
{
#pragma warning disable IDE0051 // Remove unused private member
private const int SwitchPanelWidth = 1280;
#pragma warning restore IDE0051
private const int SwitchPanelHeight = 720;
/// <summary>

View File

@@ -137,6 +137,6 @@
BackSlash,
Unbound,
Count
Count,
}
}

View File

@@ -7,7 +7,7 @@ namespace Ryujinx.Input
/// </summary>
public class KeyboardStateSnapshot
{
private bool[] _keysState;
private readonly bool[] _keysState;
/// <summary>
/// Create a new <see cref="KeyboardStateSnapshot"/>.

View File

@@ -30,7 +30,7 @@ namespace Ryujinx.Input.Motion.CemuHook
private readonly bool[] _clientErrorStatus = new bool[Enum.GetValues<PlayerIndex>().Length];
private readonly long[] _clientRetryTimer = new long[Enum.GetValues<PlayerIndex>().Length];
private NpadManager _npadManager;
private readonly NpadManager _npadManager;
public Client(NpadManager npadManager)
{
@@ -84,7 +84,7 @@ namespace Ryujinx.Input.Motion.CemuHook
try
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(host), port);
IPEndPoint endPoint = new(IPAddress.Parse(host), port);
client = new UdpClient(host, port);
@@ -141,9 +141,9 @@ namespace Ryujinx.Input.Motion.CemuHook
{
lock (_motionData)
{
if (_motionData.ContainsKey(player))
if (_motionData.TryGetValue(player, out Dictionary<int, MotionInput> value))
{
if (_motionData[player].TryGetValue(slot, out input))
if (value.TryGetValue(slot, out input))
{
return true;
}
@@ -164,26 +164,26 @@ namespace Ryujinx.Input.Motion.CemuHook
private void Send(byte[] data, int clientId)
{
if (_clients.TryGetValue(clientId, out UdpClient _client))
if (_clients.TryGetValue(clientId, out UdpClient client))
{
if (_client != null && _client.Client != null && _client.Client.Connected)
if (client != null && client.Client != null && client.Client.Connected)
{
try
{
_client?.Send(data, data.Length);
client?.Send(data, data.Length);
}
catch (SocketException socketException)
{
if (!_clientErrorStatus[clientId])
{
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to send data request to motion source at {_client.Client.RemoteEndPoint}. Error: {socketException.ErrorCode}");
Logger.Warning?.PrintMsg(LogClass.Hid, $"Unable to send data request to motion source at {client.Client.RemoteEndPoint}. Error: {socketException.ErrorCode}");
}
_clientErrorStatus[clientId] = true;
RemoveClient(clientId);
_client?.Dispose();
client?.Dispose();
SetRetryTimer(clientId);
}
@@ -193,7 +193,7 @@ namespace Ryujinx.Input.Motion.CemuHook
RemoveClient(clientId);
_client?.Dispose();
client?.Dispose();
SetRetryTimer(clientId);
}
@@ -203,13 +203,13 @@ namespace Ryujinx.Input.Motion.CemuHook
private byte[] Receive(int clientId, int timeout = 0)
{
if (_hosts.TryGetValue(clientId, out IPEndPoint endPoint) && _clients.TryGetValue(clientId, out UdpClient _client))
if (_hosts.TryGetValue(clientId, out IPEndPoint endPoint) && _clients.TryGetValue(clientId, out UdpClient client))
{
if (_client != null && _client.Client != null && _client.Client.Connected)
if (client != null && client.Client != null && client.Client.Connected)
{
_client.Client.ReceiveTimeout = timeout;
client.Client.ReceiveTimeout = timeout;
var result = _client?.Receive(ref endPoint);
var result = client?.Receive(ref endPoint);
if (result.Length > 0)
{
@@ -242,9 +242,9 @@ namespace Ryujinx.Input.Motion.CemuHook
public void ReceiveLoop(int clientId)
{
if (_hosts.TryGetValue(clientId, out IPEndPoint endPoint) && _clients.TryGetValue(clientId, out UdpClient _client))
if (_hosts.TryGetValue(clientId, out IPEndPoint endPoint) && _clients.TryGetValue(clientId, out UdpClient client))
{
if (_client != null && _client.Client != null && _client.Client.Connected)
if (client != null && client.Client != null && client.Client.Connected)
{
try
{
@@ -271,7 +271,7 @@ namespace Ryujinx.Input.Motion.CemuHook
RemoveClient(clientId);
_client?.Dispose();
client?.Dispose();
SetRetryTimer(clientId);
}
@@ -281,7 +281,7 @@ namespace Ryujinx.Input.Motion.CemuHook
RemoveClient(clientId);
_client?.Dispose();
client?.Dispose();
SetRetryTimer(clientId);
}
@@ -297,8 +297,8 @@ namespace Ryujinx.Input.Motion.CemuHook
data = data.AsSpan()[16..].ToArray();
using MemoryStream stream = new MemoryStream(data);
using BinaryReader reader = new BinaryReader(stream);
using MemoryStream stream = new(data);
using BinaryReader reader = new(stream);
switch (type)
{
@@ -310,18 +310,18 @@ namespace Ryujinx.Input.Motion.CemuHook
case MessageType.Data:
ControllerDataResponse inputData = reader.ReadStruct<ControllerDataResponse>();
Vector3 accelerometer = new Vector3()
Vector3 accelerometer = new()
{
X = -inputData.AccelerometerX,
Y = inputData.AccelerometerZ,
Z = -inputData.AccelerometerY
Z = -inputData.AccelerometerY,
};
Vector3 gyroscrope = new Vector3()
Vector3 gyroscrope = new()
{
X = inputData.GyroscopePitch,
Y = inputData.GyroscopeRoll,
Z = -inputData.GyroscopeYaw
Z = -inputData.GyroscopeYaw,
};
ulong timestamp = inputData.MotionTimestamp;
@@ -346,7 +346,7 @@ namespace Ryujinx.Input.Motion.CemuHook
}
else
{
MotionInput input = new MotionInput();
MotionInput input = new();
input.Update(accelerometer, gyroscrope, timestamp, cemuHookConfig.Sensitivity, (float)cemuHookConfig.GyroDeadzone);
@@ -355,11 +355,11 @@ namespace Ryujinx.Input.Motion.CemuHook
}
else
{
MotionInput input = new MotionInput();
MotionInput input = new();
input.Update(accelerometer, gyroscrope, timestamp, cemuHookConfig.Sensitivity, (float)cemuHookConfig.GyroDeadzone);
_motionData.Add(clientId, new Dictionary<int, MotionInput>() { { slot, input } });
_motionData.Add(clientId, new Dictionary<int, MotionInput> { { slot, input } });
}
}
else
@@ -380,15 +380,15 @@ namespace Ryujinx.Input.Motion.CemuHook
Header header = GenerateHeader(clientId);
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
using (BinaryWriter writer = new BinaryWriter(stream))
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
using BinaryWriter writer = new(stream);
writer.WriteStruct(header);
ControllerInfoRequest request = new ControllerInfoRequest()
ControllerInfoRequest request = new()
{
Type = MessageType.Info,
PortsCount = 4
PortsCount = 4,
};
request.PortIndices[0] = (byte)slot;
@@ -409,9 +409,8 @@ namespace Ryujinx.Input.Motion.CemuHook
Send(data, clientId);
}
}
public unsafe void RequestData(int clientId, int slot)
public void RequestData(int clientId, int slot)
{
if (!_active)
{
@@ -420,16 +419,16 @@ namespace Ryujinx.Input.Motion.CemuHook
Header header = GenerateHeader(clientId);
using (MemoryStream stream = MemoryStreamManager.Shared.GetStream())
using (BinaryWriter writer = new BinaryWriter(stream))
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
using BinaryWriter writer = new(stream);
writer.WriteStruct(header);
ControllerDataRequest request = new ControllerDataRequest()
ControllerDataRequest request = new()
{
Type = MessageType.Data,
Slot = (byte)slot,
SubscriberType = SubscriberType.Slot
SubscriberType = SubscriberType.Slot,
};
writer.WriteStruct(request);
@@ -448,16 +447,15 @@ namespace Ryujinx.Input.Motion.CemuHook
Send(data, clientId);
}
}
private Header GenerateHeader(int clientId)
private static Header GenerateHeader(int clientId)
{
Header header = new Header()
Header header = new()
{
Id = (uint)clientId,
MagicString = Magic,
Version = Version,
Length = 0
Length = 0,
};
return header;
@@ -465,6 +463,7 @@ namespace Ryujinx.Input.Motion.CemuHook
public void Dispose()
{
GC.SuppressFinalize(this);
_active = false;
CloseClients();

View File

@@ -42,6 +42,6 @@ namespace Ryujinx.Input.Motion.CemuHook.Protocol
{
All,
Slot,
Mac
Mac,
}
}

View File

@@ -7,7 +7,7 @@ namespace Ryujinx.Input.Motion.CemuHook.Protocol
public struct ControllerInfoResponse
{
public SharedResponse Shared;
private byte _zero;
private readonly byte _zero;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]

View File

@@ -4,6 +4,6 @@
{
Protocol = 0x100000,
Info,
Data
Data,
}
}

View File

@@ -20,21 +20,21 @@ namespace Ryujinx.Input.Motion.CemuHook.Protocol
{
Disconnected,
Reserved,
Connected
Connected,
}
public enum DeviceModelType : byte
{
None,
PartialGyro,
FullGyro
FullGyro,
}
public enum ConnectionType : byte
{
None,
USB,
Bluetooth
Bluetooth,
}
public enum BatteryStatus : byte
@@ -46,6 +46,6 @@ namespace Ryujinx.Input.Motion.CemuHook.Protocol
High,
Full,
Charging,
Charged
Charged,
}
}

View File

@@ -106,19 +106,19 @@ namespace Ryujinx.Input.Motion
float q1 = Quaternion.W;
// Estimated direction of gravity.
Vector3 gravity = new Vector3()
Vector3 gravity = new()
{
X = 2f * (q2 * q4 - q1 * q3),
Y = 2f * (q1 * q2 + q3 * q4),
Z = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4
Z = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4,
};
// Error is cross product between estimated direction and measured direction of gravity.
Vector3 error = new Vector3()
Vector3 error = new()
{
X = accel.Y * gravity.Z - accel.Z * gravity.Y,
Y = accel.Z * gravity.X - accel.X * gravity.Z,
Z = accel.X * gravity.Y - accel.Y * gravity.X
Z = accel.X * gravity.Y - accel.Y * gravity.X,
};
if (Ki > 0f)
@@ -134,7 +134,7 @@ namespace Ryujinx.Input.Motion
gyro += (Kp * error) + (Ki * _intergralError);
// Integrate rate of change of quaternion.
Vector3 delta = new Vector3(q2, q3, q4);
Vector3 delta = new(q2, q3, q4);
q1 += (-q2 * gyro.X - q3 * gyro.Y - q4 * gyro.Z) * (SampleRateCoefficient * SamplePeriod);
q2 += (q1 * gyro.X + delta.Y * gyro.Z - delta.Z * gyro.Y) * (SampleRateCoefficient * SamplePeriod);
@@ -142,7 +142,7 @@ namespace Ryujinx.Input.Motion
q4 += (q1 * gyro.Z + delta.X * gyro.Y - delta.Y * gyro.X) * (SampleRateCoefficient * SamplePeriod);
// Normalise quaternion.
Quaternion quaternion = new Quaternion(q2, q3, q4, q1);
Quaternion quaternion = new(q2, q3, q4, q1);
norm = 1f / quaternion.Length();

View File

@@ -20,6 +20,6 @@
/// Gyroscope.
/// </summary>
/// <remarks>Values are in degrees</remarks>
Gyroscope
Gyroscope,
}
}

View File

@@ -11,6 +11,6 @@ namespace Ryujinx.Input
Button7,
Button8,
Button9,
Count
Count,
}
}

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.Input
/// </summary>
public class MouseStateSnapshot
{
private bool[] _buttonState;
private readonly bool[] _buttonState;
/// <summary>
/// The position of the mouse cursor

View File

@@ -9,6 +9,6 @@
Left,
Right,
Count
Count,
}
}