sneak/Jumpy.Shared/FpsCount.cs
Colin McMillen 6659be3ec2 temp rename because Windows Git is bad
GitOrigin-RevId: c5cc586bcdba02b60e21b0a5620b18d3c86c7dd4
2020-02-13 14:45:40 -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;
}
}
}
}