Create TpsTracker.java
TPSFIX
This commit is contained in:
parent
6fd006280e
commit
2881e93f36
34
src/es/mesacarlos/webconsole/util/TpsTracker.java
Normal file
34
src/es/mesacarlos/webconsole/util/TpsTracker.java
Normal file
@ -0,0 +1,34 @@
|
||||
package es.mesacarlos.webconsole.util;
|
||||
|
||||
public class TpsTracker implements Runnable {
|
||||
public static int TICK_COUNT = 0;
|
||||
public static long[] TICKS = new long[600];
|
||||
public static long LAST_TICK = 0L;
|
||||
|
||||
public static double getTPS() {
|
||||
return getTPS(100);
|
||||
}
|
||||
|
||||
public static double getTPS(int ticks) {
|
||||
if (TICK_COUNT < ticks) {
|
||||
return 20.0;
|
||||
} else {
|
||||
int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
|
||||
long elapsed = System.currentTimeMillis() - TICKS[target];
|
||||
return (double)ticks / ((double)elapsed / 1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user