Esempio n. 1
0
        protected void FillReserve(int reserveSize)
        {   // Fill reserve with derived class node
            Debug.Assert(reserveSize > 0);
            // Only ever need to fill reserve list
            CLink curr = pReserve;

            for (int j = 0; j < reserveSize; j++)
            {
                if (curr == null)
                {
                    curr        = this.CreateNode();
                    curr.status = CLinkStatus.Reserve;
                    ++this.mNumTotalNodes;
                    ++this.mNumReserve;
                }
                else
                {
                    CLink newNode = this.CreateNode();
                    newNode.status = CLinkStatus.Reserve;
                    newNode.pCNext = curr;
                    curr.pCPrev    = newNode;
                    curr           = newNode;
                    ++this.mNumTotalNodes;
                    ++this.mNumReserve;
                }
            }
            this.pReserve = curr;
        }
Esempio n. 2
0
        protected override void DumpNode(CLink node)
        {
            SpriteBatchNode spNode = (SpriteBatchNode)node;

            Debug.WriteLine(String.Format("\t\tSpriteBatchNode:({0})", spNode.GetHashCode()));
            Debug.WriteLine(String.Format("\t\tstatus:{0}", spNode.status));
        }
Esempio n. 3
0
        protected Container(int initialReserveSize = 3, int refillReserveSize = 1)
        {
            //safety first
            Debug.Assert(initialReserveSize > 0);
            Debug.Assert(refillReserveSize > 0);

            this.mStartNumReserve = initialReserveSize;
            //set the refill rate of reserve pool
            this.mRefillSize = refillReserveSize;

            //everything else starts as 0/null,
            //data will get fixed when pool is created below;
            this.mNumActive      = 0;
            this.mNumReserve     = 0;
            this.mTotalNodeCount = 0;

            this.mActiveHighCount = 0;

            this.pActive  = null;
            this.pReserve = null;

            //fill the reserve pool
            //relevent stats updated in this method
            this.privFillReservedPool(initialReserveSize);

            //double check relevant reserve stats;
            Debug.Assert(this.mTotalNodeCount > 0);
            Debug.Assert(this.mNumReserve == initialReserveSize);
            Debug.Assert(this.pReserve != null);
            //check for proper linkage - headNode.pPrev = null;
            Debug.Assert(this.pReserve.pCPrev == null);
        }
Esempio n. 4
0
        //same as Manager
        protected CLink baseAddToFront()
        {
            // Are there any nodes on the Reserve list?
            if (this.pReserve == null)
            {
                // refill the reserve list by the DeltaGrow
                this.privFillReservedPool(this.mRefillSize);
            }

            // Always take from the reserve list
            CLink pNode = CLink.PullFromFront(ref this.pReserve);

            Debug.Assert(pNode != null);

            // Update stats
            this.mNumActive++;
            //update active high count if needed;
            if (this.mNumActive > this.mActiveHighCount)
            {
                this.mActiveHighCount = this.mNumActive;
            }
            this.mNumReserve--;

            // copy to active
            CLink.AddToFront(ref this.pActive, pNode);

            // YES - here's your new one (may its reused from reserved)
            return(pNode);
        }
Esempio n. 5
0
        public static void AddToFront(ref CLink pHead, CLink newNode)
        {
            // Will work for Active or Reserve List

            // add to front
            Debug.Assert(newNode != null);

            // add node
            if (pHead == null)
            {
                newNode.pCNext = null;
                newNode.pCPrev = null;

                // push to the front
                pHead = newNode;
            }
            else
            {
                // push to front
                //fix the links
                newNode.pCPrev = null;
                newNode.pCNext = pHead;

                pHead.pCPrev = newNode;

                //set head reference as newNode;
                pHead = newNode;
            }

            Debug.Assert(pHead != null);
        }
Esempio n. 6
0
        protected CLink BaseAdd()
        {   // take off Reserve and move to Active
            CheckReserve();
            CLink pReserveNode = pReserve;

            if (pActive == null)
            {
                this.pReserve = this.pReserve.pCNext;
                CheckReserve();
                this.pReserve.pCPrev = null;
                pReserveNode.pCNext  = null;
                pReserveNode.pCPrev  = null;
                this.pActive         = pReserveNode;
                this.pActive.status  = CLinkStatus.Active;
            }
            else
            {
                this.pReserve = this.pReserve.pCNext;
                CheckReserve();
                this.pReserve.pCPrev = null;
                this.pActive.pCPrev  = pReserveNode;
                pReserveNode.pCNext  = this.pActive;
                pReserveNode.pCPrev  = null;
                this.pActive         = pReserveNode;
                this.pActive.status  = CLinkStatus.Active;
            }
            --this.mNumReserve;
            ++this.mNumActive;
            return(this.pActive);
        }
