Pacman syncs really well now

This commit is contained in:
2026-01-16 20:36:21 +01:00
parent c41491e55e
commit 154c642cce
15 changed files with 1099 additions and 593 deletions

View File

@@ -122,6 +122,15 @@ namespace Marro.PacManUdon
/// </summary>
private bool serializationRequested;
/// <summary>
/// Events to send at the end of SyncedUpdate cycle
/// </summary>
private NetworkEventType[] eventsToSend;
/// <summary>
/// Index for <see cref="eventsToSend"/>
/// </summary>
private int eventsToSendIndex;
/// <summary>
/// Queue of events to be transmitted or processed.
/// </summary>
@@ -267,6 +276,11 @@ namespace Marro.PacManUdon
// Forwards simulated time at the FixedUpdate pace
PerformFixedSyncedUpdate();
if (IsOwner)
{
ProcessEventsToSend();
}
}
private void UpdateInternalTime()
@@ -316,7 +330,7 @@ namespace Marro.PacManUdon
}
else
{
SendEvent(NetworkEventType.FullSyncForced);
SendEventSoon(NetworkEventType.FullSyncForced);
}
}
@@ -332,7 +346,7 @@ namespace Marro.PacManUdon
#endregion
#region Sender
public void SendEvent(NetworkEventType eventType)
public void SendEventSoon(NetworkEventType eventType)
{
if (!Ready)
{
@@ -341,7 +355,40 @@ namespace Marro.PacManUdon
if (!IsOwner)
{
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Attempted {nameof(SendEvent)} while not the owner!");
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Attempted {nameof(SendEventSoon)} while not the owner!");
return;
}
if (eventsQueueIndex > eventsToSend.Length)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) {nameof(eventsToSend)} overflow!");
HandleError(false);
return;
}
eventsToSend[eventsToSendIndex++] = eventType;
}
private void ProcessEventsToSend()
{
for (int i = 0; i < eventsToSendIndex; i++)
{
SendEventNow(eventsToSend[0]);
}
eventsToSendIndex = 0;
}
public void SendEventNow(NetworkEventType eventType)
{
if (!Ready)
{
return;
}
if (!IsOwner)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Attempted {nameof(SendEventNow)} while not the owner!");
return;
}
@@ -426,10 +473,11 @@ namespace Marro.PacManUdon
if (eventType == NetworkEventType.FullSyncForced)
{
SendEvent(NetworkEventType.FullSync); // Remote is not allowed to request a forced full sync
SendEventSoon(NetworkEventType.FullSync); // Remote is not allowed to request a forced full sync
return;
}
SendEvent(eventType);
SendEventSoon(eventType);
}
private void ProgressPingTime()
@@ -587,6 +635,7 @@ namespace Marro.PacManUdon
if (Synced)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} blaat");
UpdateNextEventTime();
}
}
@@ -619,6 +668,7 @@ namespace Marro.PacManUdon
}
DequeueEventsFromBuffer(1);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} damn");
UpdateNextEventTime();
}
}
@@ -693,10 +743,14 @@ namespace Marro.PacManUdon
{
eventsQueue = new byte[BufferMaxTotalEvents][];
eventsQueueIndex = 0;
lastEventId = 0;
hasFullSyncReady = false;
eventTransmissionHistory = new int[maxEventSendTries];
eventTransmissionHistoryIndex = 0;
eventsQueueIndexAtLastTransmission = 0;
lastEventId = 0;
eventsToSend = new NetworkEventType[BufferMaxTotalEvents];
eventsToSendIndex = 0;
}
private void DequeueEventsFromBuffer(int eventCount)
@@ -822,7 +876,7 @@ namespace Marro.PacManUdon
if (newOwnerIsLocalPlayer)
{
SendEvent(NetworkEventType.FullSyncForced);
SendEventSoon(NetworkEventType.FullSyncForced);
}
}
#endregion
@@ -919,7 +973,7 @@ namespace Marro.PacManUdon
public void DoFullSync()
{
SendEvent(NetworkEventType.FullSync);
SendEventSoon(NetworkEventType.FullSync);
}
#endregion
}