Пример #1
0
        public static void RemoveFromList(ref DLink pCurrentHead, DLink pNodeToRemove)
        {
            Debug.Assert(pNodeToRemove != null);

            DLink pTmpNode = pNodeToRemove;

            // If pNode is head of list
            if (pCurrentHead == pNodeToRemove)
            {
                pCurrentHead = pCurrentHead.GetNext();

                if (pCurrentHead != null)
                {
                    // Set prev to null - it's the new list head
                    pCurrentHead.SetPrev(null);
                }
            }
            else
            {
                if (pTmpNode.GetPrev() != null)
                {
                    // Set the previous node's next to pNode's next
                    pTmpNode.GetPrev().SetNext(pNodeToRemove.GetNext());
                }

                if (pTmpNode.GetNext() != null)
                {
                    // Set the next node's prev to pNodes prev
                    pTmpNode.GetNext().SetPrev(pTmpNode.GetPrev());
                }
            }
        }
Пример #2
0
        protected DLink BaseGetNodeFromReserve()
        {
            // If pReserve is empty, refill with growDelta
            if (pReserve == null)
            {
                AddToReservedList(this.growDelta);
            }

            // Get and remove head of pReserve (as pNode)
            Debug.Assert(pReserve != null);
            DLink pNodeToActivate = pReserve;

            // Set new head of Reserve
            pReserve = pReserve.GetNext();

            // If new head is not null, clear its previous link to newly activated node
            if (pReserve != null)
            {
                pReserve.SetPrev(null);
            }

            // "Clean" values of pNode
            pNodeToActivate.Clean();

            return(pNodeToActivate);
        }
Пример #3
0
        public virtual void Print()
        {
            DLink pNode = this.pHead;

            while (pNode != null)
            {
                Debug.Write(pNode + ", ");

                pNode = pNode.GetNext();
            }
            Debug.WriteLine("");
        }
Пример #4
0
        public virtual void Notify()
        {
            DLink pNode = this.pHead;

            while (pNode != null)
            {
                // Fire off listener
                ((Observer)pNode).Update(this);

                pNode = pNode.GetNext();
            }
        }
Пример #5
0
        public virtual void PurgeAll()
        {
            DLink pNode = this.pHead;
            DLink pTmp  = null;

            while (pHead != null)
            {
                // hold next, delete current, pass next to current
                pTmp = pNode.GetNext();
                DLink.Remove(ref this.pHead, pNode);
                pNode = pTmp;
            }
        }
Пример #6
0
        public override void Print()
        {
            Debug.WriteLine(" GameObject Name: {0} ({1})", this.GetName(), this.GetHashCode());
            base.Print();

            DLink pNode = pHead;

            while (pNode != null)
            {
                pNode.Print();
                pNode = pNode.GetNext();
            }
        }
Пример #7
0
        public override Component GetLastChild()
        {
            DLink pNode = this.poHeadChild;
            DLink pTmp  = null;

            while (pNode != null)
            {
                pTmp  = pNode;
                pNode = pNode.GetNext();
            }

            return((Component)pTmp);
        }
Пример #8
0
        public override string ToString()
        {
            String returnVal = String.Format("[Composite Component: ({0})", this.GetHashCode());

            DLink pNode = this.poHeadChild;

            while (pNode != null)
            {
                returnVal += pNode.ToString();
                returnVal += ", ";
                pNode      = pNode.GetNext();
            }

            return(returnVal + " ]\n");
        }
        public override string ToString()
        {
            String returnVal = "[GameObjectComposite: " + base.ToString();

            DLink pNode = this.poHeadChild;

            while (pNode != null)
            {
                returnVal += pNode.ToString();
                returnVal += ", ";
                pNode      = pNode.GetNext();
            }

            return(returnVal + " ]\n");
        }
Пример #10
0
        protected DLink BaseFind(DLink refNode)
        {
            DLink tmpNode = pActive;

            while (tmpNode != null)
            {
                if (CompareTo(tmpNode, refNode))
                {
                    break;
                }
                tmpNode = tmpNode.GetNext();
            }

            return(tmpNode);
        }
Пример #11
0
        public override void Move(float xDelta, float yDelta)
        {
            DLink pNode = this.pHead;

            while (pNode != null)
            {
                // Get component
                Component pComponent = (Component)pNode;

                // Move component
                pComponent.Move(xDelta, yDelta);

                // Increment pointer along list
                pNode = pNode.GetNext();
            }
        }
