From f2a819c149b8071fb5badc83003304b7d1b06252 Mon Sep 17 00:00:00 2001 From: Robin Rolf Date: Thu, 16 Feb 2023 11:20:56 +0100 Subject: [PATCH] Comments --- Assets/Mirror/Core/NetworkConnection.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Assets/Mirror/Core/NetworkConnection.cs b/Assets/Mirror/Core/NetworkConnection.cs index 2062a320f..d5fbcaea8 100644 --- a/Assets/Mirror/Core/NetworkConnection.cs +++ b/Assets/Mirror/Core/NetworkConnection.cs @@ -44,12 +44,6 @@ public abstract class NetworkConnection // Works fine with NetworkIdentity pointers though. public readonly HashSet owned = new HashSet(); - // define batchers for both channels explicitly. - // Mirror only ever uses reliable and unreliable. - // this is faster than a Dict: - // https://github.com/MirrorNetworking/Mirror/pull/3382 - protected Batcher reliableBatcher; - protected Batcher unreliableBatcher; // batching from server to client & client to server. // fewer transport calls give us significantly better performance/scale. // @@ -58,7 +52,14 @@ public abstract class NetworkConnection // // depending on the transport, this can give 10x performance. // - // Dictionary because we have multiple channels. + // define batchers for the two default channels explicitly. + // Mirror only ever uses reliable and unreliable unless users specify their own channels in the few transports + // that support them + // this is faster than a Dict: + // https://github.com/MirrorNetworking/Mirror/pull/3382 + protected Batcher reliableBatcher; + protected Batcher unreliableBatcher; + // Any batchers for custom channels (not Reliable or Unreliable) are in here: protected Dictionary batches = new Dictionary(); /// last batch's remote timestamp. not interpolated. useful for NetworkTransform etc. @@ -113,6 +114,7 @@ protected Batcher GetBatchForChannelId(int channelId) return unreliableBatcher; } + // handle custom (not Reliable or Unreliable) channels // get existing or create new writer for the channelId Batcher batch; if (!batches.TryGetValue(channelId, out batch)) @@ -194,7 +196,8 @@ internal virtual void Send(ArraySegment segment, int channelId = Channels. protected abstract void SendToTransport(ArraySegment segment, int channelId = Channels.Reliable); internal void UpdateBatcher(int channelId, Batcher batcher) - { // make and send as many batches as necessary from the stored + { + // make and send as many batches as necessary from the stored // messages. using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { @@ -223,6 +226,9 @@ internal void UpdateBatcher(int channelId, Batcher batcher) // flush batched messages at the end of every Update. internal virtual void Update() { + // go through batches for all channels + + // mirror default ones (Reliable/Unreliable) if (reliableBatcher != null) { UpdateBatcher(Channels.Reliable, reliableBatcher); @@ -233,7 +239,7 @@ internal virtual void Update() UpdateBatcher(Channels.Unreliable, unreliableBatcher); } - // go through batches for all channels + // update custom (non-Reliable/Unreliable) channels // foreach ((int key, Batcher batcher) in batches) // Unity 2020 doesn't support deconstruct yet foreach (KeyValuePair kvp in batches) {