Exemplo n.º 1
0
        /// <summary>
        ///     Adds the current deltaTime to update ticks and processes simulated fixed update.
        /// </summary>
        private void UpdateTicks(float deltaTime)
        {
            updateTicks += deltaTime;
            while (updateTicks >= adjustedFixedUpdate)
            {
                updateTicks -= adjustedFixedUpdate;

                //If at maximum value then reset fixed frame.
                //This would probably break the game but even at 128t/s
                //it would take over a year of the server running straight to ever reach this value!
                if (FixedFrame == uint.MaxValue)
                {
                    FixedFrame = 0;
                }

                FixedFrame++;

                OnPreFixedUpdate?.Invoke();
                OnFixedUpdate?.Invoke();

                Physics2D.Simulate(Time.fixedDeltaTime);
                Physics.Simulate(Time.fixedDeltaTime);

                OnPostFixedUpdate?.Invoke();
            }

            //Recover timing towards default fixedDeltaTime.
            adjustedFixedUpdate =
                Mathf.MoveTowards(adjustedFixedUpdate, Time.fixedDeltaTime, TIMING_RECOVER_RATE * deltaTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes Fixed Update events.
        /// </summary>
        internal static void CallFixedUpdateEvents(GameTime gameTime)
        {
            _fixedUpdateTimer += gameTime.ElapsedGameTime.TotalSeconds;

            if (_fixedUpdateTimer >= GameMgr.FixedUpdateRate)
            {
                var overflow = (int)(_fixedUpdateTimer / GameMgr.FixedUpdateRate);                 // In case of lags.
                _fixedUpdateTimer -= GameMgr.FixedUpdateRate * overflow;

                TimeKeeper._elapsedTime = GameMgr.FixedUpdateRate;

                OnPreFixedUpdate?.Invoke();
                foreach (var scene in Scenes)
                {
                    if (scene.Enabled)
                    {
                        CurrentScene = scene;

                        scene.FixedUpdate();
                    }
                }
                OnPostFixedUpdate?.Invoke();
            }
        }