2019-12-09 02:19:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2020-01-08 22:56:57 +00:00
|
|
|
|
namespace SemiColinGames {
|
2019-12-09 02:19:50 +00:00
|
|
|
|
class FpsCounter {
|
|
|
|
|
private double fps = 0;
|
|
|
|
|
private int[] frameTimes = new int[60];
|
|
|
|
|
private int idx = 0;
|
|
|
|
|
|
2019-12-09 04:02:22 +00:00
|
|
|
|
public int Fps {
|
|
|
|
|
get => (int) Math.Ceiling(fps);
|
2019-12-09 02:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2019-12-09 22:17:22 +00:00
|
|
|
|
idx = (idx + 1) % frameTimes.Length;
|
2019-12-09 02:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|