From bce6b329c289b30e0ff755000076fa1d9d3ebbf8 Mon Sep 17 00:00:00 2001 From: Marro64 Date: Thu, 11 Jun 2026 12:25:12 +0200 Subject: [PATCH] Improved network accuracy --- Assets/Scenes/PacMan.unity | 8 +++++++ Assets/Scripts/NetworkManager.cs | 37 ++++++++++++++++++-------------- Assets/Scripts/PacMan.cs | 1 + 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Assets/Scenes/PacMan.unity b/Assets/Scenes/PacMan.unity index 3eae7ed..c23d41c 100644 --- a/Assets/Scenes/PacMan.unity +++ b/Assets/Scenes/PacMan.unity @@ -6048,6 +6048,10 @@ PrefabInstance: propertyPath: serializationData.Prefab value: objectReference: {fileID: 3521573303519548534, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} + - target: {fileID: 3555002988650332767, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} + propertyPath: m_LocalPosition.x + value: -0.2 + objectReference: {fileID: 0} - target: {fileID: 3559251034056489513, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} propertyPath: serializationData.Prefab value: @@ -13506,6 +13510,10 @@ PrefabInstance: propertyPath: serializationData.Prefab value: objectReference: {fileID: 3521573303519548534, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} + - target: {fileID: 3555002988650332767, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} + propertyPath: m_LocalPosition.x + value: 0.91 + objectReference: {fileID: 0} - target: {fileID: 3559251034056489513, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} propertyPath: serializationData.Prefab value: diff --git a/Assets/Scripts/NetworkManager.cs b/Assets/Scripts/NetworkManager.cs index 1b01f0b..272875c 100644 --- a/Assets/Scripts/NetworkManager.cs +++ b/Assets/Scripts/NetworkManager.cs @@ -386,25 +386,10 @@ namespace Marro.PacManUdon // Get our target time UpdateInternalTime(); - if (Ready) - { - if (IsOwner) - { - ProcessEventsToSend(); // Prepare events from last cycle - ProgressPingTime(); // See if we need to send a ping - } - else - { - ApplyReceivedEvents(); // See if there's events that need to be replayed - } - } - // Forwards simulated time by updateDelta until we're caught up while (nextUpdateTime <= internalTime) { - ProgressSyncedTime(nextUpdateTime); PerformFixedSyncedUpdate(); - nextUpdateTime = SyncedTime + updateDelta; } } @@ -432,6 +417,26 @@ namespace Marro.PacManUdon } private void PerformFixedSyncedUpdate() + { + if (Ready) + { + if (IsOwner) + { + ProcessEventsToSend(); // Prepare events from last cycle + ProgressPingTime(); // See if we need to send a ping + } + else + { + ApplyReceivedEvents(); // See if there's events after last update that need to be replayed + } + } + + ProgressSyncedTime(nextUpdateTime); + CallSyncedUpdate(); + nextUpdateTime = SyncedTime + updateDelta; + } + + private void CallSyncedUpdate() { IsEventUpdate = false; @@ -817,7 +822,7 @@ namespace Marro.PacManUdon { IsEventUpdate = true; - while (eventsQueueIndex > 0 && nextEventTime <= internalTime) + while (eventsQueueIndex > 0 && nextEventTime <= SyncedTime) { var success = ApplyEvent(eventsQueue[0]); diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 64e2c67..ad8c651 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -370,6 +370,7 @@ namespace Marro.PacManUdon { index += 8; base.ConsumeSyncedData(data, ref index, eventType); + return true; } SetTargetDirection(data.ReadVector2(ref index));