public DynamicTree() { m_root = TreeNode.NULL_NODE; m_nodeCount = 0; m_nodeCapacity = 16; m_nodes = new TreeNode[16]; // Build a linked list for the free list. for (int i = 0; i < m_nodeCapacity; i++) { m_nodes[i] = new TreeNode(); m_nodes[i].parent = i + 1; m_nodes[i].height = -1; } m_nodes[m_nodeCapacity - 1].parent = TreeNode.NULL_NODE; m_freeList = 0; m_insertionCount = 0; for (int i = 0; i < drawVecs.Length; i++) { drawVecs[i] = new Vec2(); } }
private int allocateNode() { if (m_freeList == TreeNode.NULL_NODE) { Debug.Assert(m_nodeCount == m_nodeCapacity); TreeNode[] old = m_nodes; m_nodeCapacity *= 2; m_nodes = new TreeNode[m_nodeCapacity]; Array.Copy(old, 0, m_nodes, 0, old.Length); // Build a linked list for the free list. for (int i = m_nodeCount; i < m_nodeCapacity; i++) { m_nodes[i] = new TreeNode(); m_nodes[i].parent = i + 1; m_nodes[i].height = -1; } m_nodes[m_nodeCapacity - 1].parent = TreeNode.NULL_NODE; m_freeList = m_nodeCount; } int nodeId = m_freeList; m_freeList = m_nodes[nodeId].parent; m_nodes[nodeId].parent = TreeNode.NULL_NODE; m_nodes[nodeId].child1 = TreeNode.NULL_NODE; m_nodes[nodeId].child2 = TreeNode.NULL_NODE; m_nodes[nodeId].height = 0; m_nodes[nodeId].userData = null; ++m_nodeCount; return nodeId; }