Skip to content

Commit ea3c5b9

Browse files
committed
cleanup
1 parent 29ae7cd commit ea3c5b9

3 files changed

Lines changed: 49 additions & 18 deletions

File tree

sources/Input/Input/Implementations/SDL3/DataStructures/SdlArray.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Silk.NET.Input.SDL3.DataStructures;
1818
/// <typeparam name="T">The type of values in the array - usually SDL struct types.</typeparam>
1919
internal readonly unsafe ref struct SdlArray<T> : IDisposable, IEquatable<SdlArray<T>> where T : unmanaged
2020
{
21-
private readonly Ptr<T> _ptr;
21+
private readonly T* _ptr;
2222
public int Count { get; }
2323
private readonly ISdl? _sdl;
2424

@@ -47,15 +47,18 @@ public void Dispose()
4747
{
4848
if (!CanDispose)
4949
{
50+
#if DEBUG
51+
InputLog.Error("SdlArray disposal attempt without permission");
52+
#endif
5053
return;
5154
}
5255

53-
if (_ptr.Native == null)
56+
if (_ptr == null)
5457
{
5558
return;
5659
}
5760

58-
_sdl.Free(_ptr.Native);
61+
_sdl.Free(_ptr);
5962
}
6063

6164
public static implicit operator Ptr<T>(SdlArray<T> array) => array._ptr;
@@ -72,19 +75,19 @@ public void Dispose()
7275

7376

7477

75-
public bool IsNull => _ptr.Native == null;
78+
public bool IsNull => _ptr == null;
7679

7780
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78-
public Span<T> AsSpan() => _ptr.Native == null ? default : new Span<T>(_ptr.Native, Count);
81+
public Span<T> AsSpan() => _ptr == null ? default : new Span<T>(_ptr, Count);
7982

8083
[MethodImpl(MethodImplOptions.AggressiveInlining)]
81-
public ReadOnlySpan<T> AsReadOnlySpan() => _ptr.Native == null ? default : new ReadOnlySpan<T>(_ptr.Native, Count);
84+
public ReadOnlySpan<T> AsReadOnlySpan() => _ptr == null ? default : new ReadOnlySpan<T>(_ptr, Count);
8285

8386
public ref T this[int index]
8487
{
8588
get
8689
{
87-
if (_ptr.Native == null)
90+
if (_ptr == null)
8891
{
8992
throw new NullReferenceException();
9093
}
@@ -96,7 +99,7 @@ public ref T this[int index]
9699

97100
ArgumentOutOfRangeException.ThrowIfNegative(index);
98101

99-
return ref _ptr.Native[index];
102+
return ref _ptr[index];
100103
}
101104
}
102105

@@ -108,6 +111,6 @@ public ref T this[uint index]
108111

109112
public bool Equals(SdlArray<T> other) => this == other;
110113

111-
public override bool Equals(object? obj) => obj == null && _ptr.Native == null;
112-
public override int GetHashCode() => HashCode.Combine(_ptr, Count, _sdl);
114+
public override bool Equals(object? obj) => obj == null && _ptr == null;
115+
public override int GetHashCode() => HashCode.Combine((nuint)_ptr, Count, _sdl);
113116
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.InteropServices;
5+
46
namespace Silk.NET.Input.SDL3.Devices.Pointers.Targets;
57

8+
[StructLayout(LayoutKind.Explicit, Size = sizeof(uint), Pack = 1)]
69
internal readonly struct SilkSdlDisplayHandle
710
{
11+
[FieldOffset(0)] public readonly uint Id;
12+
13+
private SilkSdlDisplayHandle(uint id) => Id = id;
14+
815
public static readonly SilkSdlDisplayHandle AllDisplays = new(uint.MaxValue);
9-
public uint Id { get; }
10-
public SilkSdlDisplayHandle(uint id) => Id = id;
1116
}

sources/Input/Input/Implementations/SDL3/SdlInputBackend.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,30 @@ public void Update(IInputHandler? handler = null)
166166
var rawEvents = _rawEvents.ConsumeWithoutClearing();
167167

168168
#if DEBUG
169-
var previousTimestamp = 0ul;
170-
var previousStopwatchTimestamp = 0L;
169+
TimedRawSdlEvent? previous = null;
171170
#endif
172171

173172
for(var i = 0; i < rawEvents.Length; ++i)
174173
{
175174
ref readonly var evt = ref rawEvents[i];
176175
#if DEBUG
177-
if (evt.Event.Common.Timestamp < previousTimestamp || evt.StopwatchTimestamp < previousStopwatchTimestamp)
176+
const string fmt = "Needs pre-sort by {0} timestamp. Please alert maintainer.\nPrevious:{1}\nCurrent:{2}\nDifference: SDL {3} Stopwatch {4}";
177+
if (previous is { } prev)
178178
{
179-
InputLog.Error("Needs pre-sort by timestamp - please alert maintainer");
179+
if (prev.Event.Common.Timestamp > evt.Event.Common.Timestamp)
180+
{
181+
evt.TimeMinus(prev, out var stopwatchDiff, out var sdlDiff);
182+
InputLog.Error(string.Format(fmt, "SDL", previous?.ToString() ?? "null", evt.ToString(), sdlDiff, stopwatchDiff));
183+
}
184+
185+
if (prev.StopwatchTimestamp > evt.StopwatchTimestamp)
186+
{
187+
evt.TimeMinus(prev, out var stopwatchDiff, out var sdlDiff);
188+
InputLog.Error(string.Format(fmt, "SDL", previous?.ToString() ?? "null", evt.ToString(), sdlDiff, stopwatchDiff));
189+
}
180190
}
181191

182-
previousTimestamp = evt.Event.Common.Timestamp;
183-
previousStopwatchTimestamp = evt.StopwatchTimestamp;
192+
previous = evt;
184193
#endif
185194

186195
ProcessEvent(evt.Event, evt.StopwatchTimestamp, ref eventArgs);
@@ -623,6 +632,20 @@ public TimedRawSdlEvent(Event @event, long timestamp)
623632
Event = @event;
624633
StopwatchTimestamp = timestamp;
625634
}
635+
636+
#if DEBUG
637+
public override string ToString()
638+
{
639+
var type = (EventType)Event.Type;
640+
return $"{type} | SDL Timestamp: {Event.Common.Timestamp} | Stopwatch Timestamp: {StopwatchTimestamp}";
641+
}
642+
643+
public void TimeMinus(in TimedRawSdlEvent other, out long stopwatchDiff, out long sdlDiff)
644+
{
645+
stopwatchDiff = StopwatchTimestamp - other.StopwatchTimestamp;
646+
sdlDiff = (long)(Event.Common.Timestamp - other.Event.Common.Timestamp);
647+
}
648+
#endif
626649
}
627650

628651

0 commit comments

Comments
 (0)