mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: NetworkBehaviour dirty check uses double time (#2839)
This commit is contained in:
parent
28bcce7f0f
commit
d516280dca
@ -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.)")]
|
[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)]
|
[Range(0, 2)]
|
||||||
[HideInInspector] public float syncInterval = 0.1f;
|
[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>
|
/// <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
|
// 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.
|
// be called manually as well.
|
||||||
public void ClearAllDirtyBits()
|
public void ClearAllDirtyBits()
|
||||||
{
|
{
|
||||||
lastSyncTime = Time.time;
|
lastSyncTime = NetworkTime.localTime;
|
||||||
syncVarDirtyBits = 0L;
|
syncVarDirtyBits = 0L;
|
||||||
|
|
||||||
// flush all unsynchronized changes in syncobjects
|
// flush all unsynchronized changes in syncobjects
|
||||||
@ -508,7 +508,7 @@ bool AnySyncObjectDirty()
|
|||||||
// true if syncInterval elapsed and any SyncVar or SyncObject is dirty
|
// true if syncInterval elapsed and any SyncVar or SyncObject is dirty
|
||||||
public bool IsDirty()
|
public bool IsDirty()
|
||||||
{
|
{
|
||||||
if (Time.time - lastSyncTime >= syncInterval)
|
if (NetworkTime.localTime - lastSyncTime >= syncInterval)
|
||||||
{
|
{
|
||||||
return syncVarDirtyBits != 0L || AnySyncObjectDirty();
|
return syncVarDirtyBits != 0L || AnySyncObjectDirty();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public void TestSettingStruct()
|
|||||||
public void TestSyncIntervalAndClearDirtyComponents()
|
public void TestSyncIntervalAndClearDirtyComponents()
|
||||||
{
|
{
|
||||||
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
|
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
|
||||||
player.lastSyncTime = Time.time;
|
player.lastSyncTime = NetworkTime.localTime;
|
||||||
// synchronize immediately
|
// synchronize immediately
|
||||||
player.syncInterval = 1f;
|
player.syncInterval = 1f;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public void TestSyncIntervalAndClearDirtyComponents()
|
|||||||
player.netIdentity.ClearDirtyComponentsDirtyBits();
|
player.netIdentity.ClearDirtyComponentsDirtyBits();
|
||||||
|
|
||||||
// set lastSyncTime far enough back to be ready for syncing
|
// 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
|
// should be dirty now
|
||||||
Assert.That(player.IsDirty(), Is.True, "Sync interval met, should be dirty");
|
Assert.That(player.IsDirty(), Is.True, "Sync interval met, should be dirty");
|
||||||
@ -94,7 +94,7 @@ public void TestSyncIntervalAndClearDirtyComponents()
|
|||||||
public void TestSyncIntervalAndClearAllComponents()
|
public void TestSyncIntervalAndClearAllComponents()
|
||||||
{
|
{
|
||||||
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
|
CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out MockPlayer player);
|
||||||
player.lastSyncTime = Time.time;
|
player.lastSyncTime = NetworkTime.localTime;
|
||||||
// synchronize immediately
|
// synchronize immediately
|
||||||
player.syncInterval = 1f;
|
player.syncInterval = 1f;
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ public void TestSyncIntervalAndClearAllComponents()
|
|||||||
player.netIdentity.ClearAllComponentsDirtyBits();
|
player.netIdentity.ClearAllComponentsDirtyBits();
|
||||||
|
|
||||||
// set lastSyncTime far enough back to be ready for syncing
|
// 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
|
// should be dirty now
|
||||||
Assert.That(player.IsDirty(), Is.False, "Sync interval met, should still not be dirty");
|
Assert.That(player.IsDirty(), Is.False, "Sync interval met, should still not be dirty");
|
||||||
|
Loading…
Reference in New Issue
Block a user