//to destroy game objects that are hit public static void Dettach(GameObject pGameObject) { GONodeMan pGOMan = GONodeMan.PrivGetInstance(); Debug.Assert(pGOMan != null); //Remeber: a doublly linked list of trees //whatever game object we get, we have to travel up its tree // to its its tree's root/ upper most parent Debug.Assert(pGameObject != null); GameObject pTemp = pGameObject; GameObject pRoot = null; while (pTemp != null) { pRoot = pTemp; pTemp = (GameObject)Iterator.GetParent(pTemp); //keep traveling up the tree //exit out at the top of the tree } //Found the tree our game object is in // now go traverse the DLink list to that tree GONode pTree = (GONode)pGOMan.BaseGetActive(); while (pTree != null) { //check if the game objects match if (pTree.poGameObject == pRoot) { break; } pTree = (GONode)pTree.pNext; } //Now we are in the tree with the Game Object //we need to remove Debug.Assert(pTree != null); Debug.Assert(pTree.poGameObject != null); GameObject pParent = (GameObject)Iterator.GetParent(pGameObject); Debug.Assert(pParent != null); GameObject pChild = (GameObject)Iterator.GetChild(pGameObject); Debug.Assert(pChild == null); //finally //Remove Gamobject from its parent composite pParent.Remove(pGameObject); }
public static void Update() { // go through active list and update everything in it // while loop GONodeMan pMan = GONodeMan.PrivGetInstance(); Debug.Assert(pMan != null); //Debug.WriteLine("---------------"); GONode pGONode = (GONode)pMan.BaseGetActive(); while (pGONode != null) { //Debug.WriteLine("update: GameObjectTree {0} ({1})", pGONode.poGameObject, pGONode.poGameObject.GetHashCode()); //Debug.WriteLine(" +++++"); if (pGONode.poGameObject.GetPlayerOption() == true) { ReverseIterator pRev = new ReverseIterator(pGONode.poGameObject); //need to update the children 1st then work our way back up the tree // So depth first(ReverseIterator) // maintaines integrity of the bounding collision rectangles 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(" ------"); pGONode = (GONode)pGONode.pNext; } } }