package de.frajul.particlelab.rendering;

/**
 * Created by Julian on 22.11.2015.
 */
public class Timer {

    private long lastFpsTime;
    private int fpsCounter;
    private int fps;

    private long lastTime;
    private long delta;


    public Timer() {
        lastTime = System.currentTimeMillis();
        lastFpsTime = lastTime;
    }

    public void update() {
        long currentTime = System.currentTimeMillis();
        delta = currentTime - lastTime;
        lastTime = currentTime;

        fpsCounter++;
        if (currentTime - lastFpsTime > 1000) {
            fps = fpsCounter;
            lastFpsTime += 1000;
            fpsCounter = 0;
        }
    }

    public float getFrameTime() {
        return delta;
    }

    public int getFps() {
        return fps;
    }

    public long getCurrentTime() {
        return System.currentTimeMillis();
    }

}
