Example #1
0
        public static void Update()
        {
            GameObjectMan pMan = GameObjectMan.PrivGetInstance();

            Debug.Assert(pMan != null);

            //Debug.WriteLine("---------------");

            GameObjectNode pGameObjectNode = (GameObjectNode)pMan.BaseGetActive();

            while (pGameObjectNode != null)
            {
                //Debug.WriteLine("update: GameObjectTree {0} ({1})", pGameObjectNode.poGameObj, pGameObjectNode.poGameObj.GetHashCode());
                // Debug.WriteLine("   +++++");
                ReverseIterator pRev = new ReverseIterator(pGameObjectNode.poGameObj);

                Component pNode = pRev.First();
                while (!pRev.IsDone())
                {
                    GameObject pGameObj = (GameObject)pNode;

                    //Debug.WriteLine("update: {0} ({1})", pGameObj, pGameObj.GetHashCode());
                    pGameObj.Update();

                    pNode = pRev.Next();
                }

                //Debug.WriteLine("   ------");
                pGameObjectNode = (GameObjectNode)pGameObjectNode.pNext;
            }
        }
Example #2
0
        public static void Remove(GameObject pNode)
        {
            Debug.Assert(pNode != null);
            GameObjectMan pMan = GameObjectMan.PrivGetInstance();

            GameObject pSafetyNode = pNode;

            // OK so we have a linked list of trees (Remember that)

            // 1) find the tree root (we already know its the most parent)

            GameObject pTmp  = pNode;
            GameObject pRoot = null;

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

            // 2) pRoot is the tree we are looking for
            // now walk the active list looking for pRoot

            GameObjectNode pTree = (GameObjectNode)pMan.BaseGetActive();

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

            // 3) pTree is the tree that holds pNode
            //  Now remove the node from that tree

            Debug.Assert(pTree != null);
            Debug.Assert(pTree.pGameObj != null);

            // Is pTree.poGameObj same as the node we are trying to delete?
            // Answer: should be no... since we always have a group (that was a good idea)

            Debug.Assert(pTree.pGameObj != pNode);

            GameObject pParent = (GameObject)Iterator.GetParent(pNode);

            Debug.Assert(pParent != null);

            GameObject pChild = (GameObject)Iterator.GetChild(pNode);

            Debug.Assert(pChild == null);

            // remove the node
            pParent.Remove(pNode);

            // Still need to optimize
        }