Exemple #1
0
        public static PCSTree GetRootTree()
        {
            GameObjectManager pMan = GameObjectManager.privGetInstance();

            Debug.Assert(pMan.pRootTree != null);
            return(pMan.pRootTree);
        }
Exemple #2
0
        //----------------------------------------------------------------------
        // 4 Wrapper methods: baseAdd, baseFind, baseRemove, baseDump
        //----------------------------------------------------------------------

        //Remove GameObject Node
        public static void Remove(GameObjectNode pNode)
        {
            Debug.Assert(pNode != null);
            GameObjectManager pMan = GameObjectManager.privGetInstance();

            pMan.baseRemoveNode(pNode);
        }
Exemple #3
0
        public static void SetActive(GameObjectManager pGameMan)
        {
            GameObjectManager pManager = GameObjectManager.privGetInstance();

            Debug.Assert(pManager != null);

            Debug.Assert(pGameMan != null);
            GameObjectManager.pActiveManager = pGameMan;
        }
Exemple #4
0
        //public static GameObjectNode AttachTree(GameObject pGameObject, PCSTree pTree)
        //{
        //    //safety first
        //    Debug.Assert(pGameObject != null);

        //    GameObjectManager pMan = GameObjectManager.privGetInstance();
        //    Debug.Assert(pMan != null);

        //    GameObjectNode pNode = (GameObjectNode)pMan.baseAddToFront();
        //    Debug.Assert(pNode != null);


        //    Debug.Assert(pTree != null);
        //    pNode.Set(pGameObject, pTree);

        //    return pNode;
        //}

        public static GameObjectNode AttachTree(GameObject pGameObject)
        {
            Debug.Assert(pGameObject != null);

            GameObjectManager pMan = GameObjectManager.privGetInstance();

            GameObjectNode pNode = (GameObjectNode)pMan.baseAddToFront();

            Debug.Assert(pNode != null);

            pNode.Set(pGameObject);
            return(pNode);
        }
Exemple #5
0
        public static void Destroy()
        {
            // Get the instance
            GameObjectManager pMan = GameObjectManager.privGetInstance();

            #if (TRACK_DESTRUCTOR)
            Debug.WriteLine("--->GameObjectMan.Destroy()");
            #endif

            pMan.baseDestroy();
            GameObjectManager.pRefNode  = null;
            GameObjectManager.pInstance = null;
        }
Exemple #6
0
        //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);
        }
Exemple #7
0
        //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);
        }
Exemple #8
0
        public static void Insert(GameObject pGameObj, GameObject pParent)
        {
            GameObjectManager pMan = GameObjectManager.privGetInstance();

            Debug.Assert(pGameObj != null);

            if (pParent == null)
            {
                //GameObjectManager.AttachTree(pGameObj, null);
                GameObjectManager.AttachTree(pGameObj);
            }
            else
            {
                //parent shouldn't be null if here
                Debug.Assert(pParent != null);

                //set the root as the parent and insert pGamObj as
                //a child of the parent in the same tree;
                pMan.pRootTree.SetRoot(pParent);
                pMan.pRootTree.Insert(pGameObj, pParent);
            }
        }
Exemple #9
0
        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;
            }
        }