Пример #1
0
        protected override void OnUpdate()
        {
            if (_ongoingOperations.Count > 0)
            {
                for (int i = _ongoingOperations.Count - 1; i >= 0; i--)
                {
                    if (!_ongoingOperations[i].IsRunning)
                    {
                        _ongoingOperations.RemoveAt(i);
                    }
                }

                if (_ongoingOperations.Count == 0)
                {
                    _tickSystem.UnpauseSimulation(key: "PlayerJoining");
                }
            }
        }
Пример #2
0
        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);
        }