Skip to content

Commit ccd5026

Browse files
test
Made an adjustment to the InterpolatorTests.TestUpdatingInterpolatorWithNoData,. Also fixed the two tests that were disabled due to no extrapolation.
1 parent 1cf4f3d commit ccd5026

File tree

2 files changed

+5
-60
lines changed

2 files changed

+5
-60
lines changed

com.unity.netcode.gameobjects/Tests/Editor/InterpolatorTests.cs

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using NUnit.Framework;
32

43
namespace Unity.Netcode.EditorTests
@@ -105,7 +104,6 @@ public void OutOfOrderShouldStillWork()
105104
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(2f).Within(k_Precision));
106105
}
107106

108-
[Ignore("TODO: Fix this test to still handle testing message loss without extrapolation. This is tracked in MTT-11338")]
109107
[Test]
110108
public void MessageLoss()
111109
{
@@ -144,45 +142,7 @@ public void MessageLoss()
144142
serverTime += timeStep; // t = 3
145143
interpolator.UpdateInternal((float)timeStep, serverTime);
146144
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(2f));
147-
148-
// extrapolating to 2.5
149-
serverTime += timeStep; // t = 3.5d
150-
interpolator.UpdateInternal((float)timeStep, serverTime);
151-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(2.5f));
152-
153-
// next value skips to where it was supposed to be once buffer time is showing the next value
154-
serverTime += timeStep; // t = 4
155-
interpolator.UpdateInternal((float)timeStep, serverTime);
156-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(3f));
157-
158-
// interpolation continues as expected
159-
serverTime += timeStep; // t = 4.5
160-
interpolator.UpdateInternal((float)timeStep, serverTime);
161-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(3.5f));
162-
163-
serverTime += timeStep; // t = 5
164-
interpolator.UpdateInternal((float)timeStep, serverTime);
165-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(4f));
166-
167-
// lost time=6, extrapolating
168-
serverTime += timeStep; // t = 5.5
169-
interpolator.UpdateInternal((float)timeStep, serverTime);
170-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(4.5f));
171-
172-
serverTime += timeStep; // t = 6.0
173-
interpolator.UpdateInternal((float)timeStep, serverTime);
174-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(5f));
175-
176-
// misprediction
177-
serverTime += timeStep; // t = 6.5
178-
interpolator.UpdateInternal((float)timeStep, serverTime);
179-
Assert.That(interpolator.GetInterpolatedValue(), Is.EqualTo(5.5f));
180-
181-
// lerp to right value
182-
serverTime += timeStep; // t = 7.0
183-
interpolator.UpdateInternal((float)timeStep, serverTime);
184-
Assert.That(interpolator.GetInterpolatedValue(), Is.GreaterThan(6.0f));
185-
Assert.That(interpolator.GetInterpolatedValue(), Is.LessThanOrEqualTo(100f));
145+
// Since there is no extrapolation, the rest of this test was removed.
186146
}
187147

188148
[Test]
@@ -302,11 +262,10 @@ public void TestUpdatingInterpolatorWithNoData()
302262
{
303263
var interpolator = new BufferedLinearInterpolatorFloat();
304264
var serverTime = new NetworkTime(k_MockTickRate, 0.0d);
305-
// invalid case, this is undefined behaviour
306-
Assert.Throws<InvalidOperationException>(() => interpolator.UpdateInternal(1f, serverTime));
265+
var interpolatedValue = interpolator.UpdateInternal(1f, serverTime);
266+
Assert.IsTrue(interpolatedValue == 0.0f, $"Expected the result to be 0.0f but was {interpolatedValue}!");
307267
}
308268

309-
[Ignore("TODO: Fix this test to still test duplicated values without extrapolation. This is tracked in MTT-11338")]
310269
[Test]
311270
public void TestDuplicatedValues()
312271
{
@@ -340,22 +299,7 @@ public void TestDuplicatedValues()
340299
serverTime += 0.5d; // t = 3
341300
interp = interpolator.UpdateInternal(0.5f, serverTime);
342301
Assert.That(interp, Is.EqualTo(2f));
343-
344-
// with unclamped interpolation, we continue mispredicting since the two last values are actually treated as the same. Therefore we're not stopping at "2"
345-
serverTime += 0.5d; // t = 3.5
346-
interp = interpolator.UpdateInternal(0.5f, serverTime);
347-
Assert.That(interp, Is.EqualTo(2.5f));
348-
349-
serverTime += 0.5d; // t = 4
350-
interp = interpolator.UpdateInternal(0.5f, serverTime);
351-
Assert.That(interp, Is.EqualTo(3f));
352-
353-
// we add a measurement with an updated time
354-
var pastServerTime = new NetworkTime(k_MockTickRate, 3.0d);
355-
interpolator.AddMeasurement(2f, pastServerTime.Time);
356-
357-
interp = interpolator.UpdateInternal(0.5f, serverTime);
358-
Assert.That(interp, Is.EqualTo(2f));
302+
// Since there is no extrapolation, the rest of this test was removed.
359303
}
360304
}
361305
}

com.unity.netcode.gameobjects/Tests/Runtime/TransformInterpolationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ protected override void OnInitialize(ref NetworkTransformState replicatedState)
4343
m_LocalSpaceToggles = 0;
4444
m_FrameRateFractional = 1.0f / Application.targetFrameRate;
4545
PositionThreshold = MinThreshold;
46+
SetMaxInterpolationBound(1.0f);
4647
base.OnInitialize(ref replicatedState);
4748
}
4849

0 commit comments

Comments
 (0)