Files
Kenji-NX/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs
T
LotP 171624e7f0 Memory Changes part 2
* Slightly refactors RangeLists from the last Memory Changes MR, which fixes issue 61.

* Convert as many const size array iterators to span iterators as possible. When iterating over a const size array, every iteration created a Span, now only the first iteration does in most places.

* Now using object pooling for a few object types that were rapidly deleted and recreated.

* Converted a few flag checks to binary operations to save memory allocations.
2025-08-26 15:30:12 -05:00

51 lines
1.6 KiB
C#

using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
using System;
namespace Ryujinx.HLE.HOS.Services.Hid
{
public class TouchDevice : BaseDevice
{
public TouchDevice(Switch device, bool active) : base(device, active) { }
public void Update(params ReadOnlySpan<TouchPoint> points)
{
ref RingLifo<TouchScreenState> lifo = ref _device.Hid.SharedMemory.TouchScreen;
ref TouchScreenState previousEntry = ref lifo.GetCurrentEntryRef();
TouchScreenState newState = new()
{
SamplingNumber = previousEntry.SamplingNumber + 1,
};
if (Active)
{
newState.TouchesCount = points.Length;
Span<TouchState> touchesSpan = newState.Touches.AsSpan();
int pointsLength = Math.Min(points.Length, touchesSpan.Length);
for (int i = 0; i < pointsLength; ++i)
{
TouchPoint pi = points[i];
touchesSpan[i] = new TouchState
{
DeltaTime = newState.SamplingNumber,
Attribute = pi.Attribute,
X = pi.X,
Y = pi.Y,
FingerId = (uint)i,
DiameterX = pi.DiameterX,
DiameterY = pi.DiameterY,
RotationAngle = pi.Angle,
};
}
}
lifo.Write(ref newState);
}
}
}