sneak/Jumpy.Shared/FpsCounter.cs
Colin McMillen 0d7af3edbe rename back to FpsCounter hopefully with right caps this time
GitOrigin-RevId: 8711e1d9064aef6d3e27d2cedac490681f3d3286
2020-02-13 14:45:44 -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;
}
}
}
}