public void OnPausedUpdate()
        {
            if (!paused)
            {
                relativeClock.CurrentTime = currentTime;
            }

            PausedUpdate?.Invoke(this, EventArgs.Empty);
        }
Beispiel #2
0
        private void Updater()
        {
            _stopwatch.Start();
            while (CurrentState == TimerState.Active || CurrentState == TimerState.Paused)
            {
                while (CurrentState == TimerState.Paused)
                {
                    if (CurrentState == TimerState.Active || CurrentState == TimerState.Stopped)
                    {
                        break;
                    }
                    PausedUpdate?.Invoke(null, UpdateEventArgs.Empty);
                }

                _current = _stopwatch.Elapsed;
                _elapsed = _current - _last;
                _lag    += _elapsed;

                Update?.Invoke(this, new UpdateEventArgs()
                {
                    DeltaTime = _elapsed
                });
                Debugging.UpdateTime = (float)_elapsed.TotalSeconds;
                ticks++;

                Debugging.LagTime = (float)_lag.TotalSeconds * 1000.0f;

                while (_lag >= _updaterFrequency)
                {
                    FixedUpdate?.Invoke(this, new UpdateEventArgs()
                    {
                        DeltaTime = _elapsed + _lag
                    });
                    Debugging.FixedUpdateTime = ((float)_elapsed.TotalSeconds + (float)_lag.TotalSeconds);
                    fixedTicks++;
                    _lag -= _updaterFrequency;
                }

                _last            = _current;
                _tpsAccumulator += _elapsed;
                if (_tpsAccumulator >= TimeSpan.FromSeconds(1.0f))
                {
                    Debugging.TPS      = ticks;
                    Debugging.FixedTPS = fixedTicks;
                    ticks           = 0;
                    fixedTicks      = 0;
                    _tpsAccumulator = TimeSpan.Zero;
                }
            }
            if (CurrentState == TimerState.Paused || CurrentState == TimerState.Active)
            {
                Debugging.Log(LogEntryType.Warning, "Update timer was stopped unexpectedly!");
            }
        }