tcr/java/src/game/util/PerfSection.java

57 lines
1,013 B
Java
Raw Normal View History

2025-03-11 14:09:49 +01:00
package game.util;
2025-03-18 10:24:05 +01:00
import game.window.Window;
2025-03-11 14:09:49 +01:00
public enum PerfSection {
TIMING("Timing"),
INPUT("Input"),
TICK("Tick"),
UPDATE("Update"),
RENDER("Render"),
GUI("Gui"),
REST("Rest"),
SWAP("Swap"),
EVENTS("Events"),
WAIT("Wait");
private static PerfSection section;
private static int swap;
private static long start;
private static long total;
private final String name;
private long time;
private long[] last = new long[2];
private PerfSection(String name) {
this.name = name;
}
public void enter() {
2025-03-18 10:24:05 +01:00
this.time = Window.getTime();
2025-03-11 14:09:49 +01:00
if(section != null)
section.last[swap] = section.time = this.time - section.time;
section = this;
}
public String getName() {
return this.name;
}
public long getLast() {
return this.last[swap ^ 1];
}
public static void swap() {
2025-03-18 10:24:05 +01:00
long current = Window.getTime();
2025-03-11 14:09:49 +01:00
total = current - start;
start = current;
swap ^= 1;
}
public static long getTotal(boolean wait) {
return total - (wait ? 0L : WAIT.getLast());
}
}