Colin McMillen
80b6e2ac5c
rename gameTime -> time in Player GitOrigin-RevId: 0270c026e62acbc934127ec881a770de219e2fa1
27 lines
558 B
C#
27 lines
558 B
C#
using System;
|
|
|
|
namespace Jumpy {
|
|
class FpsCounter {
|
|
private double fps = 0;
|
|
private int[] frameTimes = new int[60];
|
|
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++;
|
|
if (idx == frameTimes.Length) {
|
|
idx = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|