Ejemplo n.º 1
0
        protected DLink BaseAdd()
        {
            // Are there any nodes on the Reserve list?
            if (this.poReserve == null)
            {
                // refill the reserve list by the DeltaGrow
                this.PrivFillReservedPool(this.mDeltaGrow);
            }

            // Always take from the reserve list
            DLink pLink = DLink.PopFromFront(ref this.poReserve);

            Debug.Assert(pLink != null);

            // Wash it
            this.DerivedWash(pLink);

            // Update stats
            this.mNumActive++;
            this.mNumReserved--;

            // copy to active
            DLink.AddToFront(ref this.poActive, pLink);

            // YES - here's your new one (its recycled from reserved)
            return(pLink);
        }
Ejemplo n.º 2
0
        protected DLink BaseAddToPosition(DLink pNode)
        {
            if (this.poReserve == null)
            {
                this.PrivFillReservedPool(this.mDeltaGrow);
            }

            DLink pLink = DLink.PullFromFront(ref this.poReserve);

            Debug.Assert(pLink != null);

            // Wash it
            this.DerivedWash(pLink);

            // Update stats
            this.mNumActive++;
            this.mNumReserved--;

            // copy to active
            if (pNode == null)
            {
                DLink.AddToFront(ref this.poActive, pLink);
            }
            else
            {
                DLink.AddToBehind(ref pNode, pLink);
            }

            // YES - here's your new one (its recycled from reserved)
            return(pLink);
        }
Ejemplo n.º 3
0
        protected DLink BaseAdd()
        {
            DLink newNode = DLink.RemoveFront(ref pReserve);

            if (newNode == null && growthSize > 0)
            {
                RefreshReserve();
                newNode = DLink.RemoveFront(ref pReserve);
                DLink.AddToFront(ref pActive, newNode);
            }
            else if (newNode != null)
            {
                newNode.Wash();
                DLink.AddToFront(ref pActive, newNode);
            }
            else
            {
                Debug.Assert(false, "Cannot add new node because reserve is empty and growth size is " + growthSize);
            }

            mNumActive++;
            mNumReserve--;

            return(newNode);
        }
Ejemplo n.º 4
0
        protected DLink BaseAdd()
        {
            // If any node doesn't exist in reserve list.
            if(this.pReserve == null)
            {
                // Refill the reserve list by the growthSize
                this.PrivFillReservedPool(this.growthSize);
            }

            // Always take from the reserve list
            DLink pLink = DLink.PullFromFront(ref this.pReserve);
            Debug.Assert(pLink != null);

            // Wash it
            this.DerivedWash(pLink);

            // Update stats
            this.mNumActive++;
            this.mNumReserve--;
            if (this.mNumActive > this.maximumNumActive)
            {
                this.maximumNumActive = this.mNumActive;
            }

            // copy to active
            DLink.AddToFront(ref this.pActive, pLink);
            return pLink;
        }
Ejemplo n.º 5
0
        //----------------------------------------------------------------------
        // Base Methods
        //----------------------------------------------------------------------
        public DLink baseAdd()
        {
            //calls addtofront in DLink
            // derived add method will have parameters

            //Check if there are any nodes in reserve
            if (this.poHeadReserve == null)
            {
                //perform a refill
                this.privFillReservePool(this.growthRate);
            }

            // Now that we are guarenteed that the reserve is not-empty we can pull
            DLink pLink = DLink.PullFromFront(ref this.poHeadReserve);

            //Clean the node of data and references to other DLinks
            pLink.Clear();
            this.derivedWash(pLink);


            // initialize
            DLink.AddToFront(ref this.poHeadActive, pLink);

            // update counters
            this.mNumActiveNodes++;
            this.mNumReserveNodes--;

            return(pLink);
        }
Ejemplo n.º 6
0
 private void RefreshReserve(int numNodesToAdd)
 {
     for (int i = 0; i < numNodesToAdd; i++)
     {
         DLink.AddToFront(ref pReserve, CreateNode());
         mNumReserve++;
     }
 }
Ejemplo n.º 7
0
 private void RefreshReserve()
 {
     for (int i = 0; i < growthSize; i++)
     {
         DLink.AddToFront(ref pReserve, CreateNode());
         mNumReserve++;
     }
 }
        public static void Attach(Observer pObserver)
        {
            // protection
            Debug.Assert(pObserver != null);

            DelayedObjectManager pDelayMan = DelayedObjectManager.privGetInstance();

            DLink.AddToFront(ref pDelayMan.pHead, pObserver);
        }
Ejemplo n.º 9
0
        override public void Add(Component pComponent)
        {
            Debug.Assert(pComponent != null);
            DLink.AddToFront(ref this.pHead, pComponent);

            this.numChildren += 1;

            pComponent.pParent = this;
        }
