From 3abd61c5948c90bea580eda5b33727fefaefdf2e Mon Sep 17 00:00:00 2001 From: Lucas Teles Date: Wed, 8 May 2024 12:18:25 -0300 Subject: [PATCH] format and linting --- src/Backdash/Backends/Peer2PeerBackend.cs | 2 +- src/Backdash/Backends/SpectatorBackend.cs | 2 +- src/Backdash/Backends/SyncTestBackend.cs | 2 +- src/Backdash/Core/Logger.cs | 24 ++++++------------- src/Backdash/Network/Client/UdpSocket.cs | 4 ++-- src/Backdash/Network/PeerConnection.cs | 4 ++-- .../Network/Protocol/Comm/ProtocolInbox.cs | 2 +- .../Network/ProtocolInputEventQueue.cs | 6 ++--- .../Network/ProtocolNetworkEventQueue.cs | 2 +- src/Backdash/Player.cs | 4 ++-- src/Backdash/RollbackNetcode.cs | 2 +- .../Sync/State/Stores/BinaryStateStore.cs | 2 +- .../TestUtils/Network/PortUtils.cs | 2 +- .../TestUtils/Network/UdpClientContext.cs | 2 +- 14 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/Backdash/Backends/Peer2PeerBackend.cs b/src/Backdash/Backends/Peer2PeerBackend.cs index 59a0b2ce..f1b3b354 100644 --- a/src/Backdash/Backends/Peer2PeerBackend.cs +++ b/src/Backdash/Backends/Peer2PeerBackend.cs @@ -66,7 +66,7 @@ BackendServices services logger = services.Logger; inputListener = services.InputListener; - peerInputEventQueue = new ProtocolInputEventQueue(); + peerInputEventQueue = new(); peerCombinedInputsEventPublisher = new ProtocolCombinedInputsEventPublisher(peerInputEventQueue); inputGroupSerializer = new ConfirmedInputsSerializer(inputSerializer); localConnections = new(Max.NumberOfPlayers); diff --git a/src/Backdash/Backends/SpectatorBackend.cs b/src/Backdash/Backends/SpectatorBackend.cs index 543e8ef7..08c6a81a 100644 --- a/src/Backdash/Backends/SpectatorBackend.cs +++ b/src/Backdash/Backends/SpectatorBackend.cs @@ -70,7 +70,7 @@ public SpectatorBackend(int port, ); ProtocolState protocolState = - new(new PlayerHandle(PlayerType.Remote, 0), hostEndpoint, localConnections); + new(new(PlayerType.Remote, 0), hostEndpoint, localConnections); host = peerConnectionFactory.Create(protocolState, inputGroupSerializer, this); peerObservers.Add(host.GetUdpObserver()); diff --git a/src/Backdash/Backends/SyncTestBackend.cs b/src/Backdash/Backends/SyncTestBackend.cs index a703a307..d7ce2d8d 100644 --- a/src/Backdash/Backends/SyncTestBackend.cs +++ b/src/Backdash/Backends/SyncTestBackend.cs @@ -83,7 +83,7 @@ BackendServices services public FrameSpan RollbackFrames => synchronizer.RollbackFrames; public IReadOnlyCollection GetPlayers() => - addedPlayers.Count is 0 ? [new PlayerHandle(PlayerType.Local, 1, 0)] : addedPlayers; + addedPlayers.Count is 0 ? [new(PlayerType.Local, 1, 0)] : addedPlayers; public IReadOnlyCollection GetSpectators() => addedSpectators; public void DisconnectPlayer(in PlayerHandle player) { } diff --git a/src/Backdash/Core/Logger.cs b/src/Backdash/Core/Logger.cs index cd551bfd..7bbdcb6b 100644 --- a/src/Backdash/Core/Logger.cs +++ b/src/Backdash/Core/Logger.cs @@ -42,24 +42,14 @@ public enum LogLevel : byte Error, } -sealed class Logger : IDisposable +sealed class Logger( + LogOptions options, + ILogWriter writer +) : IDisposable { - public readonly LogLevel EnabledLevel; + public readonly LogLevel EnabledLevel = options.EnabledLevel; readonly long start = Stopwatch.GetTimestamp(); readonly ArrayPool pool = ArrayPool.Shared; - readonly LogOptions options; - readonly ILogWriter writer; - - public Logger( - LogOptions options, - ILogWriter writer - ) - { - this.options = options; - this.writer = writer; - EnabledLevel = options.EnabledLevel; - JobName = $"Log Flush {writer.GetType()}"; - } public void Write(LogLevel level, string text) => Write(level, $"{text}"); @@ -89,7 +79,7 @@ LogInterpolatedStringHandler builder public bool IsEnabledFor(in LogLevel level) => level >= EnabledLevel; public static Logger CreateConsoleLogger(LogLevel level) => new( - new LogOptions + new() { EnabledLevel = level, }, @@ -132,5 +122,5 @@ static string ShortLevelName(LogLevel level) => }; public void Dispose() => writer.Dispose(); - public string JobName { get; } + public string JobName { get; } = $"Log Flush {writer.GetType()}"; } diff --git a/src/Backdash/Network/Client/UdpSocket.cs b/src/Backdash/Network/Client/UdpSocket.cs index 97bb3300..dfdfc30c 100644 --- a/src/Backdash/Network/Client/UdpSocket.cs +++ b/src/Backdash/Network/Client/UdpSocket.cs @@ -54,7 +54,7 @@ public UdpSocket(IPEndPoint bindEndpoint) try { - socket.LingerState = new LingerOption(false, 0); + socket.LingerState = new(false, 0); } catch { @@ -72,7 +72,7 @@ public UdpSocket(IPEndPoint bindEndpoint) /// - public UdpSocket(IPAddress bindAddress, int port) : this(new IPEndPoint(bindAddress, port)) { } + public UdpSocket(IPAddress bindAddress, int port) : this(new(bindAddress, port)) { } /// public UdpSocket(int port, bool useIPv6 = false) : this(useIPv6 ? IPAddress.IPv6Any : IPAddress.Any, port) { } diff --git a/src/Backdash/Network/PeerConnection.cs b/src/Backdash/Network/PeerConnection.cs index 20cf013e..7703a664 100644 --- a/src/Backdash/Network/PeerConnection.cs +++ b/src/Backdash/Network/PeerConnection.cs @@ -282,7 +282,7 @@ void OnKeepAliveTick(object? sender, ElapsedEventArgs e) return; logger.Write(LogLevel.Information, "Sending keep alive packet"); - outbox.SendMessage(new ProtocolMessage(MessageType.KeepAlive) + outbox.SendMessage(new(MessageType.KeepAlive) { KeepAlive = new(), }); @@ -309,7 +309,7 @@ void OnQualityReportTick(object? sender, ElapsedEventArgs e) return; outbox - .SendMessage(new ProtocolMessage(MessageType.QualityReport) + .SendMessage(new(MessageType.QualityReport) { QualityReport = new() { diff --git a/src/Backdash/Network/Protocol/Comm/ProtocolInbox.cs b/src/Backdash/Network/Protocol/Comm/ProtocolInbox.cs index 5a062966..37b1b71e 100644 --- a/src/Backdash/Network/Protocol/Comm/ProtocolInbox.cs +++ b/src/Backdash/Network/Protocol/Comm/ProtocolInbox.cs @@ -281,7 +281,7 @@ bool OnSyncReply(in ProtocolMessage msg, ref ProtocolMessage replyMsg) else { networkEvents.OnNetworkEvent( - new ProtocolEventInfo(ProtocolEvent.Synchronizing, state.Player) + new(ProtocolEvent.Synchronizing, state.Player) { Synchronizing = new( TotalSteps: options.NumberOfSyncRoundtrips, diff --git a/src/Backdash/Network/ProtocolInputEventQueue.cs b/src/Backdash/Network/ProtocolInputEventQueue.cs index a08d77ee..c136e39b 100644 --- a/src/Backdash/Network/ProtocolInputEventQueue.cs +++ b/src/Backdash/Network/ProtocolInputEventQueue.cs @@ -26,7 +26,7 @@ sealed class ProtocolInputEventQueue : IProtocolInputEventQueue { bool disposed; readonly Channel> channel = Channel.CreateUnbounded>( - new UnboundedChannelOptions + new() { SingleWriter = false, SingleReader = true, @@ -58,9 +58,9 @@ public void Publish(in GameInputEvent> evt) { ref readonly var current = ref evt.Input.Data.Inputs[i]; peerInputEventPublisher.Publish( - new GameInputEvent( + new( player, - new GameInput(current, frame)) + new(current, frame)) ); } } diff --git a/src/Backdash/Network/ProtocolNetworkEventQueue.cs b/src/Backdash/Network/ProtocolNetworkEventQueue.cs index a53645de..15c3e501 100644 --- a/src/Backdash/Network/ProtocolNetworkEventQueue.cs +++ b/src/Backdash/Network/ProtocolNetworkEventQueue.cs @@ -5,5 +5,5 @@ interface IProtocolNetworkEventHandler : IDisposable { void OnNetworkEvent(in ProtocolEventInfo evt); void OnNetworkEvent(in ProtocolEvent evt, in PlayerHandle player) => - OnNetworkEvent(new ProtocolEventInfo(evt, player)); + OnNetworkEvent(new(evt, player)); } diff --git a/src/Backdash/Player.cs b/src/Backdash/Player.cs index 1762b58b..79a3d9d1 100644 --- a/src/Backdash/Player.cs +++ b/src/Backdash/Player.cs @@ -76,7 +76,7 @@ public sealed class RemotePlayer(int playerNumber, IPEndPoint endpoint) : Player /// Player IP Address /// Player remote port number public RemotePlayer(int playerNumber, IPAddress ipAddress, int port) - : this(playerNumber, new IPEndPoint(ipAddress, port)) { } + : this(playerNumber, new(ipAddress, port)) { } /// /// Player network endpoint @@ -95,7 +95,7 @@ public sealed class Spectator(IPEndPoint endpoint) : Player(PlayerType.Spectator /// /// Player IP Address /// Player remote port number - public Spectator(IPAddress ipAddress, int port) : this(new IPEndPoint(ipAddress, port)) { } + public Spectator(IPAddress ipAddress, int port) : this(new(ipAddress, port)) { } /// /// Player network endpoint diff --git a/src/Backdash/RollbackNetcode.cs b/src/Backdash/RollbackNetcode.cs index 47ee4b47..b6199ebc 100644 --- a/src/Backdash/RollbackNetcode.cs +++ b/src/Backdash/RollbackNetcode.cs @@ -75,7 +75,7 @@ public static IRollbackSession CreateReplaySession new ReplayBackend( numberOfPlayers, inputs, - BackendServices.Create(new RollbackOptions(), services)); + BackendServices.Create(new(), services)); /// /// Initializes new sync test session. diff --git a/src/Backdash/Sync/State/Stores/BinaryStateStore.cs b/src/Backdash/Sync/State/Stores/BinaryStateStore.cs index b5cff4c3..e6ac9d70 100644 --- a/src/Backdash/Sync/State/Stores/BinaryStateStore.cs +++ b/src/Backdash/Sync/State/Stores/BinaryStateStore.cs @@ -27,7 +27,7 @@ public void Initialize(int size) { savedStates = new SavedFrame[size]; for (int i = 0; i < size; i++) - savedStates[i] = new(Frame.Null, new TState(), 0); + savedStates[i] = new(Frame.Null, new(), 0); } /// diff --git a/tests/Backdash.Tests/TestUtils/Network/PortUtils.cs b/tests/Backdash.Tests/TestUtils/Network/PortUtils.cs index f4a02f8c..8725982b 100644 --- a/tests/Backdash.Tests/TestUtils/Network/PortUtils.cs +++ b/tests/Backdash.Tests/TestUtils/Network/PortUtils.cs @@ -10,7 +10,7 @@ public static int FindFreePort() TcpListener? tcpListener = null; try { - tcpListener = new TcpListener(IPAddress.Loopback, 0); + tcpListener = new(IPAddress.Loopback, 0); tcpListener.Start(); return ((IPEndPoint)tcpListener.LocalEndpoint).Port; } diff --git a/tests/Backdash.Tests/TestUtils/Network/UdpClientContext.cs b/tests/Backdash.Tests/TestUtils/Network/UdpClientContext.cs index 78c535b1..2097eb05 100644 --- a/tests/Backdash.Tests/TestUtils/Network/UdpClientContext.cs +++ b/tests/Backdash.Tests/TestUtils/Network/UdpClientContext.cs @@ -23,7 +23,7 @@ public UdpClientContext(IBinarySerializer serializer, int? port = null) Port = port.Value; Address = Loopback.Serialize(); - Client = new PeerClient( + Client = new( socket, serializer, Observer,