aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-11 11:40:24 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-11 11:40:24 +0100
commit20cbb7d8e48757ae21230a650dcee06a56aaa190 (patch)
tree8f9cd96d69a0f64829ec31b70cdb00857b5cb86c /src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt
parent45fdcb9d1de40bd9ae3a9784fe908f1191976507 (diff)
downloadskyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.tar.gz
skyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.tar.bz2
skyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.zip
added hot swap detection messages
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt b/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt
new file mode 100644
index 000000000..e3acc25e7
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/test/HotSwapDetection.kt
@@ -0,0 +1,53 @@
+package at.hannibal2.skyhanni.test
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.MinecraftData
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import kotlin.concurrent.fixedRateTimer
+
+object HotSwapDetection {
+ private val config get() = SkyHanniMod.feature.dev.debug
+
+ private var latestTick = 0
+ private var lastTps = 0
+ private var hotswap = false
+
+ init {
+ fixedRateTimer(name = "skyhanni-tps-counter-seconds", period = 1000L) {
+ val currentTick = MinecraftData.totalTicks
+ val diff = currentTick - latestTick
+ latestTick = currentTick
+
+ // we count 2 client ticks per tick, we are bad
+ handleTps(diff / 2)
+ }
+ }
+
+ private fun handleTps(tps: Int) {
+ if (!config.hotSwapDetection) return
+
+ // ignore below one minute
+ if (latestTick < 20 * 60) return
+
+ println("diff: $tps")
+
+ if (tps < 5) {
+ LorenzUtils.debug("Lags! Only $tps tps")
+ }
+
+ if (!hotswap) {
+ if (tps < 2) {
+ if (lastTps > 15) {
+ LorenzUtils.debug("Detected hotswap now!")
+ hotswap = true
+ }
+ }
+ } else {
+ if (tps > 15) {
+ hotswap = false
+ LorenzUtils.debug("Detected hotswap end!")
+ }
+ }
+ lastTps = tps
+ }
+}