Skip to content

Commit

Permalink
format and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed May 8, 2024
1 parent 0ea8597 commit 3abd61c
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Backdash/Backends/Peer2PeerBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BackendServices<TInput, TGameState> services
logger = services.Logger;
inputListener = services.InputListener;

peerInputEventQueue = new ProtocolInputEventQueue<TInput>();
peerInputEventQueue = new();
peerCombinedInputsEventPublisher = new ProtocolCombinedInputsEventPublisher<TInput>(peerInputEventQueue);
inputGroupSerializer = new ConfirmedInputsSerializer<TInput>(inputSerializer);
localConnections = new(Max.NumberOfPlayers);
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/Backends/SpectatorBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/Backends/SyncTestBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ BackendServices<TInput, TGameState> services
public FrameSpan RollbackFrames => synchronizer.RollbackFrames;

public IReadOnlyCollection<PlayerHandle> GetPlayers() =>
addedPlayers.Count is 0 ? [new PlayerHandle(PlayerType.Local, 1, 0)] : addedPlayers;
addedPlayers.Count is 0 ? [new(PlayerType.Local, 1, 0)] : addedPlayers;

public IReadOnlyCollection<PlayerHandle> GetSpectators() => addedSpectators;
public void DisconnectPlayer(in PlayerHandle player) { }
Expand Down
24 changes: 7 additions & 17 deletions src/Backdash/Core/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> pool = ArrayPool<char>.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}");

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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()}";
}
4 changes: 2 additions & 2 deletions src/Backdash/Network/Client/UdpSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public UdpSocket(IPEndPoint bindEndpoint)

try
{
socket.LingerState = new LingerOption(false, 0);
socket.LingerState = new(false, 0);
}
catch
{
Expand All @@ -72,7 +72,7 @@ public UdpSocket(IPEndPoint bindEndpoint)


/// <inheritdoc />
public UdpSocket(IPAddress bindAddress, int port) : this(new IPEndPoint(bindAddress, port)) { }
public UdpSocket(IPAddress bindAddress, int port) : this(new(bindAddress, port)) { }

/// <inheritdoc />
public UdpSocket(int port, bool useIPv6 = false) : this(useIPv6 ? IPAddress.IPv6Any : IPAddress.Any, port) { }
Expand Down
4 changes: 2 additions & 2 deletions src/Backdash/Network/PeerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand All @@ -309,7 +309,7 @@ void OnQualityReportTick(object? sender, ElapsedEventArgs e)
return;

outbox
.SendMessage(new ProtocolMessage(MessageType.QualityReport)
.SendMessage(new(MessageType.QualityReport)
{
QualityReport = new()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/Network/Protocol/Comm/ProtocolInbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/Backdash/Network/ProtocolInputEventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sealed class ProtocolInputEventQueue<TInput> : IProtocolInputEventQueue<TInput>
{
bool disposed;
readonly Channel<GameInputEvent<TInput>> channel = Channel.CreateUnbounded<GameInputEvent<TInput>>(
new UnboundedChannelOptions
new()
{
SingleWriter = false,
SingleReader = true,
Expand Down Expand Up @@ -58,9 +58,9 @@ public void Publish(in GameInputEvent<ConfirmedInputs<TInput>> evt)
{
ref readonly var current = ref evt.Input.Data.Inputs[i];
peerInputEventPublisher.Publish(
new GameInputEvent<TInput>(
new(
player,
new GameInput<TInput>(current, frame))
new(current, frame))
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/Network/ProtocolNetworkEventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
4 changes: 2 additions & 2 deletions src/Backdash/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public sealed class RemotePlayer(int playerNumber, IPEndPoint endpoint) : Player
/// <param name="ipAddress">Player IP Address</param>
/// <param name="port">Player remote port number</param>
public RemotePlayer(int playerNumber, IPAddress ipAddress, int port)
: this(playerNumber, new IPEndPoint(ipAddress, port)) { }
: this(playerNumber, new(ipAddress, port)) { }

/// <summary>
/// Player network endpoint
Expand All @@ -95,7 +95,7 @@ public sealed class Spectator(IPEndPoint endpoint) : Player(PlayerType.Spectator
/// </summary>
/// <param name="ipAddress">Player IP Address</param>
/// <param name="port">Player remote port number</param>
public Spectator(IPAddress ipAddress, int port) : this(new IPEndPoint(ipAddress, port)) { }
public Spectator(IPAddress ipAddress, int port) : this(new(ipAddress, port)) { }

/// <summary>
/// Player network endpoint
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/RollbackNetcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static IRollbackSession<TInput, TGameState> CreateReplaySession<TInput, T
where TGameState : notnull, new() =>
new ReplayBackend<TInput, TGameState>(
numberOfPlayers, inputs,
BackendServices.Create(new RollbackOptions(), services));
BackendServices.Create(new(), services));

/// <summary>
/// Initializes new sync test session.
Expand Down
2 changes: 1 addition & 1 deletion src/Backdash/Sync/State/Stores/BinaryStateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Initialize(int size)
{
savedStates = new SavedFrame<TState>[size];
for (int i = 0; i < size; i++)
savedStates[i] = new(Frame.Null, new TState(), 0);
savedStates[i] = new(Frame.Null, new(), 0);
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion tests/Backdash.Tests/TestUtils/Network/PortUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Backdash.Tests/TestUtils/Network/UdpClientContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public UdpClientContext(IBinarySerializer<T> serializer, int? port = null)
Port = port.Value;
Address = Loopback.Serialize();

Client = new PeerClient<T>(
Client = new(
socket,
serializer,
Observer,
Expand Down

0 comments on commit 3abd61c

Please sign in to comment.