Fix: #3120 Send Interval / Sync Interval Inaccuracy.
Resolves #3120 Send Interval / Sync Interval Inaccuracy.
Improves accuracy of send/sync intervals in NetworkAnimator, NetworkTransformBase, and NetworkBehavior sync vars.
Implemented enhancement based on @imerr suggestion in https://github.com/vis2k/Mirror/issues/3120#issuecomment-1076226260, instead of my error accumulator suggestion because it was simpler to implement and understand.
Accuracy of send/sync intervals is improved by using lastSendTime to keep track of late sends/syncs, and allowing followup sends/syncs to run slightly early. A threshold, of one sync interval, is used to reset lastSendTime in temporary cases of low FPS, freezes, or no changes occurring, to prevent lastSendTime from lagging behind afterwards and causing sends every frame.
Under normal circumstances, FPS >= Sync Rate, the overall send/sync rate will more accurately match the developer specified send/sync rate. The pacing between send/sync intervals will also be more consistent with the specified interval. The only real difference, is that send/syncs occasionally send slightly early, < syncInterval, to accommodate for send/syncs that were late. Under abnormal circumstances, FPS < Sync Rate, behavior will be the same as previously, syncing every frame.
Before:
| Game FPS | Specified Send Interval (Hz) | Actual Send Interval (Hz) | Interval Error % |
|---|---|---|---|
| ~160 | 60 | ~54 | 10% |
| 60 | 60 | ~40 | 33% |
| 60 | 30 | ~24 | 20% |
After:
| Game FPS | Specified Send Interval (Hz) | Actual Send Interval (Hz) | Interval Error % |
|---|---|---|---|
| ~160 | 60 | ~59.9 | 0.1% |
| 60 | 60 | ~59.8 | 0.3% |
| 60 | 30 | ~30 | 0.0% |
thanks for PR, gonna take a look asap
will backport my solution from mirro 2 soon. thanks for PR, very good
alright, I figured out a solution which is accurate (keeps the remainders), while also prevent catchup.
for example, say we have a 100ms interval. then server goes under heavy load, updates slow down to 1s.
first Update at t=1.0 would return true (interval has elapsed at least 10 times) next Update at t=1.0001 should return false(!)
if we were to do lastTime += interval, the next 10 updates would all return true instead. the solution is to % in order to ignore multiples of interval.
will backport soon..
AccurateInterval is merged. just need to use it here later.
@vis2k Can this be closed now, given work done more recently on NT?
yes, safe to close. AccurateInterval solves this.