Exemplo n.º 1
0
        public static void Remove(GameObject pNode)
        {
            Debug.Assert(pNode != null);
            GameObjectManager pMan = GameObjectManager.PrivGetInstance();

            Debug.Assert(pMan != null);

            // pNode may be part of a tree. If so, find it's root.
            // The root will be on the GameObjectManager's Linked list
            GameObject pRoot = null;
            GameObject pTmp  = pNode;

            while (pTmp != null)
            {
                pRoot = pTmp;
                pTmp  = (GameObject)pTmp.GetParent();
            }

            Debug.Assert(pRoot != null);

            // Now that we have the root of pNode's tree, or we have pNode if it has no parent
            // lets find that node on the GameObjectManager's Linked list
            GameObjectNode pTree = (GameObjectNode)pMan.BaseGetActive();

            while (pTree != null)
            {
                if (pTree.pGameObj == pRoot)
                {
                    // found it
                    break;
                }
                // Goto Next tree
                pTree = (GameObjectNode)pTree.GetNext();
            }

            // pTree should now be holding the node that matches Root
            Debug.Assert(pTree != null);

            // we shouldn't kills nodes with families right?
            // we aren't monsters
            Debug.Assert(pNode.GetFirstChild() == null);

            // check to see if pTree is just holding pNode or if
            // it is holding a tree containing pNode
            GameObject pNodeParent = (GameObject)pNode.GetParent();

            if (pTree.pGameObj == pNode)
            {
                // pNode is not part of a tree so just remove it.
                Debug.Assert(pNodeParent == null);
                Remove(pTree);
            }
            else
            {
                // pNode is a part of a tree so we'll use the node's
                // parent composite remove method to remove it.
                Debug.Assert(pNodeParent != null);
                pNodeParent.Remove(pNode);
            }
        }