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.
48 lines
683 B
48 lines
683 B
10 years ago
|
package com.porcupine.time;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Timer for delta timing
|
||
|
*
|
||
|
* @author 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;
|
||
|
}
|
||
|
}
|