2020-01-18 03:41:45 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
2020-03-09 16:22:33 +00:00
|
|
|
public class FpsCounter {
|
2020-03-07 17:40:21 +00:00
|
|
|
private readonly int[] frameTimes = new int[60];
|
2020-01-18 03:41:45 +00:00
|
|
|
private double fps = 0;
|
|
|
|
private int idx = 0;
|
|
|
|
|
|
|
|
public int Fps {
|
|
|
|
get => (int) Math.Ceiling(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 = (idx + 1) % frameTimes.Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|