Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Assets/Mirror/Transports/Latency/LatencySimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down