From 07a7f4960b3f42f9d96b5ce37eb209e83eb8f707 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 9 Sep 2023 12:51:44 +0900 Subject: [PATCH] crowd updage flags --- src/DotRecast.Recast.Demo/RecastDemo.cs | 2 +- .../Tools/CrowdProfilingSampleTool.cs | 38 +------------- .../{CrowdampleTool.cs => CrowdSampleTool.cs} | 50 ++++--------------- .../Tools/CrowdOption.cs | 33 ++++++++++++ 4 files changed, 45 insertions(+), 78 deletions(-) rename src/DotRecast.Recast.Demo/Tools/{CrowdampleTool.cs => CrowdSampleTool.cs} (95%) diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 670ff20..ff97355 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -386,7 +386,7 @@ public class RecastDemo : IRecastDemoChannel new ObstacleSampleTool(), new OffMeshConnectionSampleTool(), new ConvexVolumeSampleTool(), - new CrowdampleTool(), + new CrowdSampleTool(), new CrowdProfilingSampleTool(), new JumpLinkBuilderSampleTool(), new DynamicUpdateSampleTool() diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingSampleTool.cs index 88365af..33e1ca9 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingSampleTool.cs @@ -94,45 +94,12 @@ public class CrowdProfilingSampleTool : ISampleTool ap.maxSpeed = settings.agentMaxSpeed; ap.collisionQueryRange = ap.radius * 12.0f; ap.pathOptimizationRange = ap.radius * 30.0f; - ap.updateFlags = GetUpdateFlags(); + ap.updateFlags = _option.GetUpdateFlags(); ap.obstacleAvoidanceType = _option.obstacleAvoidanceType; ap.separationWeight = _option.separationWeight; return ap; } - - private int GetUpdateFlags() - { - int updateFlags = 0; - if (_option.anticipateTurns) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS; - } - - if (_option.optimizeVis) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS; - } - - if (_option.optimizeTopo) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO; - } - - if (_option.obstacleAvoidance) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE; - } - - if (_option.separation) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION; - } - - return updateFlags; - } - - public IRcToolable GetTool() { return _tool; @@ -537,7 +504,6 @@ public class CrowdProfilingSampleTool : ISampleTool private void UpdateAgentParams() { - int updateFlags = GetUpdateFlags(); if (crowd != null) { foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) @@ -551,7 +517,7 @@ public class CrowdProfilingSampleTool : ISampleTool option.pathOptimizationRange = ag.option.pathOptimizationRange; option.queryFilterType = ag.option.queryFilterType; option.userData = ag.option.userData; - option.updateFlags = updateFlags; + option.updateFlags = _option.GetUpdateFlags(); option.obstacleAvoidanceType = _option.obstacleAvoidanceType; option.separationWeight = _option.separationWeight; crowd.UpdateAgentParameters(ag, option); diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs similarity index 95% rename from src/DotRecast.Recast.Demo/Tools/CrowdampleTool.cs rename to src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs index 04e7bd6..a2cca5b 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs @@ -35,9 +35,9 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class CrowdampleTool : ISampleTool +public class CrowdSampleTool : ISampleTool { - private static readonly ILogger Logger = Log.ForContext(); + private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; private readonly RcCrowdTool _tool; @@ -69,7 +69,7 @@ public class CrowdampleTool : ISampleTool private bool m_showDetailAll; - public CrowdampleTool() + public CrowdSampleTool() { m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048); _tool = new(); @@ -237,7 +237,7 @@ public class CrowdampleTool : ISampleTool ap.maxSpeed = settings.agentMaxSpeed; ap.collisionQueryRange = ap.radius * 12.0f; ap.pathOptimizationRange = ap.radius * 30.0f; - ap.updateFlags = GetUpdateFlags(); + ap.updateFlags = _option.GetUpdateFlags(); ap.obstacleAvoidanceType = _option.obstacleAvoidanceType; ap.separationWeight = _option.separationWeight; return ap; @@ -709,10 +709,10 @@ public class CrowdampleTool : ISampleTool ImGui.NewLine(); if (m_optimizeVis != _option.optimizeVis || m_optimizeTopo != _option.optimizeTopo - || m_anticipateTurns != _option.anticipateTurns || m_obstacleAvoidance != _option.obstacleAvoidance - || m_separation != _option.separation - || m_obstacleAvoidanceType != _option.obstacleAvoidanceType - || m_separationWeight != _option.separationWeight) + || m_anticipateTurns != _option.anticipateTurns || m_obstacleAvoidance != _option.obstacleAvoidance + || m_separation != _option.separation + || m_obstacleAvoidanceType != _option.obstacleAvoidanceType + || m_separationWeight != _option.separationWeight) { UpdateAgentParams(); } @@ -742,7 +742,6 @@ public class CrowdampleTool : ISampleTool return; } - int updateFlags = GetUpdateFlags(); foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { DtCrowdAgentParams option = new DtCrowdAgentParams(); @@ -755,44 +754,13 @@ public class CrowdampleTool : ISampleTool option.obstacleAvoidanceType = ag.option.obstacleAvoidanceType; option.queryFilterType = ag.option.queryFilterType; option.userData = ag.option.userData; - option.updateFlags = updateFlags; + option.updateFlags = _option.GetUpdateFlags(); option.obstacleAvoidanceType = _option.obstacleAvoidanceType; option.separationWeight = _option.separationWeight; crowd.UpdateAgentParameters(ag, option); } } - private int GetUpdateFlags() - { - int updateFlags = 0; - if (_option.anticipateTurns) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS; - } - - if (_option.optimizeVis) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS; - } - - if (_option.optimizeTopo) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO; - } - - if (_option.obstacleAvoidance) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE; - } - - if (_option.separation) - { - updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION; - } - - return updateFlags; - } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { diff --git a/src/DotRecast.Recast.Toolset/Tools/CrowdOption.cs b/src/DotRecast.Recast.Toolset/Tools/CrowdOption.cs index 140fbb5..969e93b 100644 --- a/src/DotRecast.Recast.Toolset/Tools/CrowdOption.cs +++ b/src/DotRecast.Recast.Toolset/Tools/CrowdOption.cs @@ -1,3 +1,5 @@ +using DotRecast.Detour.Crowd; + namespace DotRecast.Recast.Toolset.Tools { public class CrowdOption @@ -10,5 +12,36 @@ namespace DotRecast.Recast.Toolset.Tools public int obstacleAvoidanceType = 3; public bool separation; public float separationWeight = 2f; + + public int GetUpdateFlags() + { + int updateFlags = 0; + if (anticipateTurns) + { + updateFlags |= DtCrowdAgentParams.DT_CROWD_ANTICIPATE_TURNS; + } + + if (optimizeVis) + { + updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_VIS; + } + + if (optimizeTopo) + { + updateFlags |= DtCrowdAgentParams.DT_CROWD_OPTIMIZE_TOPO; + } + + if (obstacleAvoidance) + { + updateFlags |= DtCrowdAgentParams.DT_CROWD_OBSTACLE_AVOIDANCE; + } + + if (separation) + { + updateFlags |= DtCrowdAgentParams.DT_CROWD_SEPARATION; + } + + return updateFlags; + } } } \ No newline at end of file