using System;
using Microsoft.Xna.Framework;
namespace V3.Screens
{
///
/// Counts the frames per second based on the elapsed time and the number
/// of frames that have been drawn. Call Update in each Update, and
/// AddFrame in each Draw.
///
public sealed class FpsCounter
{
///
/// The current frames per second.
///
public int Fps { get; private set; }
private int mFrameCount;
private TimeSpan mTimeSpan = TimeSpan.Zero;
///
/// Updates the elapsed time and -- once every second -- the fps value.
///
/// the elapsed game time
public void Update(GameTime gameTime)
{
mTimeSpan += gameTime.ElapsedGameTime;
if (mTimeSpan > TimeSpan.FromSeconds(1))
{
mTimeSpan -= TimeSpan.FromSeconds(1);
Fps = mFrameCount;
mFrameCount = 0;
}
}
///
/// Registers that a frame has been drawn. Should be called once for
/// every Draw.
///
public void AddFrame()
{
mFrameCount++;
}
}
}