Refactor send and receive Orders loop

This commit is contained in:
teinarss
2021-05-27 19:29:10 +02:00
committed by abcdefg30
parent 5e1468facb
commit f3777a25e6
7 changed files with 152 additions and 54 deletions

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Network
}
Queue<Chunk> chunks = new Queue<Chunk>();
List<byte[]> sync = new List<byte[]>();
Queue<byte[]> sync = new Queue<byte[]>();
readonly int orderLatency;
int ordersFrame;
@@ -139,7 +139,7 @@ namespace OpenRA.Network
var ms = new MemoryStream(4 + syncData.Length);
ms.WriteArray(BitConverter.GetBytes(frame));
ms.WriteArray(syncData);
sync.Add(ms.GetBuffer());
sync.Enqueue(ms.GetBuffer());
// Store the current frame so Receive() can return the next chunk of orders.
ordersFrame = frame + orderLatency;
@@ -148,10 +148,7 @@ namespace OpenRA.Network
public void Receive(Action<int, byte[]> packetFn)
{
while (sync.Count != 0)
{
packetFn(LocalClientId, sync[0]);
sync.RemoveAt(0);
}
packetFn(LocalClientId, sync.Dequeue());
while (chunks.Count != 0 && chunks.Peek().Frame <= ordersFrame)
foreach (var o in chunks.Dequeue().Packets)