Skip to content

Commit b6d32f0

Browse files
fix: network time system tests should use double fixed delta time (#3373)
Adding the support to use a double delta time for NetworkTimeSystemTests. ## Changelog NA ## Testing and Documentation - Includes update to the `NetworkTimeSystemTests.CorrectAmountTicksTest` integration test. - No documentation changes or additions were necessary. <!-- Uncomment and mark items off with a * if this PR deprecates any API: ### Deprecated API - [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter yyyy-mm-dd)` entry. - [ ] An [api updater] was added. - [ ] Deprecation of the API is explained in the CHANGELOG. - [ ] The users can understand why this API was removed and what they should use instead. -->
1 parent 7d20da4 commit b6d32f0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

com.unity.netcode.gameobjects/Runtime/Timing/NetworkTime.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public struct NetworkTime
5050
/// </summary>
5151
public float FixedDeltaTime => (float)m_TickInterval;
5252

53+
/// <summary>
54+
/// Gets the fixed delta time as a double. This value is calculated by dividing 1.0 by the <see cref="TickRate"/> and stays constant.
55+
/// </summary>
56+
public double FixedDeltaTimeAsDouble => m_TickInterval;
57+
5358
/// <summary>
5459
/// Gets the amount of network ticks which have passed until reaching the current time value.
5560
/// </summary>

com.unity.netcode.gameobjects/Tests/Runtime/Timing/NetworkTimeSystemTests.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,34 @@ public IEnumerator PlayerLoopTimeTest_WithDifferentTimeScale([Values(0.0f, 0.1f,
6262
public IEnumerator CorrectAmountTicksTest()
6363
{
6464
NetworkTickSystem tickSystem = NetworkManager.Singleton.NetworkTickSystem;
65-
float delta = tickSystem.LocalTime.FixedDeltaTime;
65+
double delta = tickSystem.LocalTime.FixedDeltaTimeAsDouble;
6666
int previous_localTickCalculated = 0;
6767
int previous_serverTickCalculated = 0;
6868

6969
while (tickSystem.LocalTime.Time < 3f)
7070
{
7171
yield return null;
7272

73-
var tickCalculated = tickSystem.LocalTime.Time / delta;
74-
previous_localTickCalculated = (int)tickCalculated;
73+
var localTickCalculated = tickSystem.LocalTime.Time / delta;
74+
previous_localTickCalculated = (int)localTickCalculated;
7575

7676
// This check is needed due to double division imprecision of large numbers
77-
if ((tickCalculated - previous_localTickCalculated) >= 0.999999999999)
77+
if ((localTickCalculated - previous_localTickCalculated) >= 0.999999999999)
7878
{
7979
previous_localTickCalculated++;
8080
}
8181

82-
83-
tickCalculated = NetworkManager.Singleton.ServerTime.Time / delta;
84-
previous_serverTickCalculated = (int)tickCalculated;
82+
var serverTickCalculated = tickSystem.ServerTime.Time / delta;
83+
previous_serverTickCalculated = (int)serverTickCalculated;
8584

8685
// This check is needed due to double division imprecision of large numbers
87-
if ((tickCalculated - previous_serverTickCalculated) >= 0.999999999999)
86+
if ((serverTickCalculated - previous_serverTickCalculated) >= 0.999999999999)
8887
{
8988
previous_serverTickCalculated++;
9089
}
9190

92-
Assert.AreEqual(previous_localTickCalculated, NetworkManager.Singleton.LocalTime.Tick, $"Calculated local tick {previous_localTickCalculated} does not match local tick {NetworkManager.Singleton.LocalTime.Tick}!");
93-
Assert.AreEqual(previous_serverTickCalculated, NetworkManager.Singleton.ServerTime.Tick, $"Calculated server tick {previous_serverTickCalculated} does not match server tick {NetworkManager.Singleton.ServerTime.Tick}!");
91+
Assert.AreEqual(previous_localTickCalculated, NetworkManager.Singleton.LocalTime.Tick, $"Calculated local tick {previous_localTickCalculated} does not match local tick {NetworkManager.Singleton.LocalTime.Tick}!]n Local Tick-Calc: {localTickCalculated} LocalTime: {tickSystem.LocalTime.Time} | Server Tick-Calc: {serverTickCalculated} ServerTime: {tickSystem.ServerTime.Time} | TickDelta: {delta}");
92+
Assert.AreEqual(previous_serverTickCalculated, NetworkManager.Singleton.ServerTime.Tick, $"Calculated server tick {previous_serverTickCalculated} does not match server tick {NetworkManager.Singleton.ServerTime.Tick}!\n Local Tick-Calc: {localTickCalculated} LocalTime: {tickSystem.LocalTime.Time} | Server Tick-Calc: {serverTickCalculated} ServerTime: {tickSystem.ServerTime.Time} | TickDelta: {delta}");
9493
Assert.AreEqual((float)NetworkManager.Singleton.LocalTime.Time, (float)NetworkManager.Singleton.ServerTime.Time, $"Local time {(float)NetworkManager.Singleton.LocalTime.Time} is not approximately server time {(float)NetworkManager.Singleton.ServerTime.Time}!", FloatComparer.s_ComparerWithDefaultTolerance);
9594
}
9695
}

0 commit comments

Comments
 (0)