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.Collections.Generic;
using System.Linq;
namespace DotRecast.Detour namespace DotRecast.Detour
{ {
@ -41,6 +42,11 @@ namespace DotRecast.Detour
m_nodeCount = 0; m_nodeCount = 0;
} }
public int GetNodeCount()
{
return m_nodeCount;
}
public int FindNodes(long id, out List<DtNode> nodes) public int FindNodes(long id, out List<DtNode> nodes)
{ {
var hasNode = m_map.TryGetValue(id, out nodes); var hasNode = m_map.TryGetValue(id, out nodes);
@ -127,9 +133,9 @@ namespace DotRecast.Detour
return GetNode(refs, 0); 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,45 +1200,39 @@ public class RecastDebugDraw : DebugDraw
float off = 0.5f; float off = 0.5f;
Begin(DebugDrawPrimitives.POINTS, 4.0f); Begin(DebugDrawPrimitives.POINTS, 4.0f);
foreach (List<DtNode> nodes in pool.GetNodeMap().Values) foreach (DtNode node in pool.AsEnumerable())
{ {
foreach (DtNode node in nodes) if (node == null)
{ {
if (node == null) continue;
{
continue;
}
Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 255));
} }
Vertex(node.pos.X, node.pos.Y + off, node.pos.Z, DuRGBA(255, 192, 0, 255));
} }
End(); End();
Begin(DebugDrawPrimitives.LINES, 2.0f); Begin(DebugDrawPrimitives.LINES, 2.0f);
foreach (List<DtNode> nodes in pool.GetNodeMap().Values) foreach (DtNode node in pool.AsEnumerable())
{ {
foreach (DtNode node in nodes) if (node == null)
{ {
if (node == null) continue;
{
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));
} }
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(); End();

View File

@ -74,11 +74,11 @@ public class DtNodePoolTest
Assert.That(nodes, Is.Null); Assert.That(nodes, Is.Null);
} }
var totalCount = pool.GetNodeMap().Sum(x => x.Value.Count); var totalCount = pool.GetNodeCount();
Assert.That(totalCount, Is.EqualTo(sum)); Assert.That(totalCount, Is.EqualTo(sum));
pool.Clear(); pool.Clear();
totalCount = pool.GetNodeMap().Sum(x => x.Value.Count); totalCount = pool.GetNodeCount();
Assert.That(totalCount, Is.EqualTo(0)); Assert.That(totalCount, Is.EqualTo(0));
} }
} }