LatencySimulation: spike latency via multiplier

This commit is contained in:
vis2k 2021-03-16 15:29:20 +08:00
parent 1281f72ac2
commit 83f8593caa

View File

@ -21,6 +21,10 @@ public class LatencySimulation : Transport
{
public Transport wrap;
[Header("Common")]
[Tooltip("Spike latency via Sin(Time) * multiplier")]
public float latencySineMultiplier;
[Header("Reliable Messages")]
[Tooltip("Reliable latency in seconds")]
public float reliableLatency;
@ -63,12 +67,16 @@ public void Awake()
// helper function to simulate latency
float SimulateLatency(int channeldId)
{
// spike over sine
float spike = (float)Math.Sin(Time.time) * latencySineMultiplier;
// base latency
switch (channeldId)
{
case Channels.Reliable:
return reliableLatency;
return reliableLatency + spike;
case Channels.Unreliable:
return unreliableLatency;
return unreliableLatency + spike;
default:
return 0;
}