Beispiel #1
0
        public void Search <T>(Func <ISpatialObject, bool> predicate,
                               Func <ISpatialObject, float> prioritizer,
                               int maxResultsCount,
                               ICollection <T> results) where T : ISpatialObject
        {
            lock (m_Lock)
            {
                var count = 0;
                m_PriorityHeap.Clear();
                results.Clear();
                m_PriorityHeap.Push(m_RootNode);

                while (count < maxResultsCount && !m_PriorityHeap.isEmpty)
                {
                    if (!m_PriorityHeap.TryPop(out var obj))
                    {
                        break;
                    }

                    if (obj is SpatialNode node)
                    {
                        foreach (var child in node.children)
                        {
                            if (!predicate(child))
                            {
                                continue;
                            }

                            child.priority = prioritizer(child);
                            m_PriorityHeap.Push(child);
                        }

                        continue;
                    }

                    results.Add((T)obj);
                    ++count;
                }
            }
        }
 void OnLoad(SpatialObject obj)
 {
     m_ObjectsToLoad.Push(obj);
 }