Skip to content

Commit

Permalink
fix: NetworkBehaviour dirty check uses double time (#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
imerr committed Jul 16, 2021
1 parent 28bcce7 commit d516280
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Assets/Mirror/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Tests/Editor/SyncVarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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;

Expand All @@ -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");
Expand Down

0 comments on commit d516280

Please sign in to comment.