diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-11 11:40:24 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-11 11:40:24 +0100 |
commit | 20cbb7d8e48757ae21230a650dcee06a56aaa190 (patch) | |
tree | 8f9cd96d69a0f64829ec31b70cdb00857b5cb86c | |
parent | 45fdcb9d1de40bd9ae3a9784fe908f1191976507 (diff) | |
download | skyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.tar.gz skyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.tar.bz2 skyhanni-20cbb7d8e48757ae21230a650dcee06a56aaa190.zip |
added hot swap detection messages
3 files changed, 64 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index b4a9a1c12..4006df431 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -289,6 +289,7 @@ import at.hannibal2.skyhanni.features.summonings.SummoningMobManager import at.hannibal2.skyhanni.features.summonings.SummoningSoulsName import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.test.HighlightMissingRepoItems +import at.hannibal2.skyhanni.test.HotSwapDetection import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.ParkourWaypointSaver import at.hannibal2.skyhanni.test.ShowItemUuid @@ -639,6 +640,8 @@ class SkyHanniMod { loadModule(HighlightMissingRepoItems()) loadModule(ParkourWaypointSaver()) loadModule(TestShowSlotNumber()) + loadModule(SkyHanniDebugsAndTests) + loadModule(HotSwapDetection) } @Mod.EventHandler diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java index be43a7526..4ee5f9469 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DevConfig.java @@ -34,9 +34,9 @@ public class DevConfig { @Expose @ConfigOption( - name = "Mod Menu Log", - desc = "Enables debug messages when the currently opened GUI changes, with the path to the gui class. " + - "Useful for adding more mods to quick mod menu switch." + name = "Mod Menu Log", + desc = "Enables debug messages when the currently opened GUI changes, with the path to the gui class. " + + "Useful for adding more mods to quick mod menu switch." ) @ConfigEditorBoolean public boolean modMenuLog = false; @@ -95,6 +95,11 @@ public class DevConfig { @ConfigOption(name = "Highlight Missing Repo Items", desc = "Highlights each item in the current inventory that is not in your current NEU repo.") @ConfigEditorBoolean public boolean highlightMissingRepo = false; + + @Expose + @ConfigOption(name = "Hot Swap Detection", desc = "Show chat messages when Hot Swap starts and ends.") + @ConfigEditorBoolean + public boolean hotSwapDetection = false; } @Expose 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 + } +} |