Rogue: Savage Rats, a retro-themed dungeon crawler
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.
 
 
rogue-savage-rats/src/mightypork/gamecore/control/timing/FpsMeter.java

39 lines
762 B

package mightypork.gamecore.control.timing;
/**
* Class for counting FPS in games.<br>
* This class can be used also as a simple frequency meter - output is in Hz.
*
* @author MightyPork
*/
public class FpsMeter {
private long frames = 0;
private long lastTimeMillis = System.currentTimeMillis();
private long lastSecFPS = 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;
frames = 0;
final long over = System.currentTimeMillis() - lastTimeMillis - 1000;
lastTimeMillis = System.currentTimeMillis() - over;
}
frames++;
}
}