diff --git a/LiteEntitySystem/ClientEntityManager.cs b/LiteEntitySystem/ClientEntityManager.cs
index 629427a..60b84ba 100644
--- a/LiteEntitySystem/ClientEntityManager.cs
+++ b/LiteEntitySystem/ClientEntityManager.cs
@@ -94,6 +94,11 @@ public sealed class ClientEntityManager : EntityManager
///
public float NetworkJitter { get; private set; }
+ ///
+ /// Average jitter
+ ///
+ public float AverageJitter => _jitterMiddle;
+
///
/// Preferred input and incoming states buffer length in seconds lowest bound
/// Buffer automatically increases to Jitter time + PreferredBufferTimeLowest
@@ -178,6 +183,7 @@ public SyncCallInfo(OnSyncCallDelegate onSync, InternalEntity entity, int prevDa
private readonly float[] _jitterSamples = new float[10];
private int _jitterSampleIdx;
private readonly Stopwatch _jitterTimer = new();
+ private float _jitterPrevTime;
private float _jitterMiddle;
//local player
@@ -392,7 +398,9 @@ public unsafe DeserializeResult Deserialize(ReadOnlySpan inData)
}
//sample jitter
- _jitterSamples[_jitterSampleIdx] = _jitterTimer.ElapsedMilliseconds / 1000f;
+ float currentJitterTimer = _jitterTimer.ElapsedMilliseconds / 1000f;
+ _jitterSamples[_jitterSampleIdx] = Math.Abs(currentJitterTimer - _jitterPrevTime);
+ _jitterPrevTime = currentJitterTimer;
_jitterSampleIdx = (_jitterSampleIdx + 1) % _jitterSamples.Length;
//reset timer
_jitterTimer.Restart();
@@ -449,9 +457,9 @@ private bool PreloadNextState()
//get max and middle jitter
_jitterMiddle = 0f;
- for (int i = 0; i < _jitterSamples.Length - 1; i++)
+ for (int i = 0; i < _jitterSamples.Length; i++)
{
- float jitter = Math.Abs(_jitterSamples[i] - _jitterSamples[i + 1]);
+ float jitter = _jitterSamples[i];
if (jitter > NetworkJitter)
NetworkJitter = jitter;
_jitterMiddle += jitter;