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
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
{
|
||||
public class KeyboardDevice : BaseDevice
|
||||
@@ -6,27 +10,26 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
|
||||
public unsafe void Update(KeyboardInput keyState)
|
||||
{
|
||||
ref ShMemKeyboard keyboard = ref _device.Hid.SharedMemory.Keyboard;
|
||||
|
||||
int currentIndex = UpdateEntriesHeader(ref keyboard.Header, out int previousIndex);
|
||||
ref RingLifo<KeyboardState> lifo = ref _device.Hid.SharedMemory.Keyboard;
|
||||
|
||||
if (!Active)
|
||||
{
|
||||
lifo.Clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ref KeyboardState currentEntry = ref keyboard.Entries[currentIndex];
|
||||
KeyboardState previousEntry = keyboard.Entries[previousIndex];
|
||||
ref KeyboardState previousEntry = ref lifo.GetCurrentEntryRef();
|
||||
|
||||
currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
|
||||
currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
KeyboardState newState = new KeyboardState
|
||||
{
|
||||
currentEntry.Keys[i] = (uint)keyState.Keys[i];
|
||||
}
|
||||
SamplingNumber = previousEntry.SamplingNumber + 1,
|
||||
};
|
||||
|
||||
currentEntry.Modifier = (ulong)keyState.Modifier;
|
||||
keyState.Keys.AsSpan().CopyTo(newState.Keys.RawData.ToSpan());
|
||||
newState.Modifiers = (KeyboardModifier)keyState.Modifier;
|
||||
|
||||
lifo.Write(ref newState);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user