Exemplo n.º 1
0
        /// <summary>
        ///     This method is called every tick and checks if the waitTargetTime has already been reached.
        /// </summary>
        public static void ChangePauseStateIfNeeded()
        {
            if (_state == SpeedPauseState.WaitingForPause && GetCurrentTime() > _waitTargetTime)
            {
                SimulationManager.instance.SimulationPaused = true;
                _state = SpeedPauseState.PausedWaiting;
                SendReached();

                // Clear queued drop frames because we decided on an exact pause time, so the games are already in sync
                SlowdownHelper.ClearDropFrames();
            }
            else if (_state == SpeedPauseState.WaitingForSpeedChange && GetCurrentTime() > _waitTargetTime)
            {
                SimulationManager.instance.SelectedSimulationSpeed = _speed;
                _state = SpeedPauseState.PlayingWaiting;
                SendReached();

                // Don't clear dropped frames here because the game still continues.
                // Even if the current amount is not correct anymore because the dropped frames were
                // recorded while using a different speed, it's still an acceptable approximation.
            }
            else if (_state == SpeedPauseState.WaitingForPlay && DateTime.Now >= _waitTargetTime)
            {
                SimulationManager.instance.SimulationPaused        = false;
                SimulationManager.instance.SelectedSimulationSpeed = _speed;
                _state = SpeedPauseState.Playing;

                // Clear queued drop frames because those that arrived during paused state can be ignored
                SlowdownHelper.ClearDropFrames();
            }
        }