Commit 57f2ff6
authored
fix: NetworkTransform interpolation render time (#4133)
* test: Add NetworkTransform interpolation render time regression test
Adds an integration test that measures how far behind the server clock the
state a non-authority NetworkTransform is interpolating towards was sent.
Only states sent at or before the render time are eligible to be interpolated
towards, and the render time is the server clock minus the tick latency, so
that measurement can never be less than the tick latency. It currently is,
and goes negative, meaning the interpolator is chasing a state that the server
clock says has not happened yet.
An in-process integration test has effectively no round trip time, so the test
first widens the client's local time buffer to separate LocalTime and
ServerTime by a known amount and waits for that separation to take hold.
Without it the two clocks sit close enough together that the test would pass
regardless of which one the render time is derived from.
This commit contains the test only, so it can be run against an unfixed tree.
* fix: Derive NetworkTransform interpolation time from the server clock
A NetworkTransform state's SentTime comes from its NetworkTick, which is a
server tick, but the render time the interpolators were given was derived from
LocalTime. That mixes two clocks. LocalTime leads ServerTime, so subtracting
the tick latency from it lands the render time back at approximately ServerTime
rather than a whole tick latency behind it, and a state's SentTime is floored to
a tick boundary on top of that. The render time therefore sat at or ahead of the
newest state that could exist and the interpolator had nothing to interpolate
towards.
Measuring from ServerTime makes the offset the whole tick latency instead of
whatever is left of it, and is self correcting: as the round trip time grows the
tick latency grows and the render time moves further back with it. This also
matches the rest of the component, which already resets the interpolators using
ServerTime.
This is a no-op on a host or server, where the two clocks are the same, so it
only affects clients.
GetTickLatencyInSeconds returns an absolute time rather than a duration and had
the same defect, so it now derives from ServerTime as well. GetTickLatency is
left alone because it returns a tick count rather than a point in time.
* docs: Condense interpolation render time comments and changelog
Comment and changelog wording only, no behavioral or test logic changes.
Trims the explanation in UpdateInterpolation from twenty one lines to six and
drops the measurement anecdote and the unfilled Jira placeholder, keeping the
reason the server clock is the correct one to measure from. Shortens the test's
remarks and constant comments to match the density of the surrounding tests.
The removed detail, the measurements behind the fix, and the metrics that were
tried and rejected while building the test are recorded outside the repository.
* update
Adding PR number to changelog entries.
* fix: Return a duration from NetworkTransform.GetTickLatencyInSeconds
GetTickLatencyInSeconds returned TimeTicksAgo(...).Time, which is an absolute
network timestamp rather than a duration, so the value grew for as long as the
session ran. It is documented as returning the tick latency in seconds, and
NetworkTimeSystem.TickLatency points at it as a way to inspect that latency, so
the contract was misleading regardless of which clock it was measured from. It
now returns the tick count multiplied by the tick interval.
This also takes the clock question out of this method entirely, since a duration
does not reference LocalTime or ServerTime. The change to derive interpolation
render time from ServerTime now applies only to UpdateInterpolation.
Adds integration tests covering the documented contract: the value tracks the
tick latency rather than elapsed time, and lengthens by exactly the tick
interval for each tick of additional buffering. Both fail against the previous
implementation, the second regardless of how long the session has run, since
buffering more ticks used to make the reported latency smaller.
* style
Removing using directive for UnityEngine as it is an unused namespace.
* test: Tolerate an adaptive tick latency in the tick latency tests
NetworkTimeSystem.TickLatency is recomputed from the averaged round trip time
and can legitimately change mid-run. Both tests assumed it would not, and one
failed on macOS when it moved from two ticks to three, reporting the value as
having gone from 0.0666s to 0.1s.
The duration is now only held to being unchanged across samples where the tick
latency itself did not change, and the buffer offset test accounts for any tick
latency movement between its two samples so that only the buffering is held to
an exact figure.
Both still fail against the previous absolute timestamp implementation.
* test: Address review feedback on the render time and tick latency tests
- Drop the redundant HostOrServer fixture argument and the UseCMBService
override; Host is the default and a client-server fixture never runs
under the CMB service.
- Use WaitForSpawnedOnAllOrTimeOut, GetNonAuthorityNetworkManager and
WaitForTicks instead of hand rolled equivalents.
- There is only ever one connected client, so drop the collections and
refer to the single non-authority instance directly.
- Fold the two tick latency tests into one and drop the assertion that
recomputed the implementation's own formula. What is left is what can
actually regress: the value does not drift with session time, and it
grows by exactly the ticks added to the interpolation buffer.1 parent 2ea75a3 commit 57f2ff6
6 files changed
Lines changed: 257 additions & 9 deletions
File tree
- com.unity.netcode.gameobjects
- Runtime/Components
- Tests/Runtime/NetworkTransform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
Lines changed: 11 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4242 | 4242 | | |
4243 | 4243 | | |
4244 | 4244 | | |
4245 | | - | |
4246 | | - | |
4247 | | - | |
4248 | | - | |
4249 | | - | |
4250 | | - | |
4251 | | - | |
4252 | | - | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
4253 | 4252 | | |
4254 | 4253 | | |
4255 | 4254 | | |
| |||
4713 | 4712 | | |
4714 | 4713 | | |
4715 | 4714 | | |
4716 | | - | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
4717 | 4719 | | |
4718 | 4720 | | |
4719 | 4721 | | |
| |||
Lines changed: 147 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments