Skip to content
21 changes: 15 additions & 6 deletions src/main/kotlin/com/lambda/module/hud/FPS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit>(Int.MAX_VALUE, 1.seconds.inWholeMilliseconds)
var lastUpdated = System.currentTimeMillis()
var lastFrameTime = System.nanoTime()
var fps = 0

init {
listen<RenderEvent.Render> {
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
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/main/kotlin/com/lambda/module/hud/ModuleList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}]") }
}
}
}
}
Loading