From 7c8d2bd944f6c6f51105a8874de9d5a4ce5da708 Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 28 Nov 2021 17:10:08 +0100 Subject: [PATCH] feature: kcp2k: calculated max message sizes are now shown in Inspector (read only) for convenience --- .../KCP/MirrorTransport/KcpTransport.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs b/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs index 378c75c2c..a3fb897f6 100644 --- a/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs +++ b/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs @@ -4,6 +4,7 @@ using System.Net; using UnityEngine; using Mirror; +using Unity.Collections; namespace kcp2k { @@ -33,11 +34,17 @@ public class KcpTransport : Transport public bool CongestionWindow = false; // KCP 'NoCongestionWindow' is false by default. here we negate it for ease of use. [Tooltip("KCP window size can be modified to support higher loads.")] public uint SendWindowSize = 4096; //Kcp.WND_SND; 32 by default. Mirror sends a lot, so we need a lot more. - [Tooltip("KCP window size can be modified to support higher loads.")] + [Tooltip("KCP window size can be modified to support higher loads. This also increases max message size.")] public uint ReceiveWindowSize = 4096; //Kcp.WND_RCV; 128 by default. Mirror sends a lot, so we need a lot more. [Tooltip("Enable to use where-allocation NonAlloc KcpServer/Client/Connection versions. Highly recommended on all Unity platforms.")] public bool NonAlloc = true; + [Header("Calculated Max (based on Receive Window Size)")] + [Tooltip("KCP reliable max message size shown for convenience. Can be changed via ReceiveWindowSize.")] + [ReadOnly] public int ReliableMaxMessageSize = 0; // readonly, displayed from OnValidate + [Tooltip("KCP unreliable channel max message size for convenience. Not changeable.")] + [ReadOnly] public int UnreliableMaxMessageSize = 0; // readonly, displayed from OnValidate + // server & client (where-allocation NonAlloc versions) KcpServer server; KcpClient client; @@ -113,6 +120,13 @@ void Awake() Debug.Log("KcpTransport initialized!"); } + private void OnValidate() + { + // show max message sizes in inspector for convenience + ReliableMaxMessageSize = KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize); + UnreliableMaxMessageSize = KcpConnection.UnreliableMaxMessageSize; + } + // all except WebGL public override bool Available() => Application.platform != RuntimePlatform.WebGLPlayer;