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

55 lines
981 B
Java
Raw Normal View History

2025-03-11 14:09:49 +01:00
package game.util;
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-05-04 00:56:38 +02:00
this.time = Util.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-05-04 00:56:38 +02:00
long current = Util.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());
}
}