Skip to content

Commit

Permalink
NetworkTransform: explain that sendInterval is coupled with time inte…
Browse files Browse the repository at this point in the history
…rpolation interval; use OnValidate to force syncInterval so it's more obvious in the Inspector
  • Loading branch information
vis2k committed Oct 22, 2022
1 parent 38d94f3 commit dfd4d0b
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public abstract class NetworkTransformBase : NetworkBehaviour
// make sure to call this when inheriting too!
protected virtual void Awake() {}

protected virtual void OnValidate()
{
// time snapshot interpolation happens globally.
// value (transform) happens in here.
// both always need to be on the same send interval.
// force it in here.
syncInterval = NetworkServer.sendInterval;
}

// snapshot functions //////////////////////////////////////////////////
// construct a snapshot of the current state
// => internal for testing
Expand Down Expand Up @@ -169,7 +178,7 @@ protected virtual void OnClientToServerSync(Vector3? position, Quaternion? rotat
#if onlySyncOnChange_BANDWIDTH_SAVING
if (onlySyncOnChange)
{
double timeIntervalCheck = bufferResetMultiplier * NetworkServer.sendInterval;
double timeIntervalCheck = bufferResetMultiplier * syncInterval;

if (serverSnapshots.Count > 0 && serverSnapshots.Values[serverSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp)
{
Expand Down Expand Up @@ -232,7 +241,7 @@ protected virtual void OnServerToClientSync(Vector3? position, Quaternion? rotat
#if onlySyncOnChange_BANDWIDTH_SAVING
if (onlySyncOnChange)
{
double timeIntervalCheck = bufferResetMultiplier * NetworkServer.sendInterval;
double timeIntervalCheck = bufferResetMultiplier * syncInterval;

if (clientSnapshots.Count > 0 && clientSnapshots.Values[clientSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp)
{
Expand Down Expand Up @@ -300,7 +309,7 @@ void UpdateServer()
// authoritative movement done by the host will have to be broadcasted
// here by checking IsClientWithAuthority.
// TODO send same time that NetworkServer sends time snapshot?
if (NetworkTime.localTime >= lastServerSendTime + NetworkServer.sendInterval &&
if (NetworkTime.localTime >= lastServerSendTime + syncInterval && // same interval as time interpolation!
(!clientAuthority || IsClientWithAuthority))
{
// send snapshot without timestamp.
Expand Down Expand Up @@ -395,7 +404,7 @@ void UpdateClient()
// DO NOT send nulls if not changed 'since last send' either. we
// send unreliable and don't know which 'last send' the other end
// received successfully.
if (NetworkTime.localTime >= lastClientSendTime + NetworkServer.sendInterval)
if (NetworkTime.localTime >= lastClientSendTime + syncInterval) // same interval as time interpolation!
{
// send snapshot without timestamp.
// receiver gets it from batch timestamp to save bandwidth.
Expand Down

0 comments on commit dfd4d0b

Please sign in to comment.