mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
LatencySimulation: SimulateLatency helper function
This commit is contained in:
parent
de076348c0
commit
1281f72ac2
@ -60,6 +60,20 @@ public void Awake()
|
||||
void OnEnable() { wrap.enabled = true; }
|
||||
void OnDisable() { wrap.enabled = false; }
|
||||
|
||||
// helper function to simulate latency
|
||||
float SimulateLatency(int channeldId)
|
||||
{
|
||||
switch (channeldId)
|
||||
{
|
||||
case Channels.Reliable:
|
||||
return reliableLatency;
|
||||
case Channels.Unreliable:
|
||||
return unreliableLatency;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to simulate a send with latency/loss/scramble
|
||||
void SimulateSend(int connectionId, int channelId, ArraySegment<byte> segment, float latency, List<QueuedMessage> reliableQueue, List<QueuedMessage> unreliableQueue)
|
||||
{
|
||||
@ -133,9 +147,7 @@ public override void ClientDisconnect()
|
||||
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
{
|
||||
float latency = channelId == Channels.Reliable
|
||||
? reliableLatency
|
||||
: unreliableLatency;
|
||||
float latency = SimulateLatency(channelId);
|
||||
SimulateSend(0, channelId, segment, latency, reliableClientToServer, unreliableClientToServer);
|
||||
}
|
||||
|
||||
@ -149,9 +161,7 @@ public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
{
|
||||
float latency = channelId == Channels.Reliable
|
||||
? reliableLatency
|
||||
: unreliableLatency;
|
||||
float latency = SimulateLatency(channelId);
|
||||
SimulateSend(connectionId, channelId, segment, latency, reliableServerToClient, unreliableServerToClient);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user