Ejemplo n.º 10
0
        private static void privAddToFront(ref DLink pHead, DLink pNode)
        {
            // Will work for Active or Reserve List
            Debug.Assert(pNode != null);

            DLink.AddToFront(ref pHead, pNode);

            // worst case, pHead was null initially, now we added a node so... this is true
            Debug.Assert(pHead != null);
        }
Ejemplo n.º 11
0
        override public void Add(Component pComponent)
        {
            GameObject pGameObject = (GameObject)pComponent;

            Debug.Assert(pGameObject != null);
            DLink.AddToFront(ref this.poHeadChild, pGameObject);
            pGameObject.pParent = this;

            this.numChildren++;
        }
Ejemplo n.º 12
0
        protected void BaseRemove(DLink pDlink)
        {
            //depending on where the node is in the list we will have to move stuff around
            DLink.RemoveNode(ref this.poActive, pDlink);
            this.NumActive--;

            this.DerivedWash(pDlink);

            // then send that node or DLink back into the mNumReserve list
            DLink.AddToFront(ref this.poReserve, pDlink);
            this.NumReserve++;
        }
Ejemplo n.º 13
0
        protected void BaseRemove(DLink pNode)
        {
            Debug.Assert(pNode != null);
            DLink.RemoveNode(ref this.poActive, pNode);

            this.DerivedWash(pNode);

            DLink.AddToFront(ref this.poReserve, pNode);

            this.mNumActive--;
            this.mNumReserved++;
        }
Ejemplo n.º 14
0
        protected void BaseRemove(DLink pNode)
        {
            Debug.Assert(pNode != null);

            // Transfer the node in active list to reserve list.
            DLink.RemoveNode(ref this.pActive, pNode);
            this.DerivedWash(pNode);
            DLink.AddToFront(ref this.pReserve, pNode);

            // Update Stats
            this.mNumActive--;
            this.mNumReserve++;
        }
Ejemplo n.º 15
0
        protected void BaseRemove(DLink pDLink)
        {
            // check that pDLink is not null
            Debug.Assert(pDLink != null);
            DLink retiredNode = DLink.Remove(ref pActive, pDLink);

            mNumActive--;

            // check that retiredNode is not null
            Debug.Assert(retiredNode != null);
            DLink.AddToFront(ref pReserve, retiredNode);
            mNumReserve++;
        }
Ejemplo n.º 16
0
        /// <summary>
        ///   Moves a node from reserve to active and then returns reference for client to modify as desired
        /// </summary>
        /// <returns>DLink that was added to active list</returns>
        protected DLink BaseAdd()
        {
            DLink pNodeToActivate = BaseGetNodeFromReserve();

            // Add to front of Active List
            DLink.AddToFront(ref pActive, pNodeToActivate);

            // Stats
            this.reserveNodeNum--;
            this.activeNodeNum++;

            return(pNodeToActivate);
        }
Ejemplo n.º 17
0
        private void PrivReFill(int count)
        {
            Debug.Assert(count > 0);

            this.NumReserve += count;
            this.TotalNodes += count;

            for (int i = 0; i < count; i++)
            {
                DLink pDlink = this.DerivedCreateNode();
                DLink.AddToFront(ref this.poReserve, pDlink);
            }
        }
Ejemplo n.º 18
0
        protected void BasePurgeAllNodes()
        {
            DLink pNode;

            while (this.pActive != null)
            {
                pNode = DLink.RemoveFront(ref pActive);
                DLink.AddToFront(ref pReserve, pNode);
                mNumActive--;
                mNumReserve++;
            }

            Debug.Assert(pActive == null);
            Debug.Assert(mNumActive == 0);
        }
Ejemplo n.º 19
0
        protected void baseRemove(DLink pNode)
        {
            Debug.Assert(pNode != null);

            // remove the node from active list and update states
            DLink.RemoveNode(ref this.pActive, pNode);
            this.mNumActive--;

            // reset the node
            this.derivedReset(pNode);

            // add back to reserved list
            DLink.AddToFront(ref this.pReserved, pNode);
            this.mNumReserved++;
        }
