breaking: NetworkTransform sendIntervalMultiplier replaced by syncInterval math (#3895)

* repro

* force sendIntervalMultiplier based on syncInterval!

* Revert "repro"

This reverts commit e51c996fa6.

* cleanup

* fix

* hide

* property

* rmv

---------

Co-authored-by: mischa <info@noobtuts.com>
This commit is contained in:
mischa 2024-09-02 22:03:38 +02:00 committed by GitHub
parent 99ba539e04
commit 016b611b2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,10 +67,39 @@ public abstract class NetworkTransformBase : NetworkBehaviour
[Tooltip("Local by default. World may be better when changing hierarchy, or non-NetworkTransforms root position/rotation/scale values.")]
public CoordinateSpace coordinateSpace = CoordinateSpace.Local;
[Header("Send Interval Multiplier")]
[Tooltip("Check/Sync every multiple of Network Manager send interval (= 1 / NM Send Rate), instead of every send interval.\n(30 NM send rate, and 3 interval, is a send every 0.1 seconds)\nA larger interval means less network sends, which has a variety of upsides. The drawbacks are delays and lower accuracy, you should find a nice balance between not sending too much, but the results looking good for your particular scenario.")]
[Range(1, 120)]
public uint sendIntervalMultiplier = 1;
// TODO sendIntervalMultiplier was replaced by syncInterval for consistency with other NetworkBehaviours.
// for now, we simply calculate the multiplier based on syncInterval.
// in a future, we can remove this completely and replace with syncInterval math everywhere.
// the multiplier math isn't that simple, so for now this is a good solution!
public uint sendIntervalMultiplier
{
get
{
if (syncInterval > 0)
{
// if syncInterval is > 0, calculate how many multiples of NetworkManager.sendRate it is
//
// for example:
// NetworkServer.sendInterval is 1/60 = 0.16
// NetworkTransform.syncInterval is 0.5 (500ms).
// 0.5 / 0.16 = 3.125
// in other words: 3.125 x sendInterval
//
// note that NetworkServer.sendInterval is usually set on start.
// to make this work in Edit mode, make sure that NetworkManager
// OnValidate sets NetworkServer.sendInterval immediately.
float multiples = syncInterval / NetworkServer.sendInterval;
// syncInterval is always supposed to sync at a minimum of 1 x sendInterval.
// that's what we do for every other NetworkBehaviour since
// we only sync in Broadcast() which is called @ sendInterval.
return multiples > 1 ? (uint)Mathf.RoundToInt(multiples) : 1;
}
// if syncInterval is 0, use NetworkManager.sendRate (x1)
return 1;
}
}
[Header("Timeline Offset")]
[Tooltip("Add a small timeline offset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots.\nfixes: https://github.com/MirrorNetworking/Mirror/issues/3427")]
@ -116,13 +145,6 @@ protected virtual void Configure()
// set target to self if none yet
if (target == null) target = transform;
// time snapshot interpolation happens globally.
// value (transform) happens in here.
// both always need to be on the same send interval.
// force the setting to '0' in OnValidate to make it obvious that we
// actually use NetworkServer.sendInterval.
syncInterval = 0;
// Unity doesn't support setting world scale.
// OnValidate force disables syncScale in world mode.
if (coordinateSpace == CoordinateSpace.World) syncScale = false;