From 50d6a2cabf0b6c5387c948d333f63d8123b61383 Mon Sep 17 00:00:00 2001 From: mischa Date: Sun, 14 Jul 2024 10:35:46 +0200 Subject: [PATCH] NetworkIdentity: ServerDirtyMasks SyncMethod support! --- Assets/Mirror/Core/NetworkIdentity.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index 6148a478f..b012ba1c2 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -841,7 +841,11 @@ internal void OnStopLocalPlayer() // build dirty mask for server owner & observers (= all dirty components). // faster to do it in one iteration instead of iterating separately. - (ulong, ulong) ServerDirtyMasks(bool initialState) + // -> initialState: marks all components for spawn message no matter the method. + // -> delta sync: depends on SyncMethod + // Traditional: mark the dirty components + // FastPaced: mark all components (unreliable isn't guaranteed to be delivered) + (ulong, ulong) ServerDirtyMasks(bool initialState, SyncMethod method) { ulong ownerMask = 0; ulong observerMask = 0; @@ -852,7 +856,20 @@ internal void OnStopLocalPlayer() NetworkBehaviour component = components[i]; ulong nthBit = (1u << i); - bool dirty = component.IsDirty(); + // for initial sync, include all components. + // for delta sync, it depends... + bool delta = false; + + // traditional: only if dirty bits were set + if (method == SyncMethod.Traditional && component.syncMethod == SyncMethod.Traditional) + { + delta = component.IsDirty(); + } + // fast paced: always include the component since unreliable message isn't guaranteed to be delivered + else if (method == SyncMethod.FastPaced && component.syncMethod == SyncMethod.FastPaced) + { + delta = true; + } // owner needs to be considered for both SyncModes, because // Observers mode always includes the Owner. @@ -860,7 +877,7 @@ internal void OnStopLocalPlayer() // for initial, it should always sync owner. // for delta, only for ServerToClient and only if dirty. // ClientToServer comes from the owner client. - if (initialState || (component.syncDirection == SyncDirection.ServerToClient && dirty)) + if (initialState || (component.syncDirection == SyncDirection.ServerToClient && delta)) ownerMask |= nthBit; // observers need to be considered only in Observers mode, @@ -871,7 +888,7 @@ internal void OnStopLocalPlayer() // for delta, only if dirty. // SyncDirection is irrelevant, as both are broadcast to // observers which aren't the owner. - if (initialState || dirty) + if (initialState || delta) observerMask |= nthBit; } }