コード例 #1
0
 private NetMessageSimTick MakeMessage(SimTickData tick)
 {
     return(new NetMessageSimTick()
     {
         TickData = tick
     });
 }
コード例 #2
0
        void SendTickToConnectedPlayers(SimTickData tick)
        {
            var session = GetSession();

            if (session == null)
            {
                Debug.LogWarning("Cannot send sim ticks to clients because no session interface was found.");
                return;
            }

            session.SendNetMessage(MakeMessage(tick), OnlineService.OnlineInterface.SessionInterface.Connections);
        }
コード例 #3
0
        protected override void OnUpdate()
        {
            // this counter makes sure we construct ticks at the desired rate
            _tickTimeCounter += Time.DeltaTime * s_tickSpeed;

            _tickTimeCounter = Mathf.Min(_tickTimeCounter, (s_maxTicksPerFrame + 0.999f) * SimulationConstants.TIME_STEP_F);

            while (_tickTimeCounter > SimulationConstants.TIME_STEP_F)
            {
                if (_tickSystem.CanTick)
                {
                    // bundle them up in a tick
                    SimTickData tickData = new SimTickData()
                    {
                        InputSubmissions  = _inputSubmissionQueue.ToList(),
                        ExpectedNewTickId = FindExpectedNewTickId(),
                        RepackEntities    = _repackBeforeNextTick,
                        ChecksumAfter     = _checksumAfterNextTick,
                    };
                    _inputSubmissionQueue.Clear();
                    _repackBeforeNextTick  = false;
                    _checksumAfterNextTick = false;

                    var sendTickSystem = World.GetExistingSystem <SendSimulationTickSystem>();

                    if (sendTickSystem != null)
                    {
                        while (sendTickSystem.ExceedsSizeLimit(tickData))
                        {
                            _inputSubmissionQueue.Enqueue(tickData.InputSubmissions.Pop());
                        }

                        if (_inputSubmissionQueue.Count > 100)
                        {
                            Log.Warning("Too many sim inputs clugging the tick creation. Clearing the list...");
                            _inputSubmissionQueue.Clear();
                        }
                    }

                    sendTickSystem?.ConstructedTicks.Add(tickData);

                    // give tick to tick system
                    _tickSystem.AvailableTicks.Add(tickData);

                    Log.Info(SimulationIO.LogChannel, $"[{UnityEngine.Time.frameCount}] Construct tick '{tickData.ExpectedNewTickId}' with {tickData.InputSubmissions.Count} inputs. " +
                             $"{(_inputSubmissionQueue.Count > 0 ? $"{_inputSubmissionQueue.Count} input(s) were buffered onto the next tick because of size limit." : "")}");
                }


                _tickTimeCounter -= SimulationConstants.TIME_STEP_F;
            }
        }
コード例 #4
0
        public void UpdateSceneLoading()
        {
            if (_tickSystem.AvailableTicks.Count > 0)
            {
                SimTickData tick = _tickSystem.AvailableTicks.First();

                _tickId.Set(tick.ExpectedNewTickId); // clear ignore list if tick has changed
                if (_tickId.ClearDirty())
                {
                    _inputsToIgnore.Clear();
                }

                foreach (SimInputSubmission inputSubmission in tick.InputSubmissions)
                {
                    if (inputSubmission.Input is SimCommandLoadScene loadSceneCommand)
                    {
                        if (!IsLoading(loadSceneCommand.SceneName) && !_inputsToIgnore.Contains(loadSceneCommand))
                        {
                            // add input to 'ignore list' to make sure we don't load the same scenes over and over
                            _inputsToIgnore.Add(loadSceneCommand);

                            // prepare for entity injection (through convertion)
                            _simulationWorldSystem.RegisterIncomingEntityInjection(loadSceneCommand.SceneName);

                            // request load
                            _sceneLoads.Add(SceneService.Load(loadSceneCommand.SceneName, LoadSceneMode.Additive, LocalPhysicsMode.Physics3D));
                        }
                    }
                }
            }

            // clear when all scenes are loaded
            if (AreAllLoadsComplete())
            {
                _sceneLoadsToUnregisterOnUpdate.AddRange(_sceneLoads);
                _sceneLoads.Clear();
            }
        }
コード例 #5
0
        public bool ExceedsSizeLimit(SimTickData tick)
        {
            var message = MakeMessage(tick);

            return(NetSerializer.GetSerializedBitSize(message) > OnlineConstants.MAX_MESSAGE_SIZE_BITS);
        }