Proper generic constraints

This commit is contained in:
gdkchan 2020-01-03 00:11:27 -03:00
commit f9847590d9
4 changed files with 16 additions and 13 deletions

View file

@ -87,7 +87,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
WriteObjectToSharedMemory(NetworkSystemClockContextOffset, 4, context); 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; ulong indexOffset = _timeSharedMemoryAddress + offset;
@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
return result; 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; ulong indexOffset = _timeSharedMemoryAddress + offset;
uint newIndex = _device.Memory.Read<uint>(indexOffset) + 1; uint newIndex = _device.Memory.Read<uint>(indexOffset) + 1;

View file

@ -200,10 +200,14 @@ namespace Ryujinx.HLE.Input
{ {
SamplesTimestamp = _currentKeyboardEntry.SamplesTimestamp + 1, SamplesTimestamp = _currentKeyboardEntry.SamplesTimestamp + 1,
SamplesTimestamp2 = _currentKeyboardEntry.SamplesTimestamp2 + 1, SamplesTimestamp2 = _currentKeyboardEntry.SamplesTimestamp2 + 1,
Keys = keyboard.Keys,
Modifier = keyboard.Modifier, Modifier = keyboard.Modifier,
}; };
for (int index = 0; index < keyboard.Keys.Length; index++)
{
newkeyboardEntry.Keys[index] = keyboard.Keys[index];
}
_device.Memory.Write((ulong)keyboardEntryOffset, newkeyboardEntry); _device.Memory.Write((ulong)keyboardEntryOffset, newkeyboardEntry);
_currentKeyboardEntry = newkeyboardEntry; _currentKeyboardEntry = newkeyboardEntry;

View file

@ -3,13 +3,11 @@
namespace Ryujinx.HLE.Input namespace Ryujinx.HLE.Input
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct KeyboardEntry public unsafe struct KeyboardEntry
{ {
public long SamplesTimestamp; public long SamplesTimestamp;
public long SamplesTimestamp2; public long SamplesTimestamp2;
public long Modifier; public long Modifier;
public fixed int Keys[8];
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 0x8)]
public int[] Keys;
} }
} }

View file

@ -57,9 +57,9 @@ namespace Ryujinx.Memory
/// <param name="address">Address where the data is located</param> /// <param name="address">Address where the data is located</param>
/// <returns>Data at the specified address</returns> /// <returns>Data at the specified address</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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> /// <summary>
@ -80,9 +80,9 @@ namespace Ryujinx.Memory
/// <param name="address">Address to write the data into</param> /// <param name="address">Address to write the data into</param>
/// <param name="data">Data to be written</param> /// <param name="data">Data to be written</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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> /// <summary>
@ -123,10 +123,9 @@ namespace Ryujinx.Memory
/// </summary> /// </summary>
/// <typeparam name="T">Data type</typeparam> /// <typeparam name="T">Data type</typeparam>
/// <param name="address">Address of the memory region</param> /// <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> /// <returns>A reference to the given memory region data</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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; IntPtr ptr = _pointer;
@ -135,6 +134,8 @@ namespace Ryujinx.Memory
throw new ObjectDisposedException(nameof(MemoryBlock)); throw new ObjectDisposedException(nameof(MemoryBlock));
} }
int size = Unsafe.SizeOf<T>();
ulong endAddress = address + (ulong)size; ulong endAddress = address + (ulong)size;
if (endAddress > Size || endAddress < address) if (endAddress > Size || endAddress < address)