change GetNodeMap to AsEnumerable in DtNodePool

This commit is contained in:
ikpil 2024-02-06 21:43:54 +09:00 committed by Ikpil
parent 3ce4f59002
commit b26847d90f
3 changed files with 32 additions and 32 deletions

View File

@ -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<DtNode> nodes)
{
var hasNode = m_map.TryGetValue(id, out nodes);
@ -127,9 +133,9 @@ namespace DotRecast.Detour
return GetNode(refs, 0);
}
public Dictionary<long, List<DtNode>> GetNodeMap()
public IEnumerable<DtNode> AsEnumerable()
{
return m_map;
return m_nodes.Take(m_nodeCount);
}
}
}

View File

@ -1200,9 +1200,7 @@ public class RecastDebugDraw : DebugDraw
float off = 0.5f;
Begin(DebugDrawPrimitives.POINTS, 4.0f);
foreach (List<DtNode> nodes in pool.GetNodeMap().Values)
{
foreach (DtNode node in nodes)
foreach (DtNode node in pool.AsEnumerable())
{
if (node == null)
{
@ -1211,14 +1209,11 @@ public class RecastDebugDraw : DebugDraw
Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 255));
}
}
End();
Begin(DebugDrawPrimitives.LINES, 2.0f);
foreach (List<DtNode> nodes in pool.GetNodeMap().Values)
{
foreach (DtNode node in nodes)
foreach (DtNode node in pool.AsEnumerable())
{
if (node == null)
{
@ -1239,7 +1234,6 @@ public class RecastDebugDraw : DebugDraw
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();
}

View File

@ -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));
}
}