diff --git a/Directory.Build.props b/Directory.Build.props index fb6b80b7..794b8ebc 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -37,7 +37,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/LobbyServer/UdpListenerService.cs b/samples/LobbyServer/UdpListenerService.cs index 6dd8158a..c4728e62 100644 --- a/samples/LobbyServer/UdpListenerService.cs +++ b/samples/LobbyServer/UdpListenerService.cs @@ -68,9 +68,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) entry.Peer.Endpoint = remoteEndPoint; entry.LastRead = time.GetUtcNow(); } - catch (OperationCanceledException) + catch (OperationCanceledException ex) { - logger.LogInformation("UDP: operation cancelled"); + logger.LogInformation(ex, "UDP: operation cancelled"); break; } catch (Exception ex) diff --git a/samples/SpaceWar.Shared/Logic/GameState.cs b/samples/SpaceWar.Shared/Logic/GameState.cs index ceac9e29..f5bc287b 100644 --- a/samples/SpaceWar.Shared/Logic/GameState.cs +++ b/samples/SpaceWar.Shared/Logic/GameState.cs @@ -108,7 +108,7 @@ public void UpdateShip(in Ship ship, in GameInput inputs) } ship.Thrust = Math.Sign(inputs.Thrust); - if (inputs.Thrust != 0) + if (ship.Thrust != 0) { ship.Velocity += (dir * inputs.Thrust).RoundTo(); var magnitude = ship.Velocity.Length(); diff --git a/src/Backdash/Network/PeerConnection.cs b/src/Backdash/Network/PeerConnection.cs index d1ce1872..7e796c3a 100644 --- a/src/Backdash/Network/PeerConnection.cs +++ b/src/Backdash/Network/PeerConnection.cs @@ -125,10 +125,10 @@ public void Update() syncRequest.Update(); break; case ProtocolStatus.Running: - { - CheckDisconnection(); - break; - } + { + CheckDisconnection(); + break; + } case ProtocolStatus.Disconnected: break; } diff --git a/tests/Backdash.Tests/Specs/Unit/Serialization/BinarySpanReadWriteValueTests.cs b/tests/Backdash.Tests/Specs/Unit/Serialization/BinarySpanReadWriteValueTests.cs index 94e9f9bc..32d32c13 100644 --- a/tests/Backdash.Tests/Specs/Unit/Serialization/BinarySpanReadWriteValueTests.cs +++ b/tests/Backdash.Tests/Specs/Unit/Serialization/BinarySpanReadWriteValueTests.cs @@ -6,7 +6,10 @@ using Backdash.Tests.TestUtils.Types; // ReSharper disable CompareOfFloatsByEqualityOperator +#pragma warning disable S1244 + namespace Backdash.Tests.Specs.Unit.Serialization; + [Collection(SerialCollectionDefinition.Name)] public class BinarySpanReadWriteValueTests { @@ -20,6 +23,7 @@ public bool SingleByte(byte value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleSByte(sbyte value, Endianness endianness) { @@ -30,6 +34,7 @@ public bool SingleSByte(sbyte value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleBool(bool value, Endianness endianness) { @@ -40,6 +45,7 @@ public bool SingleBool(bool value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleChar(char value, Endianness endianness) { @@ -50,6 +56,7 @@ public bool SingleChar(char value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleShort(short value, Endianness endianness) { @@ -60,6 +67,7 @@ public bool SingleShort(short value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleUShort(ushort value, Endianness endianness) { @@ -70,6 +78,7 @@ public bool SingleUShort(ushort value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleInt(int value, Endianness endianness) { @@ -80,6 +89,7 @@ public bool SingleInt(int value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleUInt(uint value, Endianness endianness) { @@ -90,6 +100,7 @@ public bool SingleUInt(uint value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleLong(long value, Endianness endianness) { @@ -100,6 +111,7 @@ public bool SingleLong(long value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleULong(ulong value, Endianness endianness) { @@ -110,6 +122,7 @@ public bool SingleULong(ulong value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleInt128(Int128 value, Endianness endianness) { @@ -120,6 +133,7 @@ public bool SingleInt128(Int128 value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleIntU128(UInt128 value, Endianness endianness) { @@ -130,6 +144,7 @@ public bool SingleIntU128(UInt128 value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleHalf(Half value, Endianness endianness) { @@ -140,6 +155,7 @@ public bool SingleHalf(Half value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleFloat(float value, Endianness endianness) { @@ -150,6 +166,7 @@ public bool SingleFloat(float value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleDouble(double value, Endianness endianness) { @@ -160,6 +177,7 @@ public bool SingleDouble(double value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleVector2(Vector2 value, Endianness endianness) { @@ -170,6 +188,7 @@ public bool SingleVector2(Vector2 value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleVector3(Vector3 value, Endianness endianness) { @@ -180,6 +199,7 @@ public bool SingleVector3(Vector3 value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleVector4(Vector4 value, Endianness endianness) { @@ -190,6 +210,7 @@ public bool SingleVector4(Vector4 value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + [PropertyTest] public bool SingleQuaternion(Quaternion value, Endianness endianness) { @@ -200,8 +221,10 @@ public bool SingleQuaternion(Quaternion value, Endianness endianness) reader.ReadCount.Should().Be(size); return value == read; } + static int writeOffset; static int readOffset; + static int Setup( Endianness endianness, out BinarySpanWriter writer, @@ -222,25 +245,32 @@ out BinarySpanReader reader }; return size; } + [Collection(SerialCollectionDefinition.Name)] public class ReadWriteEnumTests { [PropertyTest] public bool TestIntEnum(IntEnum value, Endianness endianness) => TestEnum(value, endianness); [PropertyTest] public bool TestUIntEnum(UIntEnum value, Endianness endianness) => TestEnum(value, endianness); [PropertyTest] public bool TestLongEnum(LongEnum value, Endianness endianness) => TestEnum(value, endianness); + [PropertyTest] public bool TestULongEnum(ULongEnum value, Endianness endianness) => TestEnum(value, endianness); + [PropertyTest] public bool TestShortEnum(ShortEnum value, Endianness endianness) => TestEnum(value, endianness); + [PropertyTest] public bool TestUShortEnum(UShortEnum value, Endianness endianness) => TestEnum(value, endianness); + [PropertyTest] public bool TestByteEnum(ByteEnum value, Endianness endianness) => TestEnum(value, endianness); + [PropertyTest] public bool TestSByteEnum(SByteEnum value, Endianness endianness) => TestEnum(value, endianness); + bool TestEnum(T value, Endianness endianness) where T : unmanaged, Enum { var size = Setup(endianness, out var writer, out var reader); @@ -251,25 +281,32 @@ bool TestEnum(T value, Endianness endianness) where T : unmanaged, Enum return EqualityComparer.Default.Equals(read, value); } } + [Collection(SerialCollectionDefinition.Name)] public class ReadWriteBinaryIntegerTests { [PropertyTest] public bool TestInt(int value, Endianness endianness) => TestInteger(value, endianness); [PropertyTest] public bool TestUInt(uint value, Endianness endianness) => TestInteger(value, endianness); [PropertyTest] public bool TestLong(long value, Endianness endianness) => TestInteger(value, endianness); + [PropertyTest] public bool TestULong(ulong value, Endianness endianness) => TestInteger(value, endianness); + [PropertyTest] public bool TestShort(short value, Endianness endianness) => TestInteger(value, endianness); + [PropertyTest] public bool TestUShort(ushort value, Endianness endianness) => TestInteger(value, endianness); + [PropertyTest] public bool TestByte(byte value, Endianness endianness) => TestInteger(value, endianness); + [PropertyTest] public bool TestSByte(sbyte value, Endianness endianness) => TestInteger(value, endianness); + bool TestInteger(T value, Endianness endianness) where T : unmanaged, IBinaryInteger, IMinMaxValue { var size = Setup(endianness, out var writer, out var reader);