Esempio n. 7
0
        protected override bool Compare(CLink cLink1, CLink cLink2)
        {
            bool result = false;

            //SpriteBatchNode spNode1 = (SpriteBatchNode)cLink1;
            //SpriteBatchNode spNode2 = (SpriteBatchNode)cLink2;
            //if (spNode1.name == spNode2.name)
            //{
            //    result = true;
            //}
            return(result);
        }
Esempio n. 8
0
 public void addCollisionTest(CollisionSprite col)
 {
     if (headCollisionTests == null)
     {
         headCollisionTests = new WallCollisionData(col);
     }
     else
     {
         CLink temp = new WallCollisionData(col);
         temp.next          = headCollisionTests;
         headCollisionTests = temp;
     }
 }
Esempio n. 9
0
        public CLink pActive;   // only making this public for SpriteBatchManager.Draw();
        #endregion
        #region Protected Methods
        protected Container(int reserveSize = 5, int reserveIncrement = 1)
        {
            Debug.Assert(reserveSize > 0);
            Debug.Assert(reserveIncrement > 0);

            this.mNumDeltaGrow  = reserveIncrement;
            this.mNumReserve    = 0;
            this.mNumActive     = 0;
            this.mNumTotalNodes = 0;
            this.pActive        = null;
            this.pReserve       = null;

            this.FillReserve(reserveSize);
        }
Esempio n. 10
0
        public bool checkCollision(CollisionSprite sprite)
        {
            CLink temp = headCollisionTests;

            while (temp != null)
            {
                if (sprite.checkCollision(sprite, ((WallCollisionData)temp).getCol()))
                {
                    return(true);
                }
                temp = temp.next;
            }
            return(false);
        }
        public override void checkCollision()
        {
            CLink temp = headCollisionTests;

            while (temp != null)
            {
                if (tree.acceptGridVisit(((WallCollisionData)temp).getCol()))
                {
                    notifyObsevers(((WallCollisionData)temp).getName());
                    return;
                }
                temp = temp.next;
            }
            notifyObsevers(SpriteType.Unitialized);
        }
Esempio n. 12
0
        protected void baseRemoveNode(CLink pNode)
        {
            Debug.Assert(pNode != null);

            // Don't do the work here... delegate it
            CLink.RemoveNode(ref this.pActive, pNode);

            // wash it before returning to reserve list
            this.derivedWashNode(pNode);

            // add it to the return list
            CLink.AddToFront(ref this.pReserve, pNode);

            // stats update
            this.mNumActive--;
            this.mNumReserve++;
        }
Esempio n. 13
0
        private void privFillReservedPool(int count)
        {
            // doesn't make sense if its not at least 1
            Debug.Assert(count > 0);

            this.mTotalNodeCount += count;
            this.mNumReserve     += count;

            // Preload the reserve
            for (int i = 0; i < count; i++)
            {
                CLink pNode = this.derivedCreateNode();
                Debug.Assert(pNode != null);

                CLink.AddToFront(ref this.pReserve, pNode);
            }
        }
Esempio n. 14
0
        protected void BaseDump()
        {   // Print current state
            Debug.WriteLine("------BEGIN BaseDump------");
            Debug.WriteLine(String.Format("Number of Reserved:{0}", mNumReserve));
            Debug.WriteLine(String.Format("Number of Active:{0}", mNumActive));
            Debug.WriteLine(String.Format("Total:{0}", mNumTotalNodes));
            CLink curr = pReserve;

            Debug.WriteLine("------RESERVE------");
            if (curr == null)
            {
                Debug.WriteLine("------EMPTY------");
                Debug.WriteLine("------------------");
            }
            else
            {
                while (curr != null)
                {
                    Debug.WriteLine(String.Format("pPrev({0})", curr.pCPrev == null ? "null" : curr.pCPrev.GetHashCode().ToString()));
                    this.DumpNode(curr);
                    Debug.WriteLine(String.Format("pNext({0})", curr.pCNext == null ? "null" : curr.pCNext.GetHashCode().ToString()));
                    Debug.WriteLine("");
                    curr = curr.pCNext;
                }
            }
            Debug.WriteLine("------ACTIVE------");
            curr = pActive;
            if (curr == null)
            {
                Debug.WriteLine("------EMPTY------");
                Debug.WriteLine("------------------");
            }
            else
            {
                while (curr != null)
                {
                    Debug.WriteLine(String.Format("pPrev({0})", curr.pCPrev == null ? "null" : curr.pCPrev.GetHashCode().ToString()));
                    this.DumpNode(curr);
                    Debug.WriteLine(String.Format("pNext({0})", curr.pCNext == null ? "null" : curr.pCNext.GetHashCode().ToString()));
                    Debug.WriteLine("");
                    curr = curr.pCNext;
                }
            }
            Debug.WriteLine("------END BaseDump------");
        }
