#region Using Statements using System; using System.Reflection; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; #endregion namespace NekoCake { /// /// This is a game component that implements IUpdateable. /// public class pmv1 : Microsoft.Xna.Framework.DrawableGameComponent { private ContentManager content; // display varibles private SpriteBatch batch; private SpriteFont font; //FPS varibles private int totalFrames; private double currentFPS; private double averageFPS; private double highestFPS; private double lowestFPS = 999; // has to be initilised to a value over 0 //Frame Time varibles private double lastFrameTime; private double averageFrameTime; private double bestFrameTime = 999; // see lowestFPS private double worstFrameTime; // strings string output; //other GraphicsDeviceManager graphics; public pmv1(Game game, GraphicsDeviceManager graphics) : base(game) { this.graphics = graphics; } public override void Initialize() { content = new ContentManager(base.Game.Services); fontPos = new Vector2(100,100); base.Initialize(); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { batch = new SpriteBatch(graphics.GraphicsDevice); //load content files font = content.Load("assets\\font\\console"); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) { content.Unload(); } } public override void Update(GameTime gameTime) { // increment frame counter. totalFrames++; //fps calculations currentFPS = 1 / gameTime.ElapsedGameTime.TotalSeconds; averageFPS = totalFrames / gameTime.TotalGameTime.TotalSeconds; // highest fps (have to check if current fps is infinity, sometimes (mainly at the start of the program) currentFPS my be infinite! if (currentFPS > highestFPS && !double.IsInfinity(currentFPS)) highestFPS = currentFPS; // lowest fps if (currentFPS < lowestFPS) lowestFPS = currentFPS; //frame time calculations lastFrameTime = 1000 / currentFPS; averageFrameTime = gameTime.TotalGameTime.TotalMilliseconds / totalFrames; // best frame time if (lastFrameTime < bestFrameTime && lastFrameTime != 0) bestFrameTime = lastFrameTime; // worst if (lastFrameTime > worstFrameTime) worstFrameTime = lastFrameTime; //build the output string. output = "FPS Stats (Higher is better)\n CurrentFPS: " + currentFPS.ToString("##.##") + " \n Average FPS: " + averageFPS.ToString("##.##") + "\n Highest FPS: " + highestFPS.ToString("##.##") + "\n Lowest FPS: " + lowestFPS.ToString("##.##") + "\nFrame Time Stats (Lower is better) \n Last Frame Time: " + lastFrameTime.ToString("##.####") + "\n Average Frame Time: " + averageFrameTime.ToString("##.####") + " \n Best Frame Time: " + bestFrameTime.ToString("##.####") + " \n Wosrts Frame Time: " + worstFrameTime.ToString("##.####") + "\n \n \nTotal Frames: " + totalFrames.ToString() + "\nTime Running " + gameTime.TotalRealTime.ToString(); //base.Update(gameTime); } public override void Draw(GameTime gameTime) { batch.Begin(); batch.DrawString(font,output,Vector2.Zero,Color.White);//draw the text batch.End(); } } }