fix(LatencySimulation): implement PortTransport since almost all underlying Transports are PortTransports (#3830)

* fix(LatencySimulation): implement PortTransport since almost all underlying Transports are PortTransports

* Update Assets/Mirror/Transports/Latency/LatencySimulation.cs

Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>

* Update Assets/Mirror/Transports/Latency/LatencySimulation.cs

Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>

---------

Co-authored-by: mischa <16416509+vis2k@users.noreply.github.com>
Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>
This commit is contained in:
mischa 2024-05-24 16:57:34 +02:00 committed by MrGadget
parent 2d97adeaf5
commit f51b7878f6

View File

@ -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 get Port but {wrap} is not a PortTransport.");
return 0;
}
set
{
if (wrap is PortTransport port)
{
port.Port = value;
return;
}
Debug.LogWarning($"LatencySimulation: attempted to set Port but {wrap} is not a 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!