Esempio n. 15
0
        protected CLink baseFindNode(CLink pNodeRef)
        {
            // search the active list
            CLink pLink = this.pActive;

            // Walk through the nodes
            while (pLink != null)
            {
                if (derivedCompareNodes(pLink, pNodeRef))
                {
                    // found it
                    break;
                }
                pLink = pLink.pCNext;
            }

            return(pLink);
        }
Esempio n. 16
0
        public static CLink PullFromFront(ref CLink pHead)
        {
            // There should always be something on list
            Debug.Assert(pHead != null);

            // return node
            CLink pNode = pHead;

            // Update head (OK if it points to NULL)
            pHead = pHead.pCNext;
            if (pHead != null)
            {
                pHead.pCPrev = null;
            }

            // remove any lingering links
            pNode.ClearNodeLinks();

            return(pNode);
        }
Esempio n. 17
0
        protected void BaseRemove(CLink node)
        {   // remove from Active, and add to Reserve
            if (node != null)
            {
                if (node.pCPrev == null)
                {   // Remove first node in Active List
                    if (this.pActive != null && this.pActive.pCNext != null)
                    {
                        this.pActive        = this.pActive.pCNext;
                        this.pActive.pCPrev = null;
                    }
                    else
                    {   // Removing last Active node
                        this.pActive = null;
                    }
                }
                else if (node.pCNext == null)
                {   // Remove last node in Active list
                    node.pCPrev.pCNext = null;
                }
                else
                {   // Remove node somewhere in the middle
                    node.pCPrev.pCNext = node.pCNext;
                    node.pCNext.pCPrev = node.pCPrev;
                }
                // Clear foundNode and add to front of Reserve List
                node.Clear();
                node.status          = CLinkStatus.Reserve;
                node.pCNext          = this.pReserve;
                this.pReserve.pCPrev = node;
                this.pReserve        = node;

                --this.mNumActive;
                ++this.mNumReserve;
            }
            else
            {
                //Debug.WriteLine(String.Format("Node {0} was not found.", node.GetHashCode()));
            }
        }
Esempio n. 18
0
        public static void RemoveNode(ref CLink pHead, CLink targetNode)
        {
            // protection
            Debug.Assert(targetNode != null);

            // 4 different conditions...
            if (targetNode.pCPrev != null)
            {
                // middle or last node
                targetNode.pCPrev.pCNext = targetNode.pCNext;
            }
            else
            {
                // first
                pHead = targetNode.pCNext;
            }

            if (targetNode.pCNext != null)
            {
                // middle node
                targetNode.pCNext.pCPrev = targetNode.pCPrev;
            }
        }
Esempio n. 19
0
        protected CLink BaseFind(CLink node)
        {   // find node in Active list
            CLink foundNode = null;

            if (pActive == null)
            {
                foundNode = null;
            }
            else
            {
                CLink curr = pActive;
                while (curr != null)
                {
                    if (Compare(curr, node))
                    {
                        foundNode = curr;
                        break;
                    }
                    curr = curr.pCNext;
                }
            }
            return(foundNode);
        }
Esempio n. 20
0
        protected void debugPrintLists()
        {
            Debug.WriteLine("");
            Debug.WriteLine("------ Container Active List: ---------------------------\n");

            CLink pNode = this.pActive;

            int i = 0;

            while (pNode != null)
            {
                Debug.WriteLine("active index {0}: -------------", i);
                this.derivedDumpNode(pNode);
                i++;
                pNode = pNode.pCNext;
            }
            Debug.WriteLine("");
            Debug.WriteLine("------ END OF CONTAINER ACTIVE LIST: ------------------\n");


            Debug.WriteLine("");
            Debug.WriteLine("------ Container Reserve List: ---------------------------\n");

            pNode = this.pReserve;
            i     = 0;
            while (pNode != null)
            {
                Debug.WriteLine("reserve index {0}:  -------------", i);
                this.derivedDumpNode(pNode);
                i++;
                pNode = pNode.pCNext;
            }

            Debug.WriteLine("");
            Debug.WriteLine("------ END OF CONTAINER RESERVE LIST---------------------------\n");
        }
Esempio n. 21
0
 public void Clear()
 {
     this.pCPrev = null;
     this.pCNext = null;
     this.status = CLinkStatus.Unitialized;
 }
Esempio n. 22
0
 abstract protected void derivedWashNode(CLink pLink);
Esempio n. 23
0
 abstract protected void derivedDumpNode(CLink pLink);
Esempio n. 24
0
        //----------------------------------------------------------------------
        // Abstract methods - derived class must implement
        //----------------------------------------------------------------------

        abstract protected Boolean derivedCompareNodes(CLink pLinkA, CLink pLinkB);
Esempio n. 25
0
 abstract protected Boolean Compare(CLink dLink1, CLink dLink2);
Esempio n. 26
0
 abstract protected void DumpNode(CLink node);
Esempio n. 27
0
 public void ClearNodeLinks()
 {
     this.pCNext = null;
     this.pCPrev = null;
 }