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/FpsMeter.java

62 lines
1.0 KiB

package com.porcupine.time;
/**
* Class for counting FPS in games.<br>
* This class can be used also as a simple frequency meter - output is in Hz.
*
* @author Ondřej Hruška (MightyPork)
*/
public class FpsMeter {
private long frames = 0;
private long drops = 0;
private long lastTimeMillis = System.currentTimeMillis();
private long lastSecFPS = 0;
private long lastSecDrop = 0;
/**
* @return current second's FPS
*/
public long getFPS()
{
return lastSecFPS;
}
/**
* Notification that frame was rendered
*/
public void frame()
{
if (System.currentTimeMillis() - lastTimeMillis > 1000) {
lastSecFPS = frames;
lastSecDrop = drops;
frames = 0;
drops = 0;
lastTimeMillis = System.currentTimeMillis();
}
frames++;
}
/**
* Notification that some frames have been dropped
*
* @param dropped dropped frames
*/
public void drop(int dropped)
{
drops += dropped;
}
/**
* @return current second's dropped frames
*/
public long getDropped()
{
return lastSecDrop;
}
}