diff --git a/src/main/kotlin/com/lambda/module/hud/FPS.kt b/src/main/kotlin/com/lambda/module/hud/FPS.kt index 05d3185ec..e2ec81ae1 100644 --- a/src/main/kotlin/com/lambda/module/hud/FPS.kt +++ b/src/main/kotlin/com/lambda/module/hud/FPS.kt @@ -22,31 +22,40 @@ import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.module.HudModule import com.lambda.module.tag.ModuleTag +import com.lambda.util.collections.LimitedDecayQueue +import kotlin.time.Duration.Companion.seconds object FPS : HudModule( name = "FPS", description = "Displays your games frames per second", tag = ModuleTag.HUD ) { + val average by setting("Average", true) val updateDelay by setting("Update Delay", 50, 0..1000, 1, "Time between updating the fps value") + val frames = LimitedDecayQueue(Int.MAX_VALUE, 1.seconds.inWholeMilliseconds) var lastUpdated = System.currentTimeMillis() var lastFrameTime = System.nanoTime() var fps = 0 init { listen { - val currentTimeNano = System.nanoTime() + var currentFps = 0 + if (average) { + frames.add(Unit) + currentFps = frames.size + } else { + val currentTimeNano = System.nanoTime() + val elapsedNs = currentTimeNano - lastFrameTime + currentFps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt() else 0 + lastFrameTime = currentTimeNano + } val currentTypeMilli = System.currentTimeMillis() if (currentTypeMilli - lastUpdated >= updateDelay) { + fps = currentFps lastUpdated = currentTypeMilli - val elapsedNs = currentTimeNano - lastFrameTime - fps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt() - else 0 } - - lastFrameTime = currentTimeNano } } diff --git a/src/main/kotlin/com/lambda/module/hud/ModuleList.kt b/src/main/kotlin/com/lambda/module/hud/ModuleList.kt index 46c257649..9d2d3d592 100644 --- a/src/main/kotlin/com/lambda/module/hud/ModuleList.kt +++ b/src/main/kotlin/com/lambda/module/hud/ModuleList.kt @@ -28,7 +28,9 @@ object ModuleList : HudModule( name = "ModuleList", tag = ModuleTag.HUD, ) { - val onlyBound by setting("Only Bound", false, "Only displays modules with a keybind") + val onlyBound by setting("Only Bound", false, "Only displays modules with a keybind") + val showKeybind by setting("Show Keybind", true, "Display keybind next to a module") + init { drawSetting.value = false } @@ -39,10 +41,14 @@ object ModuleList : HudModule( enabled.forEach { val bound = it.keybind.key != 0 || it.keybind.mouse != -1 if (onlyBound && !bound) return@forEach - text(it.name); sameLine() - val color = if (!bound) Color.RED else Color.GREEN + text(it.name); + + if (showKeybind) { + val color = if (!bound) Color.RED else Color.GREEN - withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") } + sameLine() + withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") } + } } } }