//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynterEngine.Utilities
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
#endregion
using DarkWynterEngine.Globals;
using DarkWynterEngine.UserInterface;
///
/// Frames Per Second counter, drawn to screen.
///
public class FPSCounter
{
// Global Timers
TimeSpan elapsedTime = TimeSpan.Zero;
int frameRate = 0;
int frameCounter = 0;
///
/// Init Frames Per Second Counter
///
public FPSCounter() {}
///
/// Update the Frames Per Second counter
///
public void Update()
{
elapsedTime += Statics.SystemSettings.elementalGameTime.ElapsedGameTime;
if (elapsedTime > TimeSpan.FromSeconds(1))
{
elapsedTime -= TimeSpan.FromSeconds(1);
frameRate = frameCounter;
frameCounter = 0;
}
}
///
/// Draw the Frames Per Second counter
///
/// SpriteBatch used to draw used to draw.
public void Draw(SpriteBatch spriteBatch)
{
if (Statics.SystemSettings.enableFPSDisplay)
{
frameCounter++;
Statics.SystemSettings.graphics.GraphicsDevice.Viewport = Statics.RenderSettings.defaultViewport;
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.DrawString(FontWriter.Arial, frameRate.ToString(), new Vector2(20, 20), Color.Red);
spriteBatch.End();
}
}
}
}