package de.samdev.colorrunner.game.world;

import com.badlogic.gdx.utils.TimeUtils;

public class AverageExecutionLogger {
	private static final int UPDATE_COUNT = 60;
	
	private long on_time;
	
	private double average;
	private long sum;
	private int count;

	public AverageExecutionLogger() {
		average = 1;
		sum = 0;
		count = 0;
	}

	public void On() {
		on_time = TimeUtils.nanoTime();
	}

	public void Off() {
		sum += (TimeUtils.nanoTime() - on_time);
		count++;
		
		calc();
	}

	private void calc() {
		if (count >= UPDATE_COUNT) {
			average = (sum*1.0) / count;
			
			count = 0;
			sum = 0;
		}
	}

	public double getAvg() {
		return average/1000000.0;
	}
}
