perf: NetworkBehaviour.IsDirty: check bits before time

This commit is contained in:
vis2k 2022-10-25 19:05:10 +02:00
parent d05feed59e
commit 485b65f18d

View File

@ -170,8 +170,10 @@ public void SetSyncVarDirtyBit(ulong dirtyBit)
// OR both bitmasks. != 0 if either was dirty.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsDirty() =>
NetworkTime.localTime - lastSyncTime >= syncInterval &&
(syncVarDirtyBits | syncObjectDirtyBits) != 0UL;
// check bits first. this is basically free.
(syncVarDirtyBits | syncObjectDirtyBits) != 0UL &&
// only check time if bits were dirty. this is more expensive.
NetworkTime.localTime - lastSyncTime >= syncInterval;
/// <summary>Clears all the dirty bits that were set by SetDirtyBits()</summary>
// automatically invoked when an update is sent for this object, but can