-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from LOLYAYDEV/master
Fix the 0 tps issue
- Loading branch information
Showing
3 changed files
with
39 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters