Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/isadorasophia/murder into main
Browse files Browse the repository at this point in the history
  • Loading branch information
saint11 committed Dec 15, 2023
2 parents c77b35e + 0f625f1 commit a03eb68
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 45 deletions.
5 changes: 4 additions & 1 deletion src/Murder.Editor/Architect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Architect : Game

public static EditorDataManager EditorData => (EditorDataManager)Instance._gameData;

internal static EditorGraphLogger EditorGraphLogger => (EditorGraphLogger)Instance.GraphLogger;

/// <summary>
/// Debug and editor buffer renderer.
/// Called in <see cref="Initialize"/>.
Expand Down Expand Up @@ -64,6 +66,8 @@ public class Architect : Game

protected override bool IsDiagnosticEnabled => true;

public override GraphLogger GraphLogger { get; } = new EditorGraphLogger();

public CursorStyle Cursor { get; set; } = CursorStyle.Normal;

protected override bool HasCursor => true;
Expand All @@ -78,7 +82,6 @@ protected override void Initialize()
ImGuiRenderer.RebuildFontAtlas();

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

InitializeImGui();

Expand Down
9 changes: 1 addition & 8 deletions src/Murder.Editor/Systems/Debug/DebugPlotterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
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
{
Expand Down Expand Up @@ -39,7 +32,7 @@ public void DrawGui(RenderContext render, Context context)
ImGui.SetNextWindowSize(new Vector2(350, 150), ImGuiCond.Appearing);
if (ImGui.Begin("Graph", ref _showHierarchy, ImGuiWindowFlags.AlwaysAutoResize))
{
GraphLogger logger = ((GraphLogger)Architect.Instance.GraphLogger);
EditorGraphLogger logger = Architect.EditorGraphLogger;
foreach (var entry in logger.Graphs)
{
if (entry.Value.Values.Length > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
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
internal class EditorGraphLogger : GraphLogger
{

public class Graph
{
private readonly List<float> _values = new List<float>(400);
private float[] _valuesCache = new float[0];
private readonly List<float> _values = new(512);
private float[] _valuesCache = [];
private float _maxValue = float.Epsilon;

public void Plot(float point)
{
_values.Add(point);
_maxValue = MathF.Max(point, _maxValue);
_valuesCache = _values.ToArray();
_valuesCache = [.. _values];
}

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

public readonly Dictionary<string, Graph> Graphs = new();

public override void PlotGraph(float value, string callerFilePath)
{
Expand All @@ -36,7 +31,7 @@ public override void PlotGraph(float value, string callerFilePath)
Graphs[callerClassName] = new Graph();
}

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

Expand Down
17 changes: 17 additions & 0 deletions src/Murder/Diagnostics/GraphLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Murder.Diagnostics
{
/// <summary>
/// Implement this for plotting graphs into the debug system.
/// </summary>
public class GraphLogger
{
public virtual void ClearAllGraphs()
{ }

public virtual void ClearGraph(string callerFilePath)
{ }

public virtual void PlotGraph(float value, string callerFilePath)
{ }
}
}
22 changes: 0 additions & 22 deletions src/Murder/Diagnostics/GraphLoggerBase.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Murder/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public Vector2 GameScale
/// Single logger of the game.
/// </summary>
protected GameLogger _logger;
public GraphLoggerBase GraphLogger { get; protected set; } = new GraphLoggerBase();

public virtual GraphLogger GraphLogger { get; } = new GraphLogger();

public RenderContext CreateRenderContext(GraphicsDevice graphicsDevice, Camera2D camera, RenderContextFlags settings) =>
_game?.CreateRenderContext(graphicsDevice, camera, settings) ?? new RenderContext(graphicsDevice, camera, settings);
Expand Down

0 comments on commit a03eb68

Please sign in to comment.