Skip to content

Commit 303a989

Browse files
authored
feat: add more hud settings (#192)
added following setting to hud modules: - `Show Keybind` to `ModuleList` - `Average` to `FPS`
1 parent 642f448 commit 303a989

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/main/kotlin/com/lambda/module/hud/FPS.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,40 @@ import com.lambda.event.listener.SafeListener.Companion.listen
2222
import com.lambda.gui.dsl.ImGuiBuilder
2323
import com.lambda.module.HudModule
2424
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.collections.LimitedDecayQueue
26+
import kotlin.time.Duration.Companion.seconds
2527

2628
object FPS : HudModule(
2729
name = "FPS",
2830
description = "Displays your games frames per second",
2931
tag = ModuleTag.HUD
3032
) {
33+
val average by setting("Average", true)
3134
val updateDelay by setting("Update Delay", 50, 0..1000, 1, "Time between updating the fps value")
3235

36+
val frames = LimitedDecayQueue<Unit>(Int.MAX_VALUE, 1.seconds.inWholeMilliseconds)
3337
var lastUpdated = System.currentTimeMillis()
3438
var lastFrameTime = System.nanoTime()
3539
var fps = 0
3640

3741
init {
3842
listen<RenderEvent.Render> {
39-
val currentTimeNano = System.nanoTime()
43+
var currentFps = 0
44+
if (average) {
45+
frames.add(Unit)
46+
currentFps = frames.size
47+
} else {
48+
val currentTimeNano = System.nanoTime()
49+
val elapsedNs = currentTimeNano - lastFrameTime
50+
currentFps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt() else 0
51+
lastFrameTime = currentTimeNano
52+
}
4053

4154
val currentTypeMilli = System.currentTimeMillis()
4255
if (currentTypeMilli - lastUpdated >= updateDelay) {
56+
fps = currentFps
4357
lastUpdated = currentTypeMilli
44-
val elapsedNs = currentTimeNano - lastFrameTime
45-
fps = if (elapsedNs > 0) (1000000000 / elapsedNs).toInt()
46-
else 0
4758
}
48-
49-
lastFrameTime = currentTimeNano
5059
}
5160
}
5261

src/main/kotlin/com/lambda/module/hud/ModuleList.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ object ModuleList : HudModule(
2828
name = "ModuleList",
2929
tag = ModuleTag.HUD,
3030
) {
31-
val onlyBound by setting("Only Bound", false, "Only displays modules with a keybind")
31+
val onlyBound by setting("Only Bound", false, "Only displays modules with a keybind")
32+
val showKeybind by setting("Show Keybind", true, "Display keybind next to a module")
33+
3234
init {
3335
drawSetting.value = false
3436
}
@@ -39,10 +41,14 @@ object ModuleList : HudModule(
3941
enabled.forEach {
4042
val bound = it.keybind.key != 0 || it.keybind.mouse != -1
4143
if (onlyBound && !bound) return@forEach
42-
text(it.name); sameLine()
43-
val color = if (!bound) Color.RED else Color.GREEN
44+
text(it.name);
45+
46+
if (showKeybind) {
47+
val color = if (!bound) Color.RED else Color.GREEN
4448

45-
withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") }
49+
sameLine()
50+
withStyleColor(ImGuiCol.Text, color) { text(" [${it.keybind.name}]") }
51+
}
4652
}
4753
}
4854
}

0 commit comments

Comments
 (0)