The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.0.0-pre.4] - 2021-01-04 ### Added - Added `com.unity.modules.physics` and `com.unity.modules.physics2d` package dependencies (#1565) ### Removed - Removed `com.unity.modules.ai` package dependency (#1565) - Removed `FixedQueue`, `StreamExtensions`, `TypeExtensions` (#1398) ### Fixed - Fixed in-scene NetworkObjects that are moved into the DDOL scene not getting restored to their original active state (enabled/disabled) after a full scene transition (#1354) - Fixed invalid IL code being generated when using `this` instead of `this ref` for the FastBufferReader/FastBufferWriter parameter of an extension method. (#1393) - Fixed an issue where if you are running as a server (not host) the LoadEventCompleted and UnloadEventCompleted events would fire early by the NetworkSceneManager (#1379) - Fixed a runtime error when sending an array of an INetworkSerializable type that's implemented as a struct (#1402) - NetworkConfig will no longer throw an OverflowException in GetConfig() when ForceSamePrefabs is enabled and the number of prefabs causes the config blob size to exceed 1300 bytes. (#1385) - Fixed NetworkVariable not calling NetworkSerialize on INetworkSerializable types (#1383) - Fixed NullReferenceException on ImportReferences call in NetworkBehaviourILPP (#1434) - Fixed NetworkObjects not being despawned before they are destroyed during shutdown for client, host, and server instances. (#1390) - Fixed KeyNotFound exception when removing ownership of a newly spawned NetworkObject that is already owned by the server. (#1500) - Fixed NetworkManager.LocalClient not being set when starting as a host. (#1511) - Fixed a few memory leak cases when shutting down NetworkManager during Incoming Message Queue processing. (#1323) ### Changed - The SDK no longer limits message size to 64k. (The transport may still impose its own limits, but the SDK no longer does.) (#1384) - Updated com.unity.collections to 1.1.0 (#1451)
94 lines
3.4 KiB
C#
94 lines
3.4 KiB
C#
using System;
|
|
|
|
namespace Unity.Netcode
|
|
{
|
|
internal class ConnectionRtt
|
|
{
|
|
private double[] m_RttSendTimes; // times at which packet were sent for RTT computations
|
|
private int[] m_SendSequence; // tick, or other key, at which packets were sent (to allow matching)
|
|
private double[] m_MeasuredLatencies; // measured latencies (ring buffer)
|
|
private int m_LatenciesBegin = 0; // ring buffer begin
|
|
private int m_LatenciesEnd = 0; // ring buffer end
|
|
|
|
/// <summary>
|
|
/// Round-trip-time data
|
|
/// </summary>
|
|
public struct Rtt
|
|
{
|
|
public double BestSec; // best RTT
|
|
public double AverageSec; // average RTT
|
|
public double WorstSec; // worst RTT
|
|
public double LastSec; // latest ack'ed RTT
|
|
public int SampleCount; // number of contributing samples
|
|
}
|
|
|
|
public ConnectionRtt()
|
|
{
|
|
m_RttSendTimes = new double[NetworkConfig.RttWindowSize];
|
|
m_SendSequence = new int[NetworkConfig.RttWindowSize];
|
|
m_MeasuredLatencies = new double[NetworkConfig.RttWindowSize];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Round-trip-time computation for this client
|
|
/// </summary>
|
|
public Rtt GetRtt()
|
|
{
|
|
var ret = new Rtt();
|
|
var index = m_LatenciesBegin;
|
|
double total = 0.0;
|
|
ret.BestSec = m_MeasuredLatencies[m_LatenciesBegin];
|
|
ret.WorstSec = m_MeasuredLatencies[m_LatenciesBegin];
|
|
|
|
while (index != m_LatenciesEnd)
|
|
{
|
|
total += m_MeasuredLatencies[index];
|
|
ret.SampleCount++;
|
|
ret.BestSec = Math.Min(ret.BestSec, m_MeasuredLatencies[index]);
|
|
ret.WorstSec = Math.Max(ret.WorstSec, m_MeasuredLatencies[index]);
|
|
index = (index + 1) % NetworkConfig.RttAverageSamples;
|
|
}
|
|
|
|
if (ret.SampleCount != 0)
|
|
{
|
|
ret.AverageSec = total / ret.SampleCount;
|
|
// the latest RTT is one before m_LatenciesEnd
|
|
ret.LastSec = m_MeasuredLatencies[(m_LatenciesEnd + (NetworkConfig.RttWindowSize - 1)) % NetworkConfig.RttWindowSize];
|
|
}
|
|
else
|
|
{
|
|
ret.AverageSec = 0;
|
|
ret.BestSec = 0;
|
|
ret.WorstSec = 0;
|
|
ret.SampleCount = 0;
|
|
ret.LastSec = 0;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
internal void NotifySend(int sequence, double timeSec)
|
|
{
|
|
m_RttSendTimes[sequence % NetworkConfig.RttWindowSize] = timeSec;
|
|
m_SendSequence[sequence % NetworkConfig.RttWindowSize] = sequence;
|
|
}
|
|
|
|
internal void NotifyAck(int sequence, double timeSec)
|
|
{
|
|
// if the same slot was not used by a later send
|
|
if (m_SendSequence[sequence % NetworkConfig.RttWindowSize] == sequence)
|
|
{
|
|
double latency = timeSec - m_RttSendTimes[sequence % NetworkConfig.RttWindowSize];
|
|
|
|
m_MeasuredLatencies[m_LatenciesEnd] = latency;
|
|
m_LatenciesEnd = (m_LatenciesEnd + 1) % NetworkConfig.RttAverageSamples;
|
|
|
|
if (m_LatenciesEnd == m_LatenciesBegin)
|
|
{
|
|
m_LatenciesBegin = (m_LatenciesBegin + 1) % NetworkConfig.RttAverageSamples;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|