|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.module.hud |
| 19 | + |
| 20 | +import com.lambda.gui.dsl.ImGuiBuilder |
| 21 | +import com.lambda.module.HudModule |
| 22 | +import com.lambda.module.tag.ModuleTag |
| 23 | +import com.lambda.util.Formatting.format |
| 24 | +import com.lambda.util.ServerTPS |
| 25 | +import com.lambda.util.ServerTPS.recentData |
| 26 | +import imgui.ImVec2 |
| 27 | + |
| 28 | +object TPS : HudModule( |
| 29 | + name = "TPS", |
| 30 | + description = "Display the server's tick rate", |
| 31 | + tag = ModuleTag.HUD, |
| 32 | +) { |
| 33 | + private val format by setting("Tick format", ServerTPS.TickFormat.Tps) |
| 34 | + private val showGraph by setting("Show TPS Graph", false) |
| 35 | + private val graphHeight by setting("Graph Height", 40f, 10f..200f, 1f) |
| 36 | + private val graphWidth by setting("Graph Width", 200f, 10f..500f, 1f) |
| 37 | + private val graphStride by setting("Graph Stride", 1, 1..20, 1) |
| 38 | + |
| 39 | + override fun ImGuiBuilder.buildLayout() { |
| 40 | + val data = recentData(format) |
| 41 | + if (data.isEmpty()) { |
| 42 | + text("No ${format.displayName} data yet") |
| 43 | + return |
| 44 | + } |
| 45 | + val current = data.last() |
| 46 | + val avg = data.average().toFloat() |
| 47 | + if (!showGraph) { |
| 48 | + text("${format.displayName}: ${avg.format()}${format.unit}") |
| 49 | + return |
| 50 | + } |
| 51 | + val overlay = "cur ${current.format()}${format.unit} | avg ${avg.format()}${format.unit}" |
| 52 | + |
| 53 | + plotLines( |
| 54 | + label = "##TPSPlot", |
| 55 | + values = data, |
| 56 | + overlayText = overlay, |
| 57 | + graphSize = ImVec2(graphWidth, graphHeight), |
| 58 | + stride = graphStride |
| 59 | + ) |
| 60 | + } |
| 61 | +} |
0 commit comments