Skip to content

Commit

Permalink
Improve debug UI
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStolk committed Jun 29, 2023
1 parent de87147 commit 3ce975f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/app/DevilDaggersInfo.App/Ui/DebugLayout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DevilDaggersInfo.App.Engine.Maths.Numerics;
using ImGuiNET;
using System.Numerics;

namespace DevilDaggersInfo.App.Ui;

Expand All @@ -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!");

Expand All @@ -67,9 +69,9 @@ public static void Render()

foreach (string debugMessage in _debugMessages)
ImGui.Text(debugMessage);
#endif
}

ImGui.End();
ImGui.End();
}
#endif
}
}

0 comments on commit 3ce975f

Please sign in to comment.