package client.util;

import common.util.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() {
		this.time = Util.getTime();
		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() {
		long current = Util.getTime();
		total = current - start;
		start = current;
		swap ^= 1;
	}
	
	public static long getTotal(boolean wait) {
		return total - (wait ? 0L : WAIT.getLast());
	}
}
