public static void Update() { GameObjectManager pMan = GameObjectManager.pActiveManager; 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; } }
//Remove from GameObject PCSTree public static void Remove(GameObject pNode) { Debug.Assert(pNode != null); GameObjectManager pMan = GameObjectManager.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)pTmp.pParent; } // 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.pMNext; } // 3) pTree is the tree that holds pNode // Now remove it Debug.Assert(pTree != null); Debug.Assert(pTree.pGameObj != null); pMan.pRootTree.SetRoot(pTree.pGameObj); pMan.pRootTree.Remove(pNode); }
//public static GameObject Find(GameObject.Name name) //{ // //get the singleton // GameObjectManager pMan = privGetInstance(); // // Compare functions only compares two Nodes // GameObjectManager.pRefNode.pGameObj.SetName(name); // GameObjectNode pNode = (GameObjectNode)pMan.baseFindNode(GameObjectManager.pRefNode); // Debug.Assert(pNode != null); // return pNode.pGameObj; //} public static GameObject Find(GameObject.Name name, int index = 0) { GameObjectManager pMan = GameObjectManager.privGetInstance(); // Compare functions only compares two Nodes GameObjectManager.pRefNode.pGameObj.SetName(name); GameObjectManager.pRefNode.pGameObj.index = index; GameObjectNode pRoot = (GameObjectNode)pMan.baseGetActive(); GameObject pGameObj = null; bool found = false; while (pRoot != null && found == false) { // OK at this point, I have a Root tree, // need to walk the tree completely before moving to next tree //forward navigation PCSTreeForwardIterator pIterator = new PCSTreeForwardIterator(pRoot.pGameObj); // Initialize pGameObj = (GameObject)pIterator.First(); //while (pGameObj != null) while (!pIterator.IsDone()) { //check for both matching name and index if (pGameObj.GetName() == GameObjectManager.pRefNode.pGameObj.GetName() && pGameObj.index == GameObjectManager.pRefNode.pGameObj.index) { found = true; break; } // Advance pGameObj = (GameObject)pIterator.Next(); } // Goto Next tree pRoot = (GameObjectNode)pRoot.pMNext; } return(pGameObj); }
public static void Update() { GameObjectManager pMan = GameObjectManager.privGetInstance(); //get the root game object GameObjectNode pRoot = (GameObjectNode)pMan.baseGetActive(); while (pRoot != null) { // OK at this point, I have a Root tree, // need to walk the tree completely before moving to next tree //todo double check on forward or reverse iteration //PCSTreeIterator pIterator = new PCSTreeIterator(pRoot.pGameObj); PCSTreeForwardIterator pIterator = new PCSTreeForwardIterator(pRoot.pGameObj); //PCSTreeReverseIterator pIterator = new PCSTreeReverseIterator(pRoot.pGameObj); // Initialize the first game object pointer GameObject pGameObj = (GameObject)pIterator.First(); //iterate through and update all GameObjects in this tree/subtree //Debug.WriteLine("-------"); while (!pIterator.IsDone()) { //Debug.WriteLine(" {0}", pGameObj.GetName()); pGameObj.Update(); // Advance pGameObj = (GameObject)pIterator.Next(); } // Go to next tree pRoot = (GameObjectNode)pRoot.pMNext; } }
public static void Remove(GameObject pNode) { // Keenan(delete.E) Debug.Assert(pNode != null); GameObjectManager pMan = GameObjectManager.pActiveManager; Debug.Assert(pMan != null); 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.poGameObj == 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.poGameObj != 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.poGameObj != pNode); GameObject pParent = (GameObject)Iterator.GetParent(pNode); Debug.Assert(pParent != null); // Make sure there is no child before the delete GameObject pChild = (GameObject)Iterator.GetChild(pNode); Debug.Assert(pChild == null); // remove the node pParent.Remove(pNode); // FOUND the bug!!!! pParent.Update(); // TODO - Recycle pNode }