using System.Collections.Generic; using System.Linq; namespace xServer.Core.Helper { public class FrameCounter { public long TotalFrames { get; private set; } public float TotalSeconds { get; private set; } public float AverageFramesPerSecond { get; private set; } public float CurrentFramesPerSecond { get; private set; } public const int MAXIMUM_SAMPLES = 100; private Queue _sampleBuffer = new Queue(); public void Update(float deltaTime) { CurrentFramesPerSecond = 1.0f / deltaTime; _sampleBuffer.Enqueue(CurrentFramesPerSecond); if (_sampleBuffer.Count > MAXIMUM_SAMPLES) { _sampleBuffer.Dequeue(); AverageFramesPerSecond = _sampleBuffer.Average(i => i); } else { AverageFramesPerSecond = CurrentFramesPerSecond; } TotalFrames++; TotalSeconds += deltaTime; } } }