Skip to content

Commit

Permalink
fix sample
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed May 8, 2024
1 parent 3abd61c commit aae32f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion samples/SpaceWar/GameSessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static IRollbackSession<PlayerInputs, GameState> ParseArgs(

var session = RollbackNetcode.CreateSession<PlayerInputs, GameState>(port, options, new()
{
// LogWriter = new FileLogWriter($"log_{localPlayer.Number}.log"),
// LogWriter = new Backdash.Core.FileTextLogWriter($"log_{localPlayer.Number}.log"),
InputListener = saveInputsListener,
});

Expand Down
4 changes: 2 additions & 2 deletions samples/SpaceWar/scripts/windows/start_2players.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dotnet build -c Release %~dp0\..\..
pushd %~dp0\..\..\bin\Release\net8.0
del *.log
start SpaceWar 9000 2 local 127.0.0.1:9001
start SpaceWar 9000 2 local 127.0.0.1:9001
start SpaceWar 9001 2 127.0.0.1:9000 local
popd
popd
13 changes: 8 additions & 5 deletions src/Backdash/Backends/Peer2PeerBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,19 @@ Frame MinimumFrame2Players()
var queueConnected = true;
if (endpoints[i] is { IsRunning: true } endpoint)
queueConnected = endpoint.GetPeerConnectStatus(i, out _);

ref var localConn = ref localConnections[i];

if (!localConn.Disconnected)
totalMinConfirmed = Frame.Min(in localConnections[i].LastFrame, in totalMinConfirmed);

logger.Write(LogLevel.Trace,
$"Queue {i} => connected: {!localConn.Disconnected}; last received: {localConn.LastFrame}; min confirmed: {totalMinConfirmed}");
if (!queueConnected && !localConn.Disconnected)

if (!queueConnected && !localConn.Disconnected && endpoints[i] is { Player: var handler })
{
logger.Write(LogLevel.Information, $"disconnecting {i} by remote request");
PlayerHandle handle = new(PlayerType.Remote, i);
DisconnectPlayerQueue(in handle, in totalMinConfirmed);
DisconnectPlayerQueue(in handler, in totalMinConfirmed);
}

logger.Write(LogLevel.Trace, $"Queue {i} => min confirmed = {totalMinConfirmed}");
Expand Down Expand Up @@ -608,10 +611,10 @@ Frame MinimumFrameNPlayers()
// check to see if this disconnect notification is further back than we've been before. If
// so, we need to re-adjust. This can happen when we detect our own disconnect at frame n
// and later receive a disconnect notification for frame n-1.
if (!localStatus.Disconnected || localStatus.LastFrame > queueMinConfirmed)
if ((!localStatus.Disconnected || localStatus.LastFrame > queueMinConfirmed)
&& endpoints[queue] is { Player: var handle })
{
logger.Write(LogLevel.Information, $"disconnecting queue {queue} by remote request");
PlayerHandle handle = new(PlayerType.Remote, queue);
DisconnectPlayerQueue(in handle, in queueMinConfirmed);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Backdash/Network/Protocol/Comm/ProtocolInputBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,22 @@ SendInputResult CreateInputMessage(out ProtocolMessage protocolMessage)
}

Trace.Assert(lastAckedInput.Frame.IsNull || lastAckedInput.Frame.Next() == lastAckFrame);

var current = pendingOutput.Peek();
var currentSize = inputSerializer.Serialize(in current.Data, currentBytes);
inputMessage.InputSize = (byte)currentSize;
inputMessage.StartFrame = current.Frame;

Trace.Assert(lastAckedInput.Frame.IsNull || lastAckedInput.Frame.Next() == inputMessage.StartFrame);

if (lastAckedInput.Frame.IsNull && lastSentSize < currentSize)
lastSentSize = currentSize;

if (lastAckSize is 0)
sendBuffer.Clear();
else
lastAckBytes[..lastAckSize].CopyTo(sendBuffer);

var compressor = InputEncoder.GetCompressor(in inputMessage, sendBuffer);
var count = pendingOutput.Count;
var n = 0;
Expand Down

0 comments on commit aae32f7

Please sign in to comment.