From 2881e93f361ee89d3b668a2c5c210200845819a8 Mon Sep 17 00:00:00 2001 From: LOLYAY <118024018+LOLYAYDEV@users.noreply.github.com> Date: Fri, 26 Jul 2024 22:43:39 +0200 Subject: [PATCH] Create TpsTracker.java TPSFIX --- .../webconsole/util/TpsTracker.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/es/mesacarlos/webconsole/util/TpsTracker.java diff --git a/src/es/mesacarlos/webconsole/util/TpsTracker.java b/src/es/mesacarlos/webconsole/util/TpsTracker.java new file mode 100644 index 0000000..e460efe --- /dev/null +++ b/src/es/mesacarlos/webconsole/util/TpsTracker.java @@ -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; + } +}