From 12c9474169208754ccab27a1a27e32fae9a717f5 Mon Sep 17 00:00:00 2001 From: mischa <16416509+vis2k@users.noreply.github.com> Date: Fri, 24 May 2024 11:10:54 +0200 Subject: [PATCH 1/3] fix(LatencySimulation): implement PortTransport since almost all underlying Transports are PortTransports --- .../Transports/Latency/LatencySimulation.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Transports/Latency/LatencySimulation.cs b/Assets/Mirror/Transports/Latency/LatencySimulation.cs index 0277d79604..60a6f2fe1c 100644 --- a/Assets/Mirror/Transports/Latency/LatencySimulation.cs +++ b/Assets/Mirror/Transports/Latency/LatencySimulation.cs @@ -22,10 +22,34 @@ struct QueuedMessage [HelpURL("https://mirror-networking.gitbook.io/docs/transports/latency-simulaton-transport")] [DisallowMultipleComponent] - public class LatencySimulation : Transport + public class LatencySimulation : Transport, PortTransport { public Transport wrap; + // implement PortTransport in case the underlying Tranpsport is a PortTransport too. + // otherwise gameplay code like 'if Transport is PortTransport' would completely break with Latency Simulation. + public ushort Port + { + get + { + if (wrap is PortTransport port) + return port.Port; + + Debug.LogWarning($"LatencySimulation: attempted to set Port but {wrap} is no PortTransport."); + return 0; + } + set + { + if (wrap is PortTransport port) + { + port.Port = value; + return; + } + + Debug.LogWarning($"LatencySimulation: attempted to get Port but {wrap} is no PortTransport."); + } + } + [Header("Common")] // latency always needs to be applied to both channels! // fixes a bug in prediction where predictedTime would have no latency, but [Command]s would have 100ms latency resulting in heavy, hard to debug jittering! From 8ef842e50d26321618016c7c8dc388361c21744d Mon Sep 17 00:00:00 2001 From: mischa <16416509+miwarnec@users.noreply.github.com> Date: Fri, 24 May 2024 16:56:16 +0200 Subject: [PATCH 2/3] Update Assets/Mirror/Transports/Latency/LatencySimulation.cs Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com> --- Assets/Mirror/Transports/Latency/LatencySimulation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Mirror/Transports/Latency/LatencySimulation.cs b/Assets/Mirror/Transports/Latency/LatencySimulation.cs index 60a6f2fe1c..0d0fe77c8c 100644 --- a/Assets/Mirror/Transports/Latency/LatencySimulation.cs +++ b/Assets/Mirror/Transports/Latency/LatencySimulation.cs @@ -46,7 +46,7 @@ public ushort Port return; } - Debug.LogWarning($"LatencySimulation: attempted to get Port but {wrap} is no PortTransport."); + Debug.LogWarning($"LatencySimulation: attempted to set Port but {wrap} is not a PortTransport."); } } From bc5953dbfd3c48eb00cd73c4a71a1b2965599137 Mon Sep 17 00:00:00 2001 From: mischa <16416509+miwarnec@users.noreply.github.com> Date: Fri, 24 May 2024 16:56:22 +0200 Subject: [PATCH 3/3] Update Assets/Mirror/Transports/Latency/LatencySimulation.cs Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com> --- Assets/Mirror/Transports/Latency/LatencySimulation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Mirror/Transports/Latency/LatencySimulation.cs b/Assets/Mirror/Transports/Latency/LatencySimulation.cs index 0d0fe77c8c..f4adf6af6c 100644 --- a/Assets/Mirror/Transports/Latency/LatencySimulation.cs +++ b/Assets/Mirror/Transports/Latency/LatencySimulation.cs @@ -35,7 +35,7 @@ public ushort Port if (wrap is PortTransport port) return port.Port; - Debug.LogWarning($"LatencySimulation: attempted to set Port but {wrap} is no PortTransport."); + Debug.LogWarning($"LatencySimulation: attempted to get Port but {wrap} is not a PortTransport."); return 0; } set