35 lines
923 B
Java
35 lines
923 B
Java
package eu.univento.commons.server;
|
|
|
|
public class TPS implements Runnable {
|
|
private static int TICK_COUNT = 0;
|
|
private static long[] TICKS = new long[600];
|
|
private static long LAST_TICK = 0L;
|
|
|
|
public static double getTPS() {
|
|
return getTPS(100);
|
|
}
|
|
|
|
private static double getTPS(int ticks) {
|
|
if (TICK_COUNT < ticks) {
|
|
return 20.0D;
|
|
}
|
|
int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
|
|
long elapsed = System.currentTimeMillis() - TICKS[target];
|
|
|
|
return ticks / (elapsed / 1000.0D);
|
|
}
|
|
|
|
private static long getElapsed(int tickID) {
|
|
if (TICK_COUNT - tickID >= TICKS.length) {
|
|
}
|
|
|
|
long time = TICKS[(tickID % TICKS.length)];
|
|
return System.currentTimeMillis() - time;
|
|
}
|
|
|
|
public void run() {
|
|
TICKS[(TICK_COUNT % TICKS.length)] = System.currentTimeMillis();
|
|
|
|
TICK_COUNT += 1;
|
|
}
|
|
} |