Proper generic constraints
This commit is contained in:
parent
4f5b582df5
commit
f9847590d9
4 changed files with 16 additions and 13 deletions
|
@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
|||
WriteObjectToSharedMemory(NetworkSystemClockContextOffset, 4, context);
|
||||
}
|
||||
|
||||
private T ReadObjectFromSharedMemory<T>(ulong offset, ulong padding)
|
||||
private T ReadObjectFromSharedMemory<T>(ulong offset, ulong padding) where T : unmanaged
|
||||
{
|
||||
ulong indexOffset = _timeSharedMemoryAddress + offset;
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
|||
return result;
|
||||
}
|
||||
|
||||
private void WriteObjectToSharedMemory<T>(ulong offset, ulong padding, T value)
|
||||
private void WriteObjectToSharedMemory<T>(ulong offset, ulong padding, T value) where T : unmanaged
|
||||
{
|
||||
ulong indexOffset = _timeSharedMemoryAddress + offset;
|
||||
uint newIndex = _device.Memory.Read<uint>(indexOffset) + 1;
|
||||
|
|
|
@ -200,10 +200,14 @@ namespace Ryujinx.HLE.Input
|
|||
{
|
||||
SamplesTimestamp = _currentKeyboardEntry.SamplesTimestamp + 1,
|
||||
SamplesTimestamp2 = _currentKeyboardEntry.SamplesTimestamp2 + 1,
|
||||
Keys = keyboard.Keys,
|
||||
Modifier = keyboard.Modifier,
|
||||
};
|
||||
|
||||
for (int index = 0; index < keyboard.Keys.Length; index++)
|
||||
{
|
||||
newkeyboardEntry.Keys[index] = keyboard.Keys[index];
|
||||
}
|
||||
|
||||
_device.Memory.Write((ulong)keyboardEntryOffset, newkeyboardEntry);
|
||||
|
||||
_currentKeyboardEntry = newkeyboardEntry;
|
||||
|
|
|
@ -3,13 +3,11 @@
|
|||
namespace Ryujinx.HLE.Input
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct KeyboardEntry
|
||||
public unsafe struct KeyboardEntry
|
||||
{
|
||||
public long SamplesTimestamp;
|
||||
public long SamplesTimestamp2;
|
||||
public long Modifier;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 0x8)]
|
||||
public int[] Keys;
|
||||
public fixed int Keys[8];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,9 +57,9 @@ namespace Ryujinx.Memory
|
|||
/// <param name="address">Address where the data is located</param>
|
||||
/// <returns>Data at the specified address</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T Read<T>(ulong address)
|
||||
public T Read<T>(ulong address) where T : unmanaged
|
||||
{
|
||||
return GetRef<T>(address, Unsafe.SizeOf<T>());
|
||||
return GetRef<T>(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -80,9 +80,9 @@ namespace Ryujinx.Memory
|
|||
/// <param name="address">Address to write the data into</param>
|
||||
/// <param name="data">Data to be written</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Write<T>(ulong address, T data)
|
||||
public void Write<T>(ulong address, T data) where T : unmanaged
|
||||
{
|
||||
GetRef<T>(address, Unsafe.SizeOf<T>()) = data;
|
||||
GetRef<T>(address) = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -123,10 +123,9 @@ namespace Ryujinx.Memory
|
|||
/// </summary>
|
||||
/// <typeparam name="T">Data type</typeparam>
|
||||
/// <param name="address">Address of the memory region</param>
|
||||
/// <param name="size">Size in bytes of the memory region</param>
|
||||
/// <returns>A reference to the given memory region data</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe ref T GetRef<T>(ulong address, int size)
|
||||
public unsafe ref T GetRef<T>(ulong address) where T : unmanaged
|
||||
{
|
||||
IntPtr ptr = _pointer;
|
||||
|
||||
|
@ -135,6 +134,8 @@ namespace Ryujinx.Memory
|
|||
throw new ObjectDisposedException(nameof(MemoryBlock));
|
||||
}
|
||||
|
||||
int size = Unsafe.SizeOf<T>();
|
||||
|
||||
ulong endAddress = address + (ulong)size;
|
||||
|
||||
if (endAddress > Size || endAddress < address)
|
||||
|
|
Loading…
Add table
Reference in a new issue