A stealth-based 2D platformer where you don't have to kill anyone unless you want to.
https://www.semicolin.games
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace SemiColinGames {
|
|
class Timer {
|
|
|
|
private readonly Stopwatch stopwatch = new Stopwatch();
|
|
private readonly double targetTime;
|
|
private readonly string name;
|
|
private double startTime = 0.0;
|
|
private int[] histogram = new int[41];
|
|
private int totalFrames = 0;
|
|
|
|
public Timer(double targetTime, string name) {
|
|
this.targetTime = targetTime;
|
|
this.name = name;
|
|
}
|
|
|
|
public void Start() {
|
|
startTime = stopwatch.Elapsed.TotalSeconds;
|
|
stopwatch.Start();
|
|
}
|
|
|
|
public void Stop() {
|
|
stopwatch.Stop();
|
|
totalFrames++;
|
|
double frameTime = stopwatch.Elapsed.TotalSeconds - startTime;
|
|
int bucket = FMath.Clamp((int) (5.0f * frameTime / targetTime), 0, 40);
|
|
histogram[bucket]++;
|
|
if (totalFrames % 100 == 0) {
|
|
DumpStats();
|
|
}
|
|
}
|
|
|
|
public void DumpStats() {
|
|
Debug.WriteLine(name + ".DumpStats():");
|
|
for (int i = 0; i < histogram.Length - 1; i++) {
|
|
int value = histogram[i];
|
|
if (value > 0) {
|
|
Debug.WriteLine($"{i * 5}-{(i + 1) * 5}%: {histogram[i]}");
|
|
}
|
|
}
|
|
Debug.WriteLine($"200+%: {histogram[histogram.Length - 1]}");
|
|
}
|
|
}
|
|
}
|