mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
added an FPS counter to the demos
This commit is contained in:
parent
ab9e9f2a1b
commit
93a77b882f
1 changed files with 13 additions and 0 deletions
|
@ -14,6 +14,9 @@ namespace Demos {
|
||||||
|
|
||||||
private static readonly Dictionary<string, Func<MlemGame, Demo>> Demos = new Dictionary<string, Func<MlemGame, Demo>>();
|
private static readonly Dictionary<string, Func<MlemGame, Demo>> Demos = new Dictionary<string, Func<MlemGame, Demo>>();
|
||||||
private Demo activeDemo;
|
private Demo activeDemo;
|
||||||
|
private double fpsTime;
|
||||||
|
private int lastFps;
|
||||||
|
private int fpsCounter;
|
||||||
|
|
||||||
static GameImpl() {
|
static GameImpl() {
|
||||||
Demos.Add("Ui", game => new UiDemo(game));
|
Demos.Add("Ui", game => new UiDemo(game));
|
||||||
|
@ -68,6 +71,8 @@ namespace Demos {
|
||||||
PositionOffset = new Vector2(0, 1)
|
PositionOffset = new Vector2(0, 1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.UiSystem.Add("Fps", new Paragraph(Anchor.TopLeft, 1, p => "FPS: " + this.lastFps));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DoDraw(GameTime gameTime) {
|
protected override void DoDraw(GameTime gameTime) {
|
||||||
|
@ -77,6 +82,14 @@ namespace Demos {
|
||||||
this.GraphicsDevice.Clear(Color.CornflowerBlue);
|
this.GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
}
|
}
|
||||||
base.DoDraw(gameTime);
|
base.DoDraw(gameTime);
|
||||||
|
|
||||||
|
this.fpsCounter++;
|
||||||
|
this.fpsTime += gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
|
if (this.fpsTime >= 1) {
|
||||||
|
this.fpsTime -= 1;
|
||||||
|
this.lastFps = this.fpsCounter;
|
||||||
|
this.fpsCounter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DoUpdate(GameTime gameTime) {
|
protected override void DoUpdate(GameTime gameTime) {
|
||||||
|
|
Loading…
Reference in a new issue