Esempio n. 1
0
        /// <summary>
        /// 获取结点的所有的子结点(包括子结点的子结点,但不包括当前结点)
        /// </summary>
        /// <returns></returns>
        public QuadNode[] GetTotalChildNodes()
        {
            List <QuadNode> nodeList = QuadPool.GetNodeList();

            SearchNodes(this, nodeList, false, true);
            QuadNode[] result = nodeList.ToArray();
            QuadPool.ReleaseNodeList(nodeList);
            return(result);
        }
Esempio n. 2
0
        //对象删除或更新后,需要对旧的结点进行合并操作
        private void MergeNode(QuadNode mergedNode)
        {
            if (mergedNode == null || mergedNode.ObjectCount >= m_NodeSplitThreshold)
            {
                return;
            }

            QuadNode targetNode = mergedNode;

            while (targetNode != null)
            {
                if (targetNode.ParentNode != null && targetNode.ParentNode.GetTotalObjectCount() >= m_NodeSplitThreshold)
                {
                    break;
                }

                targetNode = targetNode.ParentNode;
            }

            if (targetNode != null && !targetNode.IsLeaf)
            {
                List <QuadNode> nodeList = QuadPool.GetNodeList();
                targetNode.GetTotalChildNodes(ref nodeList);
                List <IQuadObject> objectList = QuadPool.GetObjectList();
                targetNode.GetTotalObjects(ref objectList);

                targetNode[QuadNodeDirection.LB] = null;
                targetNode[QuadNodeDirection.RB] = null;
                targetNode[QuadNodeDirection.LT] = null;
                targetNode[QuadNodeDirection.RT] = null;

                foreach (var childNode in nodeList)
                {
                    m_NodePool.Release(childNode);
                }

                targetNode.ClearObjects();
                foreach (var obj in objectList)
                {
                    m_ObjectToNodeDic.Remove(obj);
                    InsertObjectToNode(targetNode, obj);
                }

                QuadPool.ReleaseNodeList(nodeList);
                QuadPool.ReleaseObjectList(objectList);
            }
        }