diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 7b4f048..edb0508 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -597,6 +597,7 @@ public class RecastDemo sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2); sample.setChanged(false); settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond); + settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList()); toolsUI.setSample(sample); } } diff --git a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index 6a7694b..5814396 100644 --- a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -17,7 +17,9 @@ freely, subject to the following restrictions: */ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using DotRecast.Core; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.UI; @@ -61,6 +63,7 @@ public class RcSettingsView : IRcView // public readonly NkColor transparent = NkColor.create(); private bool buildTriggered; private long buildTime; + private Dictionary telemetries = new(); private readonly int[] voxels = new int[2]; private readonly int[] tiles = new int[2]; private int maxTiles; @@ -177,6 +180,10 @@ public class RcSettingsView : IRcView ImGui.NewLine(); ImGui.Text($"Build Time: {buildTime} ms"); + foreach (var (key, millis) in telemetries) + { + ImGui.Text($"{key}: {millis} ms"); + } ImGui.Separator(); buildTriggered = ImGui.Button("Build"); const string strLoadNavMesh = "Load Nav Mesh..."; @@ -289,6 +296,15 @@ public class RcSettingsView : IRcView this.buildTime = buildTime; } + public void setBuildTelemetry(IList telemetries) + { + this.telemetries = telemetries + .SelectMany(x => x.ToList()) + .GroupBy(x => x.Item1) + .ToDictionary(x => x.Key, x => x.Sum(y => y.Item2)); + + } + public DrawMode getDrawMode() { return drawMode; diff --git a/src/DotRecast.Recast/RecastBuilderResult.cs b/src/DotRecast.Recast/RecastBuilderResult.cs index 525faa6..0f72909 100644 --- a/src/DotRecast.Recast/RecastBuilderResult.cs +++ b/src/DotRecast.Recast/RecastBuilderResult.cs @@ -11,8 +11,7 @@ private readonly Heightfield solid; private readonly Telemetry telemetry; - public RecastBuilderResult(int tileX, int tileZ, Heightfield solid, CompactHeightfield chf, ContourSet cs, PolyMesh pmesh, - PolyMeshDetail dmesh, Telemetry ctx) + public RecastBuilderResult(int tileX, int tileZ, Heightfield solid, CompactHeightfield chf, ContourSet cs, PolyMesh pmesh, PolyMeshDetail dmesh, Telemetry ctx) { this.tileX = tileX; this.tileZ = tileZ; diff --git a/src/DotRecast.Recast/Telemetry.cs b/src/DotRecast.Recast/Telemetry.cs index 3519576..0655c66 100644 --- a/src/DotRecast.Recast/Telemetry.cs +++ b/src/DotRecast.Recast/Telemetry.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Threading; using DotRecast.Core; @@ -47,12 +48,11 @@ namespace DotRecast.Recast Console.WriteLine(@string); } - public void print() + public List> ToList() { - foreach (var (n, v) in timerAccum) - { - Console.WriteLine(n + ": " + v.Read() / TimeSpan.TicksPerMillisecond); - } + return timerAccum + .Select(x => Tuple.Create(x.Key, x.Value.Read() / TimeSpan.TicksPerMillisecond)) + .ToList(); } } } \ No newline at end of file diff --git a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs index 413b733..32aa398 100644 --- a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs @@ -261,7 +261,10 @@ public class RecastSoloMeshTest Console.WriteLine(" " + (time3 - time) / TimeSpan.TicksPerMillisecond + " ms"); saveObj(filename.Substring(0, filename.LastIndexOf('.')) + "_" + partitionType + "_detail.obj", m_dmesh); saveObj(filename.Substring(0, filename.LastIndexOf('.')) + "_" + partitionType + ".obj", m_pmesh); - m_ctx.print(); + foreach (var (key, millis) in m_ctx.ToList()) + { + Console.WriteLine($"{key} : {millis} ms"); + } } private void saveObj(string filename, PolyMesh mesh)