2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
|
|
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
2023-03-15 17:00:29 +03:00
|
|
|
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2023-03-16 19:09:10 +03:00
|
|
|
namespace DotRecast.Detour
|
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
public class DtNodePool
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
private readonly Dictionary<long, List<DtNode>> m_map = new Dictionary<long, List<DtNode>>();
|
|
|
|
private readonly List<DtNode> m_nodes = new List<DtNode>();
|
2023-03-16 19:09:10 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtNodePool()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public void Clear()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
m_nodes.Clear();
|
|
|
|
m_map.Clear();
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2024-02-01 18:29:24 +03:00
|
|
|
public int FindNodes(long id, out List<DtNode> nodes)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2024-02-01 18:29:24 +03:00
|
|
|
var hasNode = m_map.TryGetValue(id, out nodes);
|
|
|
|
if (hasNode)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2024-02-01 18:29:24 +03:00
|
|
|
return nodes.Count;
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2024-02-01 18:29:24 +03:00
|
|
|
return 0;
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtNode FindNode(long id)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
var hasNode = m_map.TryGetValue(id, out var nodes);
|
|
|
|
if (nodes != null && 0 != nodes.Count)
|
|
|
|
{
|
|
|
|
return nodes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtNode GetNode(long id, int state)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
var hasNode = m_map.TryGetValue(id, out var nodes);
|
|
|
|
if (nodes != null)
|
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
foreach (DtNode node in nodes)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
if (node.state == state)
|
|
|
|
{
|
|
|
|
return node;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
2023-07-21 08:35:45 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
nodes = new List<DtNode>();
|
|
|
|
m_map.Add(id, nodes);
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-07-21 08:35:45 +03:00
|
|
|
return Create(id, state, nodes);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-07-21 08:35:45 +03:00
|
|
|
private DtNode Create(long id, int state, List<DtNode> nodes)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
DtNode node = new DtNode(m_nodes.Count + 1);
|
2023-03-16 19:48:49 +03:00
|
|
|
node.id = id;
|
|
|
|
node.state = state;
|
|
|
|
m_nodes.Add(node);
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
nodes.Add(node);
|
|
|
|
return node;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public int GetNodeIdx(DtNode node)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return node != null ? node.index : 0;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtNode GetNodeAtIdx(int idx)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return idx != 0 ? m_nodes[idx - 1] : null;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtNode GetNode(long refs)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
return GetNode(refs, 0);
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
2023-03-16 19:09:10 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public Dictionary<long, List<DtNode>> GetNodeMap()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_map;
|
|
|
|
}
|
|
|
|
}
|
2023-04-29 06:48:56 +03:00
|
|
|
}
|