sneak/Jumpy.Shared/FPSCounter.cs
Colin McMillen 568bcf8071 add FPS counter
GitOrigin-RevId: 7186a6f3cd9ba35ff51b2232ebef67cbe3ad544c
2020-02-13 14:45:36 -05:00

27 lines
541 B
C#

using System;
namespace Jumpy {
class FpsCounter {
private double fps = 0;
private int[] frameTimes = new int[60];
private int idx = 0;
public double Fps {
get => fps;
}
public void Update() {
var now = Environment.TickCount; // ms
if (frameTimes[idx] != 0) {
var timeElapsed = now - frameTimes[idx];
fps = 1000.0 * frameTimes.Length / timeElapsed;
}
frameTimes[idx] = now;
idx++;
if (idx == frameTimes.Length) {
idx = 0;
}
}
}
}