package de.samdev.colorrunner.game.world;

import com.badlogic.gdx.utils.TimeUtils;

public class FPSCounter {

	private static final int UPDATE_TIME = 500;
	private double fps;
	private long lastUpdate;
	private int count;

	public FPSCounter() {
		fps = 1;
		lastUpdate = 0;
		count = 0;
	}

	public void Inc() {
		count++;
		calc();
	}

	private void calc() {
		long delta = TimeUtils.millis() - lastUpdate;
		if (delta > UPDATE_TIME) {
			fps = Math.max(1, (count * 1d) / (delta / 1000.0));
			count = 0;
			lastUpdate = TimeUtils.millis();
		}
	}

	public double getFPS() {
		return fps;
	}
}
