forked from stefatorus/LagAssist
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.
36 lines
858 B
36 lines
858 B
package com.entryrise.lagassist;
|
|
|
|
public class ExactTPS 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 - 1 < ticks) {
|
|
return 20.0D;
|
|
}
|
|
int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
|
|
long elapsed = System.currentTimeMillis() - TICKS[target];
|
|
|
|
return ticks / (elapsed / 1000.0D);
|
|
}
|
|
|
|
public static long getElapsed(int tickID) {
|
|
if (TICK_COUNT - tickID >= TICKS.length) {
|
|
}
|
|
|
|
long time = TICKS[(tickID % TICKS.length)];
|
|
return System.currentTimeMillis() - time;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
TICKS[(TICK_COUNT % TICKS.length)] = System.currentTimeMillis();
|
|
|
|
TICK_COUNT += 1;
|
|
}
|
|
}
|