Пример #12
0
        public void DetachAllObservers()
        {
            DLink pNode = this.head;
            DLink pTmpNode;

            while (pNode != null)
            {
                // Walk through the list
                pTmpNode = pNode;
                pNode = pNode.GetNext();

                // Clear and remove node
                Debug.Assert(pTmpNode != null);
                DLink.RemoveFromList(ref this.head, pTmpNode);
                pTmpNode = null;
            }
        }
Пример #13
0
        //----------------------------------------------------------------------
        // Private methods
        //----------------------------------------------------------------------

        private void ClearList(DLink listHead)
        {
            DLink pNode;
            DLink pTmpNode;

            pNode = listHead;
            while (pNode != null)
            {
                // Walk through the list
                pTmpNode = pNode;
                pNode    = pNode.GetNext();

                // Clear and remove node
                Debug.Assert(pTmpNode != null);
                this.DerivedDestroyNode(pTmpNode);
                DLink.RemoveFromList(ref listHead, pTmpNode);
                pTmpNode = null;
            }
        }
Пример #14
0
        public Composite GetChildByIndex(int index)
        {
            Debug.Assert(index >= 0);
            Debug.Assert(index < numChildren);

            DLink pNode = this.pHead;
            int   count = 0;

            while (count <= index)
            {
                if (count == index)
                {
                    return((Composite)pNode);
                }

                pNode = pNode.GetNext();
                count++;
            }

            return(null);
        }
Пример #15
0
        private void ClearList(DLink listHead)
        {
            DLink pNode;
            DLink pTmpNode;

            pNode = listHead;
            while (pNode != null)
            {
                // Walk through the list
                pTmpNode = pNode;
                pNode    = pNode.GetNext();

                // Clear and remove node
                Debug.Assert(pTmpNode != null);
                this.DerivedDestroyNode(pTmpNode);
                DLink.RemoveFromList(ref this.pActive, pTmpNode);
                pTmpNode = null;

                // Decrement total count
                this.totalNodeNum--;
            }
        }
Пример #16
0
        public override void Move(float dummyX, float dummyY)
        {
            DLink pNode = this.pHead;

            // #1 - Initial movement since wall collision - Move down
            if (switchXDirection && !directionChangePending)
            {
                this.SetXDelta(0.0f);
                this.SetYDelta(-25.0f);
                this.directionChangePending = true;
            }

            while (pNode != null)
            {
                // Get component
                Component pComponent = (Component)pNode;

                // Move component
                pComponent.Move(this.xDelta, this.yDelta);

                pNode = pNode.GetNext();
            }

            // #3 - Finally, Grid has moved off wall, reset direction change flag
            if (directionChangePending && !switchXDirection)
            {
                this.directionChangePending = false;
            }

            // #2 - Movement down complete, switch X direction
            if (switchXDirection == true)
            {
                // Reset deltas to horizontal movement in opposite direction
                this.yDelta           = 0.0f;
                this.xDelta           = (this.prevXDelta * -1.0f);
                this.switchXDirection = false;
            }
        }
Пример #17
0
        //----------------------------------------------------------------------
        // Private methods
        //----------------------------------------------------------------------

        private DLink FindGameObjectByReference(DLink pSearchGameObject)
        {
            // If no nodes in Active list
            if (pActive == null)
            {
                return(null);
            }

            // Iterate over active list, starting at head
            DLink pSearchIterator = pActive;

            while (pSearchIterator != null)
            {
                // Compare current node to provided DLink node. If match, return node
                if (HashCodeCompare(pSearchIterator, pSearchGameObject))
                {
                    return(pSearchIterator);
                }
                pSearchIterator = pSearchIterator.GetNext();
            }

            // If no match is found
            return(null);
        }
Пример #18
0
        /// <summary>
        /// Finds first node that matches the DLink node passed in as pNodeTarget. Returns null if no matching node is found.
        /// </summary>
        /// <param name="sd">Instance of DLink that will be compared against Active list nodes using derivedCompare()</param>
        /// <returns></returns>
        protected DLink BaseFind(DLink pNodeTarget)
        {
            // If no nodes in Active list
            if (pActive == null)
            {
                return(null);
            }

            // Iterate over active list, starting at head
            DLink pSearchIterator = pActive;

            while (pSearchIterator != null)
            {
                // Compare current node to provided DLink node. If match, return node
                if (DerivedCompare(pSearchIterator, pNodeTarget))
                {
                    return(pSearchIterator);
                }
                pSearchIterator = pSearchIterator.GetNext();
            }

            // If no match is found
            return(null);
        }