From 175184e597cefce43572c7c434e1133a073b66af Mon Sep 17 00:00:00 2001 From: saint11 Date: Fri, 15 Dec 2023 01:52:41 -0800 Subject: [PATCH] Improve support on graph plotter. --- src/Murder.Editor/Architect.cs | 1 - .../Systems/Debug/EditorGraphLogger.cs | 22 +++++++++++++++++++ src/Murder/Diagnostics/GameLogger.cs | 1 + src/Murder/Diagnostics/GraphLogger.cs | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Murder.Editor/Architect.cs b/src/Murder.Editor/Architect.cs index 2601071ab..d6936c65b 100644 --- a/src/Murder.Editor/Architect.cs +++ b/src/Murder.Editor/Architect.cs @@ -59,7 +59,6 @@ public class Architect : Game /* *** Architect state *** */ - private bool _isPlayingGame = false; protected override bool AlwaysUpdateBeforeFixed => _isPlayingGame; diff --git a/src/Murder.Editor/Systems/Debug/EditorGraphLogger.cs b/src/Murder.Editor/Systems/Debug/EditorGraphLogger.cs index 9c2c1fcdc..841289cba 100644 --- a/src/Murder.Editor/Systems/Debug/EditorGraphLogger.cs +++ b/src/Murder.Editor/Systems/Debug/EditorGraphLogger.cs @@ -16,6 +16,16 @@ public void Plot(float point) _maxValue = MathF.Max(point, _maxValue); _valuesCache = [.. _values]; } + public void Plot(float point, int max) + { + if (_values.Count>max) + { + _values.Clear(); + } + _values.Add(point); + _maxValue = MathF.Max(point, _maxValue); + _valuesCache = [.. _values]; + } public float[] Values => _valuesCache; public float Max => _maxValue; @@ -35,6 +45,18 @@ public override void PlotGraph(float value, string callerFilePath) graph.Plot(value); } + public override void PlotGraph(float value, int max, string callerFilePath) + { + string callerClassName = Path.GetFileNameWithoutExtension(callerFilePath); + if (!Graphs.ContainsKey(callerClassName)) + { + Graphs[callerClassName] = new Graph(); + } + + Graph graph = Graphs[callerClassName]; + graph.Plot(value, max); + } + public override void ClearGraph(string callerFilePath) { string callerClassName = Path.GetFileNameWithoutExtension(callerFilePath); diff --git a/src/Murder/Diagnostics/GameLogger.cs b/src/Murder/Diagnostics/GameLogger.cs index 2378ca1a7..446b83097 100644 --- a/src/Murder/Diagnostics/GameLogger.cs +++ b/src/Murder/Diagnostics/GameLogger.cs @@ -107,6 +107,7 @@ protected virtual void Input(Func? onInputAction) { } public static void ClearAllGraphs() => Game.Instance.GraphLogger.ClearAllGraphs(); public static void ClearGraph([CallerFilePath] string callerFilePath = "") => Game.Instance.GraphLogger.ClearGraph(callerFilePath); public static void PlotGraph(float point, [CallerFilePath] string callerFilePath = "") => Game.Instance.GraphLogger.PlotGraph(point, callerFilePath); + public static void PlotGraph(float point, int max, [CallerFilePath] string callerFilePath = "") => Game.Instance.GraphLogger.PlotGraph(point, max, callerFilePath); public static void LogPerf(string v, Vector4? color = null) => GetOrCreateInstance().LogPerfImpl(v, color ?? new Vector4(1, 1, 1, 1) /* white */); diff --git a/src/Murder/Diagnostics/GraphLogger.cs b/src/Murder/Diagnostics/GraphLogger.cs index 2d01de49e..17865e7e3 100644 --- a/src/Murder/Diagnostics/GraphLogger.cs +++ b/src/Murder/Diagnostics/GraphLogger.cs @@ -13,5 +13,7 @@ public virtual void ClearGraph(string callerFilePath) public virtual void PlotGraph(float value, string callerFilePath) { } + public virtual void PlotGraph(float value, int max, string callerFilePath) + { } } }