Esempio n. 1
0
        private static void AddToActiveListInSortedOrder(TimerManager pInstance, TimeEvent pNewNode)
        {
            TimeEvent pListPointer = (TimeEvent)pInstance.BaseGetActive();

            if ((pListPointer == null) || (pNewNode.GetTriggerTime() <= pListPointer.GetTriggerTime()))
            {
                // If list is empty, or if pNode.triggerTime <= head.triggerTime
                // make the node as head
                pInstance.BaseSetActiveHead(pNewNode);
            }
            else
            {
                while (pListPointer != null)
                {
                    // If next TimeEvent has a greater triggerTime than new node, insert into list
                    if (pListPointer.GetTriggerTime() >= pNewNode.GetTriggerTime())
                    {
                        AddToListBeforeNode(pNewNode, pListPointer);

                        // Break loop
                        break;
                    }
                    else if (pListPointer.GetNext() == null)
                    {
                        AddToListAfterNode(pNewNode, pListPointer);
                        break;
                    }

                    pListPointer = (TimeEvent)pListPointer.GetNext();
                }
            }
        }
Esempio n. 2
0
        private static void AddToListAfterNode(TimeEvent pNewNode, TimeEvent pPrevNode)
        {
            // Set new node pointers
            pNewNode.SetNext(pPrevNode.GetNext());
            pNewNode.SetPrev(pPrevNode);

            // Set next node pointer
            if (pPrevNode.GetNext() != null)
            {
                pPrevNode.GetNext().SetPrev(pNewNode);
            }

            // Set previous node pointer
            pPrevNode.SetNext(pNewNode);
        }
Esempio n. 3
0
        public static void Update(float totalTime)
        {
            // Get the instance
            TimerManager pInstance = TimerManager.PrivGetInstance();

            Debug.Assert(pInstance != null);

            // "Latch" the current time
            pInstance.currTime = totalTime;

            TimeEvent pEvent     = (TimeEvent)pInstance.BaseGetActive();
            TimeEvent pNextEvent = null;

            // Walk the list to end OR currTime is greater than timeEvent
            while (pEvent != null && (pInstance.currTime >= pEvent.GetTriggerTime()))
            {
                pNextEvent = (TimeEvent)pEvent.GetNext();

                if (pInstance.currTime >= pEvent.GetTriggerTime())
                {
                    // Process event
                    pEvent.Process();

                    // Remove from list
                    pInstance.BaseRemove(pEvent);
                }

                // Advance the pointer
                pEvent = pNextEvent;
            }
        }
Esempio n. 4
0
        public static void Update(float totalTime)
        {
            // Get the instance
            TimerManager pMan = TimerManager.PrivGetInstance();

            Debug.Assert(pMan != null);

            // squirrel away
            pMan.mCurrTime = totalTime;

            // walk the list
            TimeEvent pEvent     = (TimeEvent)pMan.BaseGetActive();
            TimeEvent pNextEvent = null;

            // Walk the list until there is no more list OR currTime is greater than timeEvent
            // List needs to be sorted by trigger time
            while (pEvent != null && (pMan.mCurrTime >= pEvent.triggerTime))
            {
                // Difficult to walk a list and remove itself from the list
                // so squirrel away the next event now, use it at bottom of while
                pNextEvent = (TimeEvent)pEvent.GetNext();

                if (pMan.mCurrTime >= pEvent.triggerTime)
                {
                    // call it
                    pEvent.Process();

                    // remove from list
                    pMan.BaseRemove(pEvent);
                }

                // advance the pointer
                pEvent = pNextEvent;
            }
        }
Esempio n. 5
0
        public static void PullFromMemento(TimerMemento pMemento, float currTime)
        {
            float elapsedTime = currTime - pMemento.mCurrTime;

            Debug.Assert(elapsedTime >= 0);

            TimerManager pMan = TimerManager.PrivGetInstance();

            Debug.Assert(pMan != null);
            pMan.BasePullFromMemento(pMemento);

            // update all of the times on the event chain
            TimeEvent pNode = (TimeEvent)pMan.BaseGetActive();

            while (pNode != null)
            {
                pNode.triggerTime += elapsedTime;
                pNode              = (TimeEvent)pNode.GetNext();
            }
        }