Ejemplo n.º 20
0
        //----------------------------------------------------------------------
        // Private methods
        //----------------------------------------------------------------------
        private void PrivFillReservedPool(int count)
        {
            Debug.Assert(count > 0);

            this.mNumTotal += count;
            this.mNumReserve += count;

            for(int i = 0; i < count; ++i)
            {
                DLink pNode = this.DerivedCreateNode();
                Debug.Assert(pNode != null);

                DLink.AddToFront(ref this.pReserve, pNode);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Adds additional nodes to reserved list
        /// </summary>
        /// <param name="numNodes">Number of nodes to ad to reserved list</param>
        private void AddToReservedList(int numNodes)
        {
            Debug.Assert(numNodes > 0);

            DLink pNewNode;

            for (int i = 0; i < numNodes; i++)
            {
                pNewNode = this.DerivedCreateNode();
                Debug.Assert(pNewNode != null);
                DLink.AddToFront(ref pReserve, pNewNode);
            }

            this.totalNodeNum   += numNodes;
            this.reserveNodeNum += numNodes;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Moves a node from active to reserve and cleans list references for node
        /// </summary>
        /// <param name="pNode"></param>
        protected void BaseRemove(DLink pNode)
        {
            Debug.Assert(pNode != null);

            // Update list pointers to remove pNode from list
            DLink.RemoveFromList(ref pActive, pNode);

            // Remove list references in removed node
            pNode.ClearLinks();

            // Return pNode to pReserve list
            DLink.AddToFront(ref pReserve, pNode);

            // stats update
            this.activeNodeNum--;
            this.reserveNodeNum++;
        }
Ejemplo n.º 23
0
        protected void BaseRemove(DLink pNode)
        {
            Debug.Assert(pNode != null);

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

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

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

            // stats update
            this.mNumActive--;
            this.mNumReserved++;
        }
Ejemplo n.º 24
0
        //----------------------------------------------------------------------
        // Helper Methods
        //----------------------------------------------------------------------

        private void privFillReservePool(int val)
        {
            Debug.Assert(val > 0);

            DLink current = this.poHeadReserve;

            for (int i = 0; i < val; i++)
            {
                DLink pLink = this.derivedCreateNode();
                Debug.Assert(pLink != null);
                DLink.AddToFront(ref this.poHeadReserve, pLink);
            }

            // update counters
            this.mNumReserveNodes += val;
            this.mNumTotalNodes   += val;
        }
Ejemplo n.º 25
0
        //----------------------------------------------------------------------
        // Private methods - helpers
        //----------------------------------------------------------------------
        private void PrivFillReservedPool(int count)
        {
            // doesn't make sense if its not at least 1
            Debug.Assert(count > 0);

            this.mTotalNumNodes += count;
            this.mNumReserved   += count;

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

                DLink.AddToFront(ref this.poReserve, pNode);
            }
        }
Ejemplo n.º 26
0
        //----------------------------------------------------------------------
        // Private methods
        //----------------------------------------------------------------------
        private void fillNodesToReservedList(int numNode)
        {
            int   numAddedNode = 0;
            DLink currNode     = null;

            while (numAddedNode < numNode)
            {
                // create a specific node
                currNode = this.derivedCreateNode();
                Debug.Assert(currNode != null);

                DLink.AddToFront(ref pReserved, currNode);
                this.mNumReserved++;
                this.mTotalNumNodes++;
                numAddedNode++;
            }
        }
        public void Attach(Image.Name imageName)
        {
            // Get the image
            Image pImage = ImageMan.Find(imageName);

            Debug.Assert(pImage != null);

            // Create a new holder
            ImageHolder pImageHolder = new ImageHolder(pImage);

            Debug.Assert(pImageHolder != null);

            // Attach it to the Animation Sprite ( Push to front )
            DLink.AddToFront(ref this.poFirstImage, pImageHolder);

            // Set the first one to this image
            this.pCurrImage = pImageHolder;
        }
Ejemplo n.º 28
0
        protected Manager(int numNodes = 5, int growthSize = 2)
        {
            // Check params
            Debug.Assert(numNodes >= 0);
            Debug.Assert(growthSize > 0);

            mNumActive      = 0;
            pActive         = null;
            pReserve        = null;
            this.growthSize = growthSize;

            for (int i = 0; i < numNodes; i++)
            {
                DLink newNode = this.CreateNode();
                Debug.Assert(newNode != null);

                DLink.AddToFront(ref pReserve, newNode);
                mNumReserve++;
            }
        }
Ejemplo n.º 29
0
        public void baseRemove(DLink pLink)
        {
            // remove safely
            Debug.Assert(pLink != null);
            DLink target = this.baseFind(pLink);

            DLink.RemoveNode(ref this.poHeadActive, target);

            if (target != null)
            {
                // Clean the node
                target.Clear();
                this.derivedWash(target);

                // Push the node to the reserve list
                DLink.AddToFront(ref this.poHeadReserve, target);

                // update counters
                this.mNumActiveNodes--;
                this.mNumReserveNodes++;
            }
        }
Ejemplo n.º 30
0
        protected DLink BaseAdd()
        {
            // refill Reserve List if empty
            if (this.NumReserve == 0)
            {
                this.PrivReFill(this.growth);
            }

            //pull from front of reserve list
            DLink pDlink = DLink.PullFromFront(ref this.poReserve);

            this.NumReserve--;

            //clean the notecard
            this.DerivedWash(pDlink);

            //then add to front of active list
            DLink.AddToFront(ref this.poActive, pDlink);


            this.NumActive++;

            return(pDlink);
        }