Esempio n. 1
0
        public bool OnUpdate(float deltaTime)
        {
            _stopwatch.Stop();
            double elapsed = _stopwatch.Elapsed.TotalSeconds;

            _stopwatch.Restart();

            if (_game.type == FrameSyncGameType.Online && _game.gameState == FrameSyncGameState.Running)
            {
                _inputSampleTimer += deltaTime;
                int serverPlayerFrameCount = PlayerFrameCountOnServer;
                int localServerFrameCount  = LocalServerFrameCount;

                bool adjusted = false;

                if (_game.clientSidePrediction)
                {
                    FrameSyncTime.DoFixedTickIfNecessary((float)elapsed, serverPlayerFrameCount, () =>
                    {
                        if (_localCounter == 0)
                        {
                            _stopwatch1.Start();
                        }
                        _localCounter++;
                        SWConsole.Debug($"=====[OnUpdate] serverPlayerFrameCount={serverPlayerFrameCount} =====");
                        FlushInputOnlinePrediction();
                        RunningOnlineWithPrediction();

                        if (_localCounter == 900)
                        {
                            _stopwatch1.Stop();
                            double elapsed1 = _stopwatch1.Elapsed.TotalSeconds;
                            //SWConsole.Error($"elapsed={elapsed1}");
                        }
                    });
                }
                else
                {
                    adjusted = FrameSyncTime.Adjust(serverPlayerFrameCount, localServerFrameCount, deltaTime);

                    if (_inputSampleTimer > FrameSyncTime.internalInputSampleInterval)
                    {
                        _inputSampleTimer = 0;

                        FlushInputOnline();
                    }
                }

                return(adjusted);
            }

            return(false);
        }
Esempio n. 2
0
        public void StartGame()
        {
            if (_debuggerInterupt)
            {
                return;
            }

            Time.fixedDeltaTime = (float)_tickInterval;
            FrameSyncTime.Initialize(_tickInterval, _game.clientSidePrediction, FrameSyncConstant.DYNAMIC_ADJUST_INTERVAL, FrameSyncConstant.DYNAMIC_AVERAGE_COUNT);
            _cachedFixedUpdateTime = Time.fixedDeltaTime;


            _engine.SetFrameSyncGame(_game);
            _engine.Start();
        }