Skip to content

Commit

Permalink
Add more debug/usage stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Dec 26, 2024
1 parent 70192ce commit 8f4bd81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ class Map extends Node<Map> {
addChild(terrain)
}
}

@Override
String getName() {

return "Terrain - ${children.size()} objects"
}
}

/**
Expand Down Expand Up @@ -559,6 +565,12 @@ class Map extends Node<Map> {
heading = objectLine.heading
}
}

@Override
String getName() {

return "${this.class.simpleName} - ${children.size()} units"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import imgui.type.ImBoolean
import static imgui.flag.ImGuiWindowFlags.*
import static org.lwjgl.glfw.GLFW.*

import java.lang.management.ManagementFactory
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

/**
* An overlay rendering pass for displaying debug information about the game.
*
Expand All @@ -39,11 +43,14 @@ class DebugOverlay implements ImGuiElement, Switch<DebugOverlay> {
private int debugWindowSizeX = 350
private int debugWindowSizeY = 200
private final EngineStats engineStats
private final Runtime runtime

private float leftX
private float leftY
private float rightX
private float rightY
private float memoryUsage
private long garbageCollections

/**
* Constructor, create a new blank overlay. This is made more useful by
Expand All @@ -58,6 +65,7 @@ class DebugOverlay implements ImGuiElement, Switch<DebugOverlay> {
}
}
engineStats = EngineStats.instance
runtime = Runtime.runtime

inputEventStream.on(GamepadAxisEvent) { event ->
switch (event.type) {
Expand All @@ -69,6 +77,11 @@ class DebugOverlay implements ImGuiElement, Switch<DebugOverlay> {
}

this.enabled = enabled

Executors.newScheduledThreadPool(1).scheduleAtFixedRate({ ->
memoryUsage = ((runtime.totalMemory() - runtime.freeMemory()) / 1024) / 1024
garbageCollections = ManagementFactory.garbageCollectorMXBeans.inject(0L) { acc, bean -> acc + bean.collectionCount }
}, 1, 1, TimeUnit.SECONDS)
}

@Override
Expand All @@ -84,14 +97,12 @@ class DebugOverlay implements ImGuiElement, Switch<DebugOverlay> {
debugWindowSizeY = ImGui.getWindowSizeY() as int

ImGui.text("Framerate: ${sprintf('%.1f', ImGui.getIO().framerate)}fps, Frametime: ${sprintf('%.1f', 1000 / ImGui.getIO().framerate)}ms")
ImGui.text("Memory used: ${String.format('%.2f', memoryUsage)}MB, GCs: ${garbageCollections}")
ImGui.text("Scene objects: ${engineStats.sceneObjects.get()}")
ImGui.text("Draw calls: ${engineStats.drawCalls.getAndSet(0)}")
ImGui.text("Active meshes: ${engineStats.activeMeshes}")
ImGui.text("Active textures: ${engineStats.activeTextures}")
ImGui.text("Active framebuffers: ${engineStats.activeFramebuffers}")
ImGui.text("Active uniform buffers: ${engineStats.activeUniformBuffers}")
ImGui.text("Active sources: ${engineStats.activeSources}")
ImGui.text("Active buffers: ${engineStats.activeBuffers}")
ImGui.text("Graphics meshes: ${engineStats.activeMeshes}, textures: ${engineStats.activeTextures}")
ImGui.text("Graphics framebuffers: ${engineStats.activeFramebuffers}, uniform buffers: ${engineStats.activeUniformBuffers}")
ImGui.text("Sound sources: ${engineStats.activeSources}, buffers: ${engineStats.activeBuffers}")
ImGui.text("Gamepad sticks: " +
"(${sprintf('%.2f', leftX)}, ${sprintf('%.2f', leftY)}) " +
"(${sprintf('%.2f', rightX)}, ${sprintf('%.2f', rightY)})")
Expand Down

0 comments on commit 8f4bd81

Please sign in to comment.