forked from mirror/DotRecast
upgrade performance
This commit is contained in:
parent
80970e0051
commit
37b050081d
|
@ -26,33 +26,40 @@ namespace DotRecast.Core
|
|||
|
||||
public class OrderedQueue<T>
|
||||
{
|
||||
private bool _dirty;
|
||||
private readonly List<T> _items;
|
||||
private readonly Comparison<T> _comparison;
|
||||
|
||||
public OrderedQueue(Comparison<T> comparison)
|
||||
{
|
||||
_items = new List<T>();
|
||||
_comparison = comparison;
|
||||
_comparison = (x, y) => comparison.Invoke(x, y) * -1; // reverse
|
||||
}
|
||||
|
||||
public int count()
|
||||
public int Count()
|
||||
{
|
||||
return _items.Count;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
public void Clear()
|
||||
{
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
public T top()
|
||||
public T Top()
|
||||
{
|
||||
return _items[0];
|
||||
if (_dirty)
|
||||
{
|
||||
_items.Sort(_comparison); // reverse
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
return _items[_items.Count - 1];
|
||||
}
|
||||
|
||||
public T Dequeue()
|
||||
{
|
||||
var node = top();
|
||||
var node = Top();
|
||||
_items.Remove(node);
|
||||
return node;
|
||||
}
|
||||
|
@ -60,15 +67,19 @@ namespace DotRecast.Core
|
|||
public void Enqueue(T item)
|
||||
{
|
||||
_items.Add(item);
|
||||
_items.Sort(_comparison);
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public void Remove(T item)
|
||||
{
|
||||
_items.Remove(item);
|
||||
int idx = _items.FindLastIndex(x => item.Equals(x));
|
||||
if (0 > idx)
|
||||
return;
|
||||
|
||||
_items.RemoveAt(idx);
|
||||
}
|
||||
|
||||
public bool isEmpty()
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return 0 == _items.Count;
|
||||
}
|
||||
|
|
|
@ -662,7 +662,7 @@ namespace DotRecast.Detour.Crowd
|
|||
}
|
||||
}
|
||||
|
||||
while (!queue.isEmpty())
|
||||
while (!queue.IsEmpty())
|
||||
{
|
||||
CrowdAgent ag = queue.Dequeue();
|
||||
ag.targetPathQueryResult = m_pathq.request(ag.corridor.getLastPoly(), ag.targetRef, ag.corridor.getTarget(),
|
||||
|
@ -850,7 +850,7 @@ namespace DotRecast.Detour.Crowd
|
|||
}
|
||||
}
|
||||
|
||||
while (!queue.isEmpty())
|
||||
while (!queue.IsEmpty())
|
||||
{
|
||||
CrowdAgent ag = queue.Dequeue();
|
||||
ag.corridor.optimizePathTopology(navQuery, m_filters[ag.option.queryFilterType], _config.maxTopologyOptimizationIterations);
|
||||
|
|
|
@ -18,17 +18,19 @@ freely, subject to the following restrictions:
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class NodeQueue
|
||||
{
|
||||
private readonly List<Node> m_heap = new List<Node>();
|
||||
private readonly OrderedQueue<Node> m_heap = new OrderedQueue<Node>((n1, n2) => n1.total.CompareTo(n2.total));
|
||||
|
||||
public int count()
|
||||
{
|
||||
return m_heap.Count;
|
||||
return m_heap.Count();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
|
@ -38,7 +40,7 @@ namespace DotRecast.Detour
|
|||
|
||||
public Node top()
|
||||
{
|
||||
return m_heap[0];
|
||||
return m_heap.Top();
|
||||
}
|
||||
|
||||
public Node pop()
|
||||
|
@ -50,8 +52,7 @@ namespace DotRecast.Detour
|
|||
|
||||
public void push(Node node)
|
||||
{
|
||||
m_heap.Add(node);
|
||||
m_heap.Sort((x, y) => x.total.CompareTo(y.total));
|
||||
m_heap.Enqueue(node);
|
||||
}
|
||||
|
||||
public void modify(Node node)
|
||||
|
@ -62,7 +63,7 @@ namespace DotRecast.Detour
|
|||
|
||||
public bool isEmpty()
|
||||
{
|
||||
return 0 == m_heap.Count;
|
||||
return 0 == m_heap.Count();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue