Created
July 9, 2011 16:46
-
-
Save MrSoundless/1073730 to your computer and use it in GitHub Desktop.
XNA FPS Meter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Linq; | |
| using Microsoft.Xna.Framework; | |
| namespace eindproject | |
| { | |
| public class FPSMeter : DrawableGameComponent | |
| { | |
| public FPSMeter(Game game) | |
| : base (game) | |
| { | |
| _updateTimes = new List<float>(); | |
| _drawTimes = new List<float>(); | |
| } | |
| public float DrawFPS | |
| { | |
| get { return _drawTimes.Count() / _drawTimes.Sum(); } | |
| } | |
| public float UpdateFPS | |
| { | |
| get { return _updateTimes.Count() / _updateTimes.Sum(); } | |
| } | |
| public override void Update(GameTime gameTime) | |
| { | |
| _updateTimes.Add((float)gameTime.ElapsedGameTime.TotalSeconds); | |
| while (_updateTimes.Sum() > 1f) | |
| _updateTimes.RemoveAt(0); | |
| } | |
| public override void Draw(GameTime gameTime) | |
| { | |
| _drawTimes.Add((float)gameTime.ElapsedGameTime.TotalSeconds); | |
| while (_drawTimes.Sum() > 1f) | |
| _drawTimes.RemoveAt(0); | |
| } | |
| private List<float> _updateTimes; | |
| private List<float> _drawTimes; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment