Beispiel #1
0
        public static void Update(float totalTime)
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            pMan.mCurrTime = totalTime;

            // get the active list
            TimeEvent pEvent     = (TimeEvent)pMan.baseGetActiveList();
            TimeEvent pNextEvent = null;

            // walk the list until there is no more list or currtime is greater than timeEvent
            while (pEvent != null && (pMan.mCurrTime >= pEvent.getTriggerTime()))
            {
                // get next event
                pNextEvent = (TimeEvent)pEvent.pNext;

                if (pMan.mCurrTime > pEvent.getTriggerTime())
                {
                    // call it
                    pEvent.process();
                    // remove from active list
                    pMan.baseRemove(pEvent);
                }

                // go to next event
                pEvent = pNextEvent;
            }
        }
Beispiel #2
0
        private void sortTimeEventList(TimeEvent pTimeEvent)
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            TimeEvent pActiveList = (TimeEvent)pMan.baseGetActiveList();

            TimeEvent pCurrTimeEvent = pActiveList;

            if (pCurrTimeEvent == null)
            {
                pMan.baseSetActiveHead(pTimeEvent);
                return;
            }

            if (pCurrTimeEvent.pNext == null && pCurrTimeEvent.pPrev == null)
            {
                if (pCurrTimeEvent.getTriggerTime() > pTimeEvent.getTriggerTime())
                {
                    pCurrTimeEvent.pPrev = pTimeEvent;
                    pTimeEvent.pNext     = pCurrTimeEvent;
                    pTimeEvent.pPrev     = null;
                    pMan.baseSetActiveHead(pTimeEvent);
                    return;
                }
                else
                {
                    pCurrTimeEvent.pNext = pTimeEvent;
                    pTimeEvent.pPrev     = pCurrTimeEvent;
                    pTimeEvent.pNext     = null;
                    return;
                }
            }

            while (pCurrTimeEvent != null)
            {
                if (pCurrTimeEvent.getTriggerTime() >= pTimeEvent.getTriggerTime())
                {
                    if (pCurrTimeEvent.pPrev == null)
                    {
                        pCurrTimeEvent.pPrev = pTimeEvent;
                        pTimeEvent.pNext     = pCurrTimeEvent;
                        pTimeEvent.pPrev     = null;
                        pMan.baseSetActiveHead(pTimeEvent);
                        return;
                    }
                    else
                    {
                        pTimeEvent.pPrev           = pCurrTimeEvent.pPrev;
                        pTimeEvent.pNext           = pCurrTimeEvent;
                        pCurrTimeEvent.pPrev.pNext = pTimeEvent;
                        pCurrTimeEvent.pPrev       = pTimeEvent;
                        return;
                    }
                }

                if (pCurrTimeEvent.pNext == null)
                {
                    pCurrTimeEvent.pNext = pTimeEvent;
                    pTimeEvent.pPrev     = pCurrTimeEvent;
                    pTimeEvent.pNext     = null;
                    return;
                }

                pCurrTimeEvent = (TimeEvent)pCurrTimeEvent.pNext;
            }
        }