From 3ce975ff4d29eb84ab8729aaad66eeb16fc07f6e Mon Sep 17 00:00:00 2001 From: Noah Stolk <31079637+NoahStolk@users.noreply.github.com> Date: Thu, 29 Jun 2023 21:46:04 +0200 Subject: [PATCH] Improve debug UI --- .../DevilDaggersInfo.App/Ui/DebugLayout.cs | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/app/DevilDaggersInfo.App/Ui/DebugLayout.cs b/src/app/DevilDaggersInfo.App/Ui/DebugLayout.cs index 81b630920f..16db5cc1e1 100644 --- a/src/app/DevilDaggersInfo.App/Ui/DebugLayout.cs +++ b/src/app/DevilDaggersInfo.App/Ui/DebugLayout.cs @@ -1,5 +1,6 @@ using DevilDaggersInfo.App.Engine.Maths.Numerics; using ImGuiNET; +using System.Numerics; namespace DevilDaggersInfo.App.Ui; @@ -21,31 +22,32 @@ public static void Clear() public static void Render() { - ImGui.SetNextWindowPos(new(8, 8)); - ImGui.SetNextWindowSize(new(320, 256)); + ImDrawListPtr drawList = ImGui.GetForegroundDrawList(); + const uint textColor = 0xffffffff; + float y = 0; + AddText(ref y, $"{Application.RenderCounter.CountPerSecond} FPS ({1f / Application.LastRenderDelta:000.000})"); -#if DEBUG - const ImGuiWindowFlags flags = Constants.LayoutFlags | ImGuiWindowFlags.NoInputs; -#else - const ImGuiWindowFlags flags = Constants.LayoutFlags; -#endif + long allocatedBytes = GC.GetAllocatedBytesForCurrentThread(); + AddText(ref y, allocatedBytes + " bytes allocated on managed heap"); + AddText(ref y, allocatedBytes - _previousAllocatedBytes + " since last frame"); + _previousAllocatedBytes = allocatedBytes; - if (ImGui.Begin("Debug", flags)) - { - ImGui.Text($"{Application.RenderCounter.CountPerSecond} FPS ({1f / Application.LastRenderDelta:000.000})"); + AddText(ref y, GC.CollectionCount(0) + " gen 0 garbage collections"); + AddText(ref y, GC.CollectionCount(1) + " gen 1 garbage collections"); + AddText(ref y, GC.CollectionCount(2) + " gen 2 garbage collections"); - long allocatedBytes = GC.GetAllocatedBytesForCurrentThread(); - ImGui.Text(allocatedBytes + " bytes allocated on managed heap"); - ImGui.Text(allocatedBytes - _previousAllocatedBytes + " since last frame"); - _previousAllocatedBytes = allocatedBytes; + AddText(ref y, $"Modal active: {Modals.IsAnyOpen}"); - ImGui.Text(GC.CollectionCount(0) + " gen 0 garbage collections"); - ImGui.Text(GC.CollectionCount(1) + " gen 1 garbage collections"); - ImGui.Text(GC.CollectionCount(2) + " gen 2 garbage collections"); - - ImGui.Text($"Modal active: {Modals.IsAnyOpen}"); + void AddText(ref float posY, string text) + { + drawList.AddText(new(0, posY), textColor, text); + posY += 16; + } #if DEBUG + ImGui.SetNextWindowSize(new(320, 256)); + if (ImGui.Begin("Debug")) + { if (ImGui.Button("Error window")) Modals.ShowError("Test error!"); @@ -67,9 +69,9 @@ public static void Render() foreach (string debugMessage in _debugMessages) ImGui.Text(debugMessage); -#endif - } - ImGui.End(); + ImGui.End(); + } +#endif } }