draw agent option

This commit is contained in:
Sarofc 2024-07-05 22:34:32 +08:00 committed by ikpil
parent 13be6d5bd8
commit 997d3f1a9b
4 changed files with 30 additions and 29 deletions

View File

@ -19,11 +19,8 @@ freely, subject to the following restrictions:
*/
using System;
using System.Collections.Generic;
using DotRecast.Core.Numerics;
using DotRecast.Detour;
using DotRecast.Detour.Crowd;
using DotRecast.Detour.Dynamic.Colliders;
using DotRecast.Recast.Toolset.Builder;
using Silk.NET.OpenGL;

View File

@ -18,12 +18,9 @@ freely, subject to the following restrictions:
*/
using System;
using System.Collections.Generic;
using System.Linq;
using DotRecast.Core.Numerics;
using DotRecast.Detour;
using DotRecast.Detour.Crowd;
using DotRecast.Recast.Toolset.Builder;
using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.Toolset;
using DotRecast.Recast.Toolset.Tools;
@ -98,6 +95,11 @@ public class CrowdAgentProfilingSampleTool : ISampleTool
ImGui.SliderInt("Max Iterations", ref toolCfg.maxIterations, 0, 4000);
ImGui.NewLine();
ImGui.Text("Debug Draw");
ImGui.Separator();
ImGui.Checkbox("Show Agents", ref toolCfg.showAgents);
ImGui.NewLine();
if (ImGui.Button("Start Crowd Profiling"))
{
var settings = _sample.GetSettings();
@ -118,11 +120,11 @@ public class CrowdAgentProfilingSampleTool : ISampleTool
ImGui.Text($"{rtt.Key}: {rtt.Micros} us");
}
ImGui.Text($"Sampling Time: {_tool.GetCrowdUpdateSamplingTime()} ms");
ImGui.Text($"Current Update Time: {_tool.GetCrowdUpdateTime()} ms");
ImGui.Text($"Avg Update Time: {_tool.GetCrowdUpdateAvgTime()} ms");
ImGui.Text($"Max Update Time: {_tool.GetCrowdUpdateMaxTime()} ms");
ImGui.Text($"Min Update Time: {_tool.GetCrowdUpdateMinTime()} ms");
ImGui.Text($"Sampling Time: {_tool.GetCrowdUpdateSamplingTime():0.00} ms");
ImGui.Text($"Current Update Time: {_tool.GetCrowdUpdateTime():0.00} ms");
ImGui.Text($"Avg Update Time: {_tool.GetCrowdUpdateAvgTime():0.00} ms");
ImGui.Text($"Max Update Time: {_tool.GetCrowdUpdateMaxTime():0.00} ms");
ImGui.Text($"Min Update Time: {_tool.GetCrowdUpdateMinTime():0.00} ms");
}
}
@ -132,7 +134,7 @@ public class CrowdAgentProfilingSampleTool : ISampleTool
dd.DepthMask(false);
var crowd = _tool.GetCrowd();
if (crowd != null)
if (crowd != null && _tool.GetToolConfig().showAgents)
{
foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
{

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
@ -26,12 +26,12 @@ namespace DotRecast.Recast.Toolset.Tools
private readonly List<DtPolyPoint> _polyPoints;
private const int SamplingCount = 500;
private long _samplingUpdateTime;
private double _samplingUpdateTime;
private readonly RcCyclicBuffer<long> _updateTimes;
private long _curUpdateTime;
private long _avgUpdateTime;
private long _minUpdateTime;
private long _maxUpdateTime;
private double _curUpdateTime;
private double _avgUpdateTime;
private double _minUpdateTime;
private double _maxUpdateTime;
public RcCrowdAgentProfilingTool()
{
@ -269,11 +269,11 @@ namespace DotRecast.Recast.Toolset.Tools
_updateTimes.PushBack(currentTime);
// for benchmark
_samplingUpdateTime = _updateTimes.Sum() / TimeSpan.TicksPerMillisecond;
_curUpdateTime = currentTime / TimeSpan.TicksPerMillisecond;
_avgUpdateTime = (long)(_updateTimes.Average() / TimeSpan.TicksPerMillisecond);
_minUpdateTime = _updateTimes.Min() / TimeSpan.TicksPerMillisecond;
_maxUpdateTime = _updateTimes.Max() / TimeSpan.TicksPerMillisecond;
_samplingUpdateTime = _updateTimes.Sum() / (double)TimeSpan.TicksPerMillisecond;
_curUpdateTime = currentTime / (double)TimeSpan.TicksPerMillisecond;
_avgUpdateTime = (_updateTimes.Average() / (double)TimeSpan.TicksPerMillisecond);
_minUpdateTime = _updateTimes.Min() / (double)TimeSpan.TicksPerMillisecond;
_maxUpdateTime = _updateTimes.Max() / (double)TimeSpan.TicksPerMillisecond;
}
private void MoveMob(DtNavMeshQuery navquery, IDtQueryFilter filter, DtCrowdAgent ag, RcCrowdAgentData crowAgentData)
@ -374,27 +374,27 @@ namespace DotRecast.Recast.Toolset.Tools
}
}
public long GetCrowdUpdateSamplingTime()
public double GetCrowdUpdateSamplingTime()
{
return _samplingUpdateTime;
}
public long GetCrowdUpdateTime()
public double GetCrowdUpdateTime()
{
return _curUpdateTime;
}
public long GetCrowdUpdateAvgTime()
public double GetCrowdUpdateAvgTime()
{
return _avgUpdateTime;
}
public long GetCrowdUpdateMinTime()
public double GetCrowdUpdateMinTime()
{
return _minUpdateTime;
}
public long GetCrowdUpdateMaxTime()
public double GetCrowdUpdateMaxTime()
{
return _maxUpdateTime;
}

View File

@ -1,4 +1,4 @@
namespace DotRecast.Recast.Toolset.Tools
namespace DotRecast.Recast.Toolset.Tools
{
public class RcCrowdAgentProfilingToolConfig
{
@ -12,5 +12,7 @@
public float percentTravellers = 15f;
public int pathQueueSize = 32;
public int maxIterations = 300;
public bool showAgents = true;
}
}