diff --git a/src/DotRecast.Detour/DtNodePool.cs b/src/DotRecast.Detour/DtNodePool.cs index 85f8f7e..bc6e99e 100644 --- a/src/DotRecast.Detour/DtNodePool.cs +++ b/src/DotRecast.Detour/DtNodePool.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using System.Collections.Generic; +using System.Linq; namespace DotRecast.Detour { @@ -41,6 +42,11 @@ namespace DotRecast.Detour m_nodeCount = 0; } + public int GetNodeCount() + { + return m_nodeCount; + } + public int FindNodes(long id, out List nodes) { var hasNode = m_map.TryGetValue(id, out nodes); @@ -127,9 +133,9 @@ namespace DotRecast.Detour return GetNode(refs, 0); } - public Dictionary> GetNodeMap() + public IEnumerable AsEnumerable() { - return m_map; + return m_nodes.Take(m_nodeCount); } } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index db61456..62ff866 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -1200,45 +1200,39 @@ public class RecastDebugDraw : DebugDraw float off = 0.5f; Begin(DebugDrawPrimitives.POINTS, 4.0f); - foreach (List nodes in pool.GetNodeMap().Values) + foreach (DtNode node in pool.AsEnumerable()) { - foreach (DtNode node in nodes) + if (node == null) { - if (node == null) - { - continue; - } - - Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 255)); + continue; } + + Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 255)); } End(); Begin(DebugDrawPrimitives.LINES, 2.0f); - foreach (List nodes in pool.GetNodeMap().Values) + foreach (DtNode node in pool.AsEnumerable()) { - foreach (DtNode node in nodes) + if (node == null) { - if (node == null) - { - continue; - } - - if (node.pidx == 0) - { - continue; - } - - DtNode parent = pool.GetNodeAtIdx(node.pidx); - if (parent == null) - { - continue; - } - - Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 128)); - Vertex(parent.pos.X, parent.pos.Y + off, parent.pos.Z, DuRGBA(255, 192, 0, 128)); + continue; } + + if (node.pidx == 0) + { + continue; + } + + DtNode parent = pool.GetNodeAtIdx(node.pidx); + if (parent == null) + { + continue; + } + + Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 128)); + Vertex(parent.pos.X, parent.pos.Y + off, parent.pos.Z, DuRGBA(255, 192, 0, 128)); } End(); diff --git a/test/DotRecast.Detour.Test/DtNodePoolTest.cs b/test/DotRecast.Detour.Test/DtNodePoolTest.cs index 646a413..7ad3d68 100644 --- a/test/DotRecast.Detour.Test/DtNodePoolTest.cs +++ b/test/DotRecast.Detour.Test/DtNodePoolTest.cs @@ -74,11 +74,11 @@ public class DtNodePoolTest Assert.That(nodes, Is.Null); } - var totalCount = pool.GetNodeMap().Sum(x => x.Value.Count); + var totalCount = pool.GetNodeCount(); Assert.That(totalCount, Is.EqualTo(sum)); pool.Clear(); - totalCount = pool.GetNodeMap().Sum(x => x.Value.Count); + totalCount = pool.GetNodeCount(); Assert.That(totalCount, Is.EqualTo(0)); } } \ No newline at end of file