Skip to content

Commit

Permalink
working on graph debug tools
Browse files Browse the repository at this point in the history
  • Loading branch information
saint11 committed Dec 14, 2023
1 parent 4731bed commit 2a6fb35
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 246 deletions.
2 changes: 2 additions & 0 deletions src/Murder.Editor/Architect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Murder.Editor.Diagnostics;
using Murder.Editor.EditorCore;
using Murder.Editor.ImGuiExtended;
using Murder.Editor.Systems.Debug;
using Murder.Editor.Utilities;
using System.Diagnostics;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -77,6 +78,7 @@ protected override void Initialize()
ImGuiRenderer.RebuildFontAtlas();

_logger = EditorGameLogger.OverrideInstanceWithEditor();
GraphLogger = new GraphLogger();

InitializeImGui();

Expand Down
63 changes: 63 additions & 0 deletions src/Murder.Editor/Systems/Debug/DebugPlotterSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Bang.Contexts;
using Bang.Systems;
using ImGuiNET;
using Murder.Core.Graphics;
using Murder.Diagnostics;
using Murder.Editor.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static Assimp.Metadata;
using static Murder.Editor.Systems.Debug.GraphLogger;

namespace Murder.Editor.Systems.Debug
{
[DoNotPause]
[OnlyShowOnDebugView]
[Filter(ContextAccessorFilter.None)]
internal class DebugPlotterSystem : IGuiSystem
{
private bool _showHierarchy = false;
public void DrawGui(RenderContext render, Context context)
{

ImGui.BeginMainMenuBar();

if (ImGui.BeginMenu("Show"))
{
ImGui.MenuItem("Graph Debugger", "", ref _showHierarchy);
ImGui.EndMenu();
}

ImGui.EndMainMenuBar();

if (_showHierarchy)
{
ImGui.SetNextWindowSize(new Vector2(350, 150), ImGuiCond.Appearing);
if (ImGui.Begin("Graph", ref _showHierarchy, ImGuiWindowFlags.AlwaysAutoResize))
{
GraphLogger logger = ((GraphLogger)Architect.Instance.GraphLogger);
foreach (var entry in logger.Graphs)
{
if (entry.Value.Values.Length > 0)
{
ImGui.PlotHistogram("", ref entry.Value.Values[0], entry.Value.Values.Length, 0, entry.Key, 0, 1, new Vector2(310, 75));
}
else
{
ImGui.Text($"Graph {entry.Key} is empty");
}
}
if (logger.Graphs.Count == 0)
{
ImGui.Text("Use GameLogger.PlotGraph(float value) to start plottting!");
}
}
ImGui.End();
}
}
}
}
51 changes: 51 additions & 0 deletions src/Murder.Editor/Systems/Debug/GraphLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Murder.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Murder.Editor.Systems.Debug.GraphLogger;

namespace Murder.Editor.Systems.Debug
{
internal class GraphLogger : GraphLoggerBase
{

public class Graph
{
private readonly List<float> _values = new List<float>(400);
private float[] _valuesCache = new float[0];
public void Plot(float point)
{
_values.Add(point);
_valuesCache = _values.ToArray();
}

public float[] Values => _valuesCache;
}
public readonly Dictionary<string, Graph> Graphs = new Dictionary<string, Graph>();

public override void PlotGraph(float value, string callerFilePath)
{
string callerClassName = Path.GetFileNameWithoutExtension(callerFilePath);
if (!Graphs.ContainsKey(callerClassName))
{
Graphs[callerClassName] = new Graph();
}

var graph = Graphs[callerClassName];
graph.Plot(value);
}

public override void ClearGraph(string callerFilePath)
{
string callerClassName = Path.GetFileNameWithoutExtension(callerFilePath);
Graphs.Remove(callerClassName);
}

public override void ClearAllGraphs()
{
Graphs.Clear();
}
}
}
1 change: 0 additions & 1 deletion src/Murder.Editor/Systems/GenericSelectorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void DrawGuiImpl(World world, ImmutableArray<Entity> entities)
hook.HoverEntity(entity);
}
}

ImGui.EndChild();
}
ImGui.End();
Expand Down
Loading

0 comments on commit 2a6fb35

Please sign in to comment.