Turtle programming game that was never finished to a playable state (but had cute graphics and sounds)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tortuga/src/com/porcupine/time/TimerDelta.java

47 lines
701 B

package com.porcupine.time;
/**
* Timer for delta timing
*
* @author Ondřej Hruška (MightyPork)
*/
public class TimerDelta {
private long lastFrame;
private static final long SECOND = 1000000000; // a million nanoseconds
/**
* New delta timer
*/
public TimerDelta() {
lastFrame = System.nanoTime();
}
/**
* Get current time in NS
*
* @return current time NS
*/
public long getTime()
{
return System.nanoTime();
}
/**
* Get time since the last "getDelta()" call.
*
* @return delta time (seconds)
*/
public double getDelta()
{
long time = getTime();
double delta = (time - lastFrame) / (double) SECOND;
lastFrame = time;
return delta;
}
}