fix: NetworkBehaviour dirty check uses double time (#2839)

This commit is contained in:
Robin Rolf 2021-07-16 06:18:59 +02:00 committed by GitHub
parent 28bcce7f0f
commit d516280dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -24,7 +24,7 @@ public abstract class NetworkBehaviour : MonoBehaviour
[Tooltip("Time in seconds until next change is synchronized to the client. '0' means send immediately if changed. '0.5' means only send changes every 500ms.\n(This is for state synchronization like SyncVars, SyncLists, OnSerialize. Not for Cmds, Rpcs, etc.)")]
[Range(0, 2)]
[HideInInspector] public float syncInterval = 0.1f;
internal float lastSyncTime;
internal double lastSyncTime;
/// <summary>True if this object is on the server and has been spawned.</summary>
// This is different from NetworkServer.active, which is true if the
@ -477,7 +477,7 @@ public void SetDirtyBit(ulong dirtyBit)
// be called manually as well.
public void ClearAllDirtyBits()
{
lastSyncTime = Time.time;
lastSyncTime = NetworkTime.localTime;
syncVarDirtyBits = 0L;
// flush all unsynchronized changes in syncobjects
@ -508,7 +508,7 @@ bool AnySyncObjectDirty()
// true if syncInterval elapsed and any SyncVar or SyncObject is dirty
public bool IsDirty()
{
if (Time.time - lastSyncTime >= syncInterval)
if (NetworkTime.localTime - lastSyncTime >= syncInterval)
{
return syncVarDirtyBits != 0L || AnySyncObjectDirty();
}

View File

@ -68,7 +68,7 @@ public void TestSettingStruct()
public void TestSyncIntervalAndClearDirtyComponents()
{
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
player.lastSyncTime = Time.time;
player.lastSyncTime = NetworkTime.localTime;
// synchronize immediately
player.syncInterval = 1f;
@ -84,7 +84,7 @@ public void TestSyncIntervalAndClearDirtyComponents()
player.netIdentity.ClearDirtyComponentsDirtyBits();
// set lastSyncTime far enough back to be ready for syncing
player.lastSyncTime = Time.time - player.syncInterval;
player.lastSyncTime = NetworkTime.localTime - player.syncInterval;
// should be dirty now
Assert.That(player.IsDirty(), Is.True, "Sync interval met, should be dirty");
@ -94,7 +94,7 @@ public void TestSyncIntervalAndClearDirtyComponents()
public void TestSyncIntervalAndClearAllComponents()
{
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
player.lastSyncTime = Time.time;
player.lastSyncTime = NetworkTime.localTime;
// synchronize immediately
player.syncInterval = 1f;
@ -110,7 +110,7 @@ public void TestSyncIntervalAndClearAllComponents()
player.netIdentity.ClearAllComponentsDirtyBits();
// set lastSyncTime far enough back to be ready for syncing
player.lastSyncTime = Time.time - player.syncInterval;
player.lastSyncTime = NetworkTime.localTime - player.syncInterval;
// should be dirty now
Assert.That(player.IsDirty(), Is.False, "Sync interval met, should still not be dirty");