diff --git a/samples/SpaceWar/GameSessionFactory.cs b/samples/SpaceWar/GameSessionFactory.cs index 8c1d0d46..af2c08d5 100644 --- a/samples/SpaceWar/GameSessionFactory.cs +++ b/samples/SpaceWar/GameSessionFactory.cs @@ -63,7 +63,7 @@ public static IRollbackSession ParseArgs( var session = RollbackNetcode.CreateSession(port, options, new() { - // LogWriter = new FileLogWriter($"log_{localPlayer.Number}.log"), + // LogWriter = new Backdash.Core.FileTextLogWriter($"log_{localPlayer.Number}.log"), InputListener = saveInputsListener, }); diff --git a/samples/SpaceWar/scripts/windows/start_2players.cmd b/samples/SpaceWar/scripts/windows/start_2players.cmd index aaf531b4..1cb59642 100644 --- a/samples/SpaceWar/scripts/windows/start_2players.cmd +++ b/samples/SpaceWar/scripts/windows/start_2players.cmd @@ -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 \ No newline at end of file +popd diff --git a/src/Backdash/Backends/Peer2PeerBackend.cs b/src/Backdash/Backends/Peer2PeerBackend.cs index f1b3b354..8ea861ba 100644 --- a/src/Backdash/Backends/Peer2PeerBackend.cs +++ b/src/Backdash/Backends/Peer2PeerBackend.cs @@ -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}"); @@ -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); } } diff --git a/src/Backdash/Network/Protocol/Comm/ProtocolInputBuffer.cs b/src/Backdash/Network/Protocol/Comm/ProtocolInputBuffer.cs index a6725177..5d080a7b 100644 --- a/src/Backdash/Network/Protocol/Comm/ProtocolInputBuffer.cs +++ b/src/Backdash/Network/Protocol/Comm/ProtocolInputBuffer.cs @@ -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;