Skip to content

Commit

Permalink
Sync reaching 100% and complete
Browse files Browse the repository at this point in the history
  • Loading branch information
sbanca committed Dec 20, 2024
1 parent 491519d commit 98fd79f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Assets/Scripts/Multiplayer/MultiplayerSceneSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ void OnDestroy()

public void StartSyncronizationForUser(int id)
{
StartSynchHistory(id);
SendCurrentTargetEnvironmentCommand(); // TODO serialize the environmentand send it via large reliable data

switch (m_SyncType)
{
Expand All @@ -74,6 +72,10 @@ public void StartSyncronizationForUser(int id)
async void SendStrokesToPlayer(int id)
{
LinkedList<Stroke> strokes = SketchMemoryScript.m_Instance.GetMemoryList;

if (strokes.Count == 0) return;

SendCurrentTargetEnvironmentCommand();
StartSyncProgressDisplayForSrokes(id, strokes);
const int chunkSize = 5;
List<Stroke> strokeList = strokes.ToList();
Expand Down Expand Up @@ -152,6 +154,10 @@ public IEnumerator SendCommandHistory(int id)

CreateBrushStrokeCommands(strokesWithoutCommand, firstCommandTimestamp); // this add the strokes without commands to the IEnumerable<BaseCommand> commands

if (commands.Count() == 0) yield break;

SendCurrentTargetEnvironmentCommand();

StartSyncProgressDisplayForCommands(id, commands.ToList());

foreach (BaseCommand command in commands) MultiplayerManager.m_Instance.OnCommandPerformed(command);
Expand Down Expand Up @@ -197,12 +203,27 @@ public async void StartSyncProgressDisplayForSrokes(int TargetPlayerId, LinkedLi
StartSynchHistory(TargetPlayerId);

int sentStrokes = 0;

foreach (var stroke in strokes)
{
while (await MultiplayerManager.m_Instance.CheckStrokeReception(stroke, TargetPlayerId))
int retryCount = 0;
const int maxRetries = 3;
bool acknowledged = false;

while (retryCount < maxRetries)
{
if (await MultiplayerManager.m_Instance.CheckStrokeReception(stroke, TargetPlayerId))
{
acknowledged = true;
break;
}
retryCount++;
await Task.Delay(200);
}

if (!acknowledged)
ControllerConsoleScript.m_Instance.AddNewLine($"Stroke {stroke.m_Guid} failed to synchronize after {maxRetries} retries.");

sentStrokes++;
SynchHistoryPercentage(TargetPlayerId, strokes.Count, sentStrokes);
}
Expand Down

0 comments on commit 98fd79f

Please sign in to comment.