Improving sync

This commit is contained in:
2026-06-22 18:31:16 +02:00
parent d6b870de79
commit 1252933ca4
7 changed files with 142 additions and 76 deletions

View File

@@ -16,7 +16,6 @@ namespace Marro.PacManUdon
[SerializeField] private GameObject intermissionScreen;
[SerializeField] private GameObject pressStartButtonScreen;
[SerializeField] private PlayerInput playerInput;
[SerializeField] private Animator demo;
[SerializeField] private SoundManager soundManager;
[SerializeField] private NetworkManager networkManagerSetup;
@@ -143,6 +142,7 @@ namespace Marro.PacManUdon
bonusFruit.Despawn();
soundManager.Reset();
collisionManager.Reset();
statusDisplay.Reset();
}
private void PrepareForCutscene()
@@ -263,7 +263,6 @@ namespace Marro.PacManUdon
statusDisplay.SetLevelDisplayVisible(false);
statusDisplay.SetPlayer1TextVisible(false);
statusDisplay.SetReadyTextVisible(false);
demo.gameObject.SetActive(false);
}
void SetPelletsActive(bool active)
@@ -373,6 +372,27 @@ namespace Marro.PacManUdon
soundManager.PlayExtraLifeSound();
}
private void SetupInGameState()
{
gameState = PacManGameState.InGame;
attractScreen.gameObject.SetActive(false);
SetPelletsActive(true);
SetMazeVisible(true);
SetGhostsActive(true);
SetPacManActive(true);
statusDisplay.SetExtraLivesDisplayVisible(true);
statusDisplay.SetLevelDisplayVisible(true);
statusDisplay.SetLabel1UPTextBlinking(true);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
SetFrozen(false);
}
public void SetFrozen(bool frozen, bool ghostIgnoreIfCaught = false, bool ghostKeepAnimating = false)
{
// Debug.Log($"{gameObject} Set Frozen: {frozen}");
@@ -389,6 +409,12 @@ namespace Marro.PacManUdon
return;
}
data.Append(gameState == PacManGameState.InGame, ref index);
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
data.Append(currentlyInTimeSequence, ref index);
if (currentlyInTimeSequence)
@@ -397,10 +423,6 @@ namespace Marro.PacManUdon
data.Append(timeSequenceSecondsPassed, ref index);
}
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
bonusFruit.CollectSyncedData(data, ref index, eventType);
collisionManager.CollectSyncedData(data, ref index, eventType);
@@ -425,22 +447,31 @@ namespace Marro.PacManUdon
return true;
}
var currentlyInTimeSequence = data.ReadBool(ref index);
if (currentlyInTimeSequence)
// If we're currently in-game, we'll need to make sure the state is setup correctly
var remoteCurrentlyInGame = data.ReadBool(ref index);
if (remoteCurrentlyInGame)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
else
{
TimeSequenceTryEndCurrent();
currentlyInTimeSequence = false; // Kill the current time sequence, otherwise it might interfere
// No need to run it to completion since we're overriding all state
SetupInGameState();
}
SetLevel(data.ReadByte(ref index));
SetScore(data.ReadInt(ref index));
SetExtraLives(data.ReadByte(ref index));
// Sync up with the remote's time sequence
var remoteCurrentlyInTimeSequence = data.ReadBool(ref index);
if (remoteCurrentlyInTimeSequence)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
// Note that we don't have any logic for if the remote is not in-game and not in a time sequence.
// Such a state should be impossible.
bonusFruit.WriteSyncedData(data, ref index, eventType);
collisionManager.WriteSyncedData(data, ref index, eventType);