using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Foresight.Engine { public class FrameCounter { private double _currFrameTime; private readonly double _weight; private readonly int _numerator; public FrameCounter(int frameWeight) { _numerator = frameWeight; _weight = frameWeight / (frameWeight - 1d); } 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 MaximumSamples = 100; private readonly Queue _sampleBuffer = new Queue(); public bool Update(float deltaTime) { CurrentFramesPerSecond = 1.0f / deltaTime; _sampleBuffer.Enqueue(CurrentFramesPerSecond); if (_sampleBuffer.Count > MaximumSamples) { _sampleBuffer.Dequeue(); AverageFramesPerSecond = _sampleBuffer.Average(i => i); } else { AverageFramesPerSecond = CurrentFramesPerSecond; } TotalFrames++; TotalSeconds += deltaTime; return true; } public void Draw(SpriteBatch spriteBatch, Vector2 pos, Color? color = null) { } } }