public static void Remove(GameObject pNode) { // Keenan(delete.E) Debug.Assert(pNode != null); //GameObjectMan pMan = GameObjectMan.privGetInstance(); GameObjectMan pMan = GameObjectMan.pActiveGOMan; 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); // TODO - Recycle pNode }
public static void Update() { //GameObjectMan pMan = GameObjectMan.privGetInstance(); GameObjectMan pMan = GameObjectMan.pActiveGOMan; Debug.Assert(pMan != null); GameObjectNode pGameObjectNode = (GameObjectNode)pMan.baseGetActive(); while (pGameObjectNode != null) { ReverseIterator pRev = new ReverseIterator(pGameObjectNode.pGameObj); Component pNode = pRev.First(); while (!pRev.IsDone()) { GameObject pGameObj = (GameObject)pNode; //Debug.WriteLine("update: {0} ({1})", pGameObj, pGameObj.GetHashCode()); pGameObj.Update(); pNode = pRev.Next(); } pGameObjectNode = (GameObjectNode)pGameObjectNode.pNext; } }
public static void Remove(GameObject pNode) { Debug.Assert(pNode != null); GameObjectMan pMan = GameObjectMan.privGetInstance(); GameObject pSafetyNode = pNode; GameObject pTmp = pNode; GameObject pRoot = null; while (pTmp != null) { pRoot = pTmp; pTmp = (GameObject)Iterator.GetParent(pTmp); } GameObjectNode pTree = (GameObjectNode)pMan.baseGetActive(); while (pTree != null) { if (pTree.poGameObj == pRoot) { break; } pTree = (GameObjectNode)pTree.pNext; } Debug.Assert(pTree != null); Debug.Assert(pTree.poGameObj != null); if (pTree.poGameObj == pNode) { return; } Debug.Assert(pTree.poGameObj != pNode); GameObject pParent = (GameObject)Iterator.GetParent(pNode); Debug.Assert(pParent != null); GameObject pChild = (GameObject)Iterator.GetChild(pNode); Debug.Assert(pChild == null); pParent.Remove(pNode); pParent.Update(); // TODO - Recycle pNode }