1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00
Ryujinx/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs
Mary 3443023a08
hid: Rewrite shared memory management (#2257)
* hid: Rewrite shared memory management

This entirely rewrite our ancient (and original) HID shared memory
interface to be more usable and accurate.

HID update logics were updated to reflect those changes but should work
still the same way it previously did.

This need heavy testing just in case to avoid possible regressions.

* Silence warnings

* Address gdkchan's comments

* Address Ac_K's comments

* Address one missing nit
2021-05-02 22:01:30 +02:00

47 lines
No EOL
1.5 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 TouchPoint[] points)
{
ref RingLifo<TouchScreenState> lifo = ref _device.Hid.SharedMemory.TouchScreen;
ref TouchScreenState previousEntry = ref lifo.GetCurrentEntryRef();
TouchScreenState newState = new TouchScreenState
{
SamplingNumber = previousEntry.SamplingNumber + 1
};
if (Active)
{
newState.TouchesCount = points.Length;
int pointsLength = Math.Min(points.Length, newState.Touches.Length);
for (int i = 0; i < pointsLength; ++i)
{
TouchPoint pi = points[i];
newState.Touches[i] = new TouchState
{
DeltaTime = newState.SamplingNumber,
X = pi.X,
Y = pi.Y,
FingerId = (uint)i,
DiameterX = pi.DiameterX,
DiameterY = pi.DiameterY,
RotationAngle = pi.Angle
};
}
}
lifo.Write(ref newState);
}
}
}