//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Engine.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; using DarkWynter.Engine.Globals; using DarkWynter.Stream; #endregion /// /// Frames Per Second counter, drawn to screen. /// public class FPSCounter { // Global Timers TimeSpan elapsedTime = TimeSpan.Zero; private int _frameRate = 0; public int frameRate { get { return _frameRate; } set { _frameRate = value; } } private int _frameCounter = 0; public int frameCounter { get { return _frameCounter; } set { _frameCounter = value; } } private int _runTimeSum = 0; public int runTimeSum { get { return _runTimeSum; } set { _runTimeSum = value; } } private int _runTimeCycles = 1; public int runTimeCycles { get { return _runTimeCycles; } set { _runTimeCycles = value; } } /// /// Init Frames Per Second Counter /// public FPSCounter(bool visible) { //Statics_Engine.SystemSettings.enableFPSDisplay = visible; } /// /// Update the Frames Per Second counter /// public void Update() { elapsedTime += Statics_Engine.SystemSettings.elementalGameTime.ElapsedGameTime; if (elapsedTime > TimeSpan.FromSeconds(1)) { elapsedTime -= TimeSpan.FromSeconds(1); frameRate = frameCounter; frameCounter = 0; // MenuSystem framerates throw off calculations if (frameRate < 300) { runTimeSum += frameRate; runTimeCycles++; } } } /// /// Draw the Frames Per Second counter /// /// SpriteBatch used to draw used to draw. public void Draw(SpriteBatch spriteBatch) { if (Statics_Engine.SystemSettings.enableFPSDisplay) { frameCounter++; Statics_Stream.RenderSettings.graphics.GraphicsDevice.Viewport = Statics_Stream.RenderSettings.defaultViewport; spriteBatch.Begin(SpriteBlendMode.AlphaBlend); spriteBatch.DrawString(Statics_Stream.Fonts.Arial, frameRate.ToString(), new Vector2(20, 20), Color.Red); spriteBatch.DrawString(Statics_Stream.Fonts.Arial, (runTimeSum / runTimeCycles).ToString(), new Vector2(20, 40), Color.Green); spriteBatch.End(); } } } }