/**
 * 
 */
package ei.engine.util;

import org.lwjgl.Sys;

/**
 * This class calculates the fps
 * @author Ziver
 *
 */
public class FpsTimer {
	// temp feald
	private long time;
	// The fps
	private float fps;
	
	/**
	 * Starts the timer
	 *
	 */
	public void startTimer(){
		if(Sys.getTime() > 0){
			time = Sys.getTime();
		}
		else{
			time = System.currentTimeMillis();
		}
	}
	
	/**
	 * Stops the timer and calculates the fps
	 *
	 */
	public void stopTimer(){
		if(Sys.getTime() > 0){
			time = Sys.getTime() - time;
		}
		else{
			time = System.currentTimeMillis() - time;
		}
		
		// calculate the fps
		fps = (float)1000/time;
		// round the fps to one decimal
		fps = (float)((int)(fps * 10))/10;
	}
	
	/**
	 * Returns the fps
	 * 
	 * @return The fps
	 */
	public float getFps(){
		return fps;
	}
}
