diff --git a/src/DotRecast.Detour.TileCache/DtTileCache.cs b/src/DotRecast.Detour.TileCache/DtTileCache.cs index c5de180..d3203d7 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCache.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCache.cs @@ -436,7 +436,7 @@ namespace DotRecast.Detour.TileCache return o; } - List QueryTiles(RcVec3f bmin, RcVec3f bmax) + private List QueryTiles(RcVec3f bmin, RcVec3f bmax) { List results = new List(); float tw = m_params.width * m_params.cs; @@ -468,12 +468,12 @@ namespace DotRecast.Detour.TileCache } /** - * Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests. - * - * @return Returns true if the tile cache is fully up to date with obstacle requests and tile rebuilds. If the tile - * cache is up to date another (immediate) call to update will have no effect; otherwise another call will - * continue processing obstacle requests and tile rebuilds. - */ + * Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests. + * + * @return Returns true if the tile cache is fully up to date with obstacle requests and tile rebuilds. If the tile + * cache is up to date another (immediate) call to update will have no effect; otherwise another call will + * continue processing obstacle requests and tile rebuilds. + */ public bool Update() { if (0 == m_update.Count) diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs index 2e9796e..de0f3a1 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs @@ -39,7 +39,7 @@ public class ConvexVolumeSampleTool : ISampleTool private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; - private readonly RcConvexVolumeTool _impl; + private readonly RcConvexVolumeTool _tool; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; private RcAreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS; @@ -51,12 +51,12 @@ public class ConvexVolumeSampleTool : ISampleTool public ConvexVolumeSampleTool() { - _impl = new RcConvexVolumeTool(); + _tool = new RcConvexVolumeTool(); } public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) @@ -78,7 +78,7 @@ public class ConvexVolumeSampleTool : ISampleTool if (shift) { - _impl.RemoveByPos(geom, p); + _tool.RemoveByPos(geom, p); } else { @@ -90,7 +90,7 @@ public class ConvexVolumeSampleTool : ISampleTool var vol = RcConvexVolumeTool.CreateConvexVolume(pts, hull, areaType, boxDescent, boxHeight, polyOffset); if (null != vol) { - _impl.Add(geom, vol); + _tool.Add(geom, vol); } pts.Clear(); diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs index 2bd19f7..36f7b8c 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs @@ -40,7 +40,7 @@ public class CrowdSampleTool : ISampleTool private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; - private readonly RcCrowdTool _impl; + private readonly RcCrowdTool _tool; private readonly CrowdToolParams toolParams = new CrowdToolParams(); private DtNavMesh m_nav; private DtCrowd crowd; @@ -58,12 +58,12 @@ public class CrowdSampleTool : ISampleTool { m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048); profilingTool = new CrowdProfilingTool(GetAgentParams); - _impl = new(); + _tool = new(); } public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs index def6241..34f923d 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs @@ -45,7 +45,7 @@ public class DynamicUpdateSampleTool : ISampleTool private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; - private readonly RcDynamicUpdateTool _impl; + private readonly RcDynamicUpdateTool _tool; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD; private float cellSize = 0.3f; @@ -91,7 +91,7 @@ public class DynamicUpdateSampleTool : ISampleTool public DynamicUpdateSampleTool() { - _impl = new(); + _tool = new(); executor = Task.Factory; bridgeGeom = DemoObjImporter.Load(Loader.ToBytes("bridge.obj")); houseGeom = DemoObjImporter.Load(Loader.ToBytes("house.obj")); @@ -100,7 +100,7 @@ public class DynamicUpdateSampleTool : ISampleTool public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs index 295e5fe..c0f4fa8 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs @@ -33,18 +33,18 @@ public class JumpLinkBuilderSampleTool : ISampleTool private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; - private readonly RcJumpLinkBuilderTool _impl; + private readonly RcJumpLinkBuilderTool _tool; private readonly RcJumpLinkBuilderToolOption _option; public JumpLinkBuilderSampleTool() { - _impl = new(); + _tool = new(); _option = new(); } public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) @@ -54,7 +54,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool public void OnSampleChanged() { - _impl.Clear(); + _tool.Clear(); } @@ -69,13 +69,13 @@ public class JumpLinkBuilderSampleTool : ISampleTool RecastDebugDraw dd = renderer.GetDebugDraw(); dd.DepthMask(false); - var annotationBuilder = _impl.GetAnnotationBuilder(); + var annotationBuilder = _tool.GetAnnotationBuilder(); if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_WALKABLE_BORDER) != 0) { if (annotationBuilder != null) { - var selEdge = _impl.GetSelEdge(); + var selEdge = _tool.GetSelEdge(); foreach (JumpEdge[] edges in annotationBuilder.GetEdges()) { @@ -132,7 +132,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANNOTATIONS) != 0) { dd.Begin(QUADS); - foreach (JumpLink link in _impl.GetLinks()) + foreach (JumpLink link in _tool.GetLinks()) { for (int j = 0; j < link.nspine - 1; ++j) { @@ -149,7 +149,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool dd.End(); dd.Begin(LINES, 3.0f); - foreach (JumpLink link in _impl.GetLinks()) + foreach (JumpLink link in _tool.GetLinks()) { for (int j = 0; j < link.nspine - 1; ++j) { @@ -178,7 +178,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool if (annotationBuilder != null) { - foreach (JumpLink link in _impl.GetLinks()) + foreach (JumpLink link in _tool.GetLinks()) { if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANIM_TRAJECTORY) != 0) { @@ -389,7 +389,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool var geom = _sample.GetInputGeom(); var settings = _sample.GetSettings(); - _impl.Build( + _tool.Build( geom, settings, _sample.GetRecastResults(), buildOffMeshConnections, _option.buildTypes, diff --git a/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs index 75b4cb1..e5edbec 100644 --- a/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs @@ -11,23 +11,23 @@ namespace DotRecast.Recast.Demo.Tools; public class ObstacleSampleTool : ISampleTool { private static readonly ILogger Logger = Log.ForContext(); - + private DemoSample _sample; - private readonly RcObstacleTool _impl; + private readonly RcObstacleTool _tool; private bool _hitPosSet; private RcVec3f _hitPos; public ObstacleSampleTool() { - _impl = new(DtTileCacheCompressorFactory.Shared); + _tool = new(DtTileCacheCompressorFactory.Shared); } public IRcToolable GetTool() { - return _impl; + return _tool; } - + public void SetSample(DemoSample sample) { _sample = sample; @@ -39,9 +39,17 @@ public class ObstacleSampleTool : ISampleTool public void Layout() { + if (ImGui.Button("Build Tile Cache")) + { + var geom = _sample.GetInputGeom(); + var settings = _sample.GetSettings(); + + _tool.Build(geom, settings, RcByteOrder.LITTLE_ENDIAN, true); + } + if (ImGui.Button("Remove All Temp Obstacles")) { - _impl.ClearAllTempObstacles(); + _tool.ClearAllTempObstacles(); } ImGui.Separator(); @@ -57,11 +65,11 @@ public class ObstacleSampleTool : ISampleTool if (shift) { - _impl.RemoveTempObstacle(s, p); + _tool.RemoveTempObstacle(s, p); } else { - _impl.AddTempObstacle(_hitPos); + _tool.AddTempObstacle(_hitPos); } } diff --git a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs index c4ca238..1d00eee 100644 --- a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs @@ -36,18 +36,18 @@ public class OffMeshConnectionSampleTool : ISampleTool private DemoSample _sample; - private readonly RcOffMeshConnectionTool _impl; + private readonly RcOffMeshConnectionTool _tool; private bool hitPosSet; private RcVec3f hitPos; public OffMeshConnectionSampleTool() { - _impl = new(); + _tool = new(); } public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) @@ -72,7 +72,7 @@ public class OffMeshConnectionSampleTool : ISampleTool if (shift) { - _impl.Remove(geom, settings, p); + _tool.Remove(geom, settings, p); } else { @@ -84,7 +84,7 @@ public class OffMeshConnectionSampleTool : ISampleTool } else { - _impl.Add(geom, settings, hitPos, p); + _tool.Add(geom, settings, hitPos, p); hitPosSet = false; } } @@ -111,7 +111,7 @@ public class OffMeshConnectionSampleTool : ISampleTool public void Layout() { - var options = _impl.GetOption(); + var options = _tool.GetOption(); ImGui.RadioButton("One Way", ref options.bidir, 0); ImGui.RadioButton("Bidirectional", ref options.bidir, 1); } diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index 8fdcca2..926de4a 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -20,7 +20,7 @@ public class TestNavmeshSampleTool : ISampleTool private const int MAX_POLYS = 256; private DemoSample _sample; - private readonly RcTestNavMeshTool _impl; + private readonly RcTestNavMeshTool _tool; private bool m_sposSet; private bool m_eposSet; @@ -49,7 +49,7 @@ public class TestNavmeshSampleTool : ISampleTool public TestNavmeshSampleTool() { - _impl = new(); + _tool = new(); m_filter = new DtQueryDefaultFilter( SampleAreaModifications.SAMPLE_POLYFLAGS_ALL, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, @@ -59,7 +59,7 @@ public class TestNavmeshSampleTool : ISampleTool public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) @@ -91,7 +91,7 @@ public class TestNavmeshSampleTool : ISampleTool public void Layout() { - var option = _impl.GetOption(); + var option = _tool.GetOption(); var previousToolMode = option.mode; int previousStraightPathOptions = option.straightPathOptions; int previousIncludeFlags = m_filter.GetIncludeFlags(); @@ -197,7 +197,7 @@ public class TestNavmeshSampleTool : ISampleTool m_endRef = 0; } - var option = _impl.GetOption(); + var option = _tool.GetOption(); if (option.mode == RcTestNavmeshToolMode.PATHFIND_FOLLOW) { @@ -206,7 +206,7 @@ public class TestNavmeshSampleTool : ISampleTool var polys = new List(); var smoothPath = new List(); - var status = _impl.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast, + var status = _tool.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast, ref polys, ref smoothPath); if (status.Succeeded()) @@ -227,7 +227,7 @@ public class TestNavmeshSampleTool : ISampleTool { var polys = new List(); var straightPath = new List(); - var status = _impl.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast, + var status = _tool.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast, ref polys, ref straightPath, option.straightPathOptions); if (status.Succeeded()) @@ -248,7 +248,7 @@ public class TestNavmeshSampleTool : ISampleTool if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0) { - m_pathFindStatus = _impl.InitSlicedFindPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast); + m_pathFindStatus = _tool.InitSlicedFindPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast); } } else if (option.mode == RcTestNavmeshToolMode.RAYCAST) @@ -258,7 +258,7 @@ public class TestNavmeshSampleTool : ISampleTool { var polys = new List(); var straightPath = new List(); - var status = _impl.Raycast(navQuery, m_startRef, m_spos, m_epos, m_filter, + var status = _tool.Raycast(navQuery, m_startRef, m_spos, m_epos, m_filter, ref polys, ref straightPath, out var hitPos, out var hitNormal, out var hitResult); if (status.Succeeded()) @@ -292,7 +292,7 @@ public class TestNavmeshSampleTool : ISampleTool List refs = new(); List parentRefs = new(); - var status = _impl.FindPolysAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs); + var status = _tool.FindPolysAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs); if (status.Succeeded()) { m_polys = refs; @@ -307,7 +307,7 @@ public class TestNavmeshSampleTool : ISampleTool var refs = new List(); var parentRefs = new List(); - var status = _impl.FindPolysAroundShape(navQuery, settings, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs, out var queryPoly); + var status = _tool.FindPolysAroundShape(navQuery, settings, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs, out var queryPoly); if (status.Succeeded()) { m_queryPoly = queryPoly; @@ -337,7 +337,7 @@ public class TestNavmeshSampleTool : ISampleTool if (m_sposSet && m_startRef != 0 && m_eposSet) { var points = new List(); - _impl.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points); + _tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points); randomPoints.AddRange(points); } } @@ -373,7 +373,7 @@ public class TestNavmeshSampleTool : ISampleTool return; } - var option = _impl.GetOption(); + var option = _tool.GetOption(); if (option.mode == RcTestNavmeshToolMode.PATHFIND_FOLLOW) { dd.DebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol); @@ -791,7 +791,7 @@ public class TestNavmeshSampleTool : ISampleTool public void HandleUpdate(float dt) { // TODO Auto-generated method stub - var option = _impl.GetOption(); + var option = _tool.GetOption(); if (option.mode == RcTestNavmeshToolMode.PATHFIND_SLICED) { DtNavMeshQuery m_navQuery = _sample.GetNavMeshQuery(); diff --git a/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs index aa2d109..553dc42 100644 --- a/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs @@ -15,19 +15,19 @@ public class TileSampleTool : ISampleTool private static readonly ILogger Logger = Log.ForContext(); private DemoSample _sample; - private readonly RcTileTool _impl; + private readonly RcTileTool _tool; private bool _hitPosSet; private RcVec3f _hitPos; public TileSampleTool() { - _impl = new(); + _tool = new(); } public IRcToolable GetTool() { - return _impl; + return _tool; } public void SetSample(DemoSample sample) @@ -47,12 +47,12 @@ public class TileSampleTool : ISampleTool if (ImGui.Button("Create All Tile")) { - _impl.BuildAllTiles(geom, settings, navMesh); + _tool.BuildAllTiles(geom, settings, navMesh); } if (ImGui.Button("Remove All Tile")) { - _impl.RemoveAllTiles(geom, settings, navMesh); + _tool.RemoveAllTiles(geom, settings, navMesh); } } @@ -67,11 +67,11 @@ public class TileSampleTool : ISampleTool if (shift) { - _impl.RemoveTile(geom, settings, navMesh, _hitPos); + _tool.RemoveTile(geom, settings, navMesh, _hitPos); } else { - bool built = _impl.BuildTile(geom, settings, navMesh, _hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage); + bool built = _tool.BuildTile(geom, settings, navMesh, _hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage); if (!built) { Logger.Error($"failed to build tile - check!"); diff --git a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index 4fe32ac..591328f 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -24,19 +24,33 @@ namespace DotRecast.Recast.Toolset.Tools return "Create Temp Obstacles"; } + public void Build(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility) + { + _tc = CreateTileCache(geom, setting, order, cCompatibility); + } + public void ClearAllTempObstacles() { + if (null == _tc) + return; } public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq) { - // .. + if (null == _tc) + return; + + //DtObstacleRef refs = hitTestObstacle(m_tileCache, sp, sq); + //_tc.RemoveObstacle(refs); } - public void AddTempObstacle(RcVec3f pos) + public void AddTempObstacle(RcVec3f p) { - //p[1] -= 0.5f; - //m_tileCache->addObstacle(p, 1.0f, 2.0f, 0); + if (null == _tc) + return; + + p.y -= 0.5f; + _tc.AddObstacle(p, 1.0f, 2.0f); } public DtTileCache CreateTileCache(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility)