SimulationSyncFromTransferServerOperation LaunchSyncForClient(INetworkInterfaceConnection clientConnection) { Log.Info($"Starting new sync..."); var newOp = new SimulationSyncFromTransferServerOperation(_session, clientConnection, _simWorldSystem.SimulationWorld); _constructTickSystem.RequestRepackBeforeNextTick(); newOp.OnFailCallback = (op) => { Log.Info($"Sync failed. {op.Message}"); }; newOp.OnSucceedCallback = (op) => { Log.Info($"Sync complete. {op.Message}"); }; newOp.Execute(); _ongoingOperations.Add(newOp); if (s_pauseSimulationWhilePlayersAreJoining) { _tickSystem.PauseSimulation(key: "PlayerJoining"); } return(newOp); }
CoroutineOperation SyncSimulationWithServer() { if (IsSynchronizing) { Log.Warning("Trying to start a SimSync process while we are already in one"); return(null); } Debug.Log($"Starting sync (old world was at {_simWorldSystem.SimulationWorld.GetLastTickIdFromEntity()})"); _tickSystem.PauseSimulation(key: "sync"); _receiveTickSystem.ClearAccumulatedTicks(); _receiveTickSystem.StartShelvingTicks(); var newWorld = _simWorldSystem.CreateNewReplacementWorld(); _ongoingSyncOp = new SimulationSyncFromTransferClientOperation(_session, newWorld); _ongoingSyncOp.OnTerminateCallback = (op) => { // restore ticks we received while syncing _receiveTickSystem.StopShelvingTicks(); _tickSystem.UnpauseSimulation(key: "sync"); }; _ongoingSyncOp.OnSucceedCallback = (op) => { DebugScreenMessage.DisplayMessage($"Transfered sim. {op.Message}"); Debug.Log($"Post sync, restore shelve from {newWorld.GetLastTickIdFromEntity() + 1} (new world is at {newWorld.GetLastTickIdFromEntity()})"); _receiveTickSystem.ClearAccumulatedTicks(); _receiveTickSystem.RestoreTicksFromShelf(newWorld.GetLastTickIdFromEntity() + 1); _simWorldSystem.RequestReplaceSimWorld(newWorld); }; _ongoingSyncOp.OnFailCallback = (op) => { DebugScreenMessage.DisplayMessage($"Failed to sync sim. {op.Message}"); }; _ongoingSyncOp.Execute(); return(_ongoingSyncOp); }