Example #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;
            }
        }
Example #2
0
        public static float GetCurrTime()
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            return(pMan.mCurrTime);
        }
Example #3
0
        public static void Remove(TimeEvent pNode)
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            Debug.Assert(pNode != null);
            pMan.baseRemove(pNode);
        }
Example #4
0
        public static void Destory()
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            pMan.baseDestory();

            pMan.poNodeForCompare = null;
            TimerMan.pInstance    = null;
        }
Example #5
0
        public static TimeEvent Find(TimeEvent.Name name)
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            Debug.Assert(pMan.poNodeForCompare != null);
            pMan.poNodeForCompare.setName(name);

            TimeEvent pData = (TimeEvent)pMan.baseFind(pMan.poNodeForCompare);

            return(pData);
        }
Example #6
0
        public static void Reset()
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            TimeEvent pTimeEvent = (TimeEvent)pMan.pActive;

            while (pTimeEvent != null)
            {
                pTimeEvent.deepClear();
                pTimeEvent = (TimeEvent)pTimeEvent.pNext;
            }

            pMan.baseSetActiveHead(null);
        }
Example #7
0
        public static TimeEvent Add(TimeEvent.Name name, Command pCommand, float deltaTimeToTrigger)
        {
            // ensure call Create() first
            TimerMan pMan = TimerMan.GetInstance();

            Debug.Assert(pMan != null);

            TimeEvent pTimeEvent = (TimeEvent)pMan.getNewNode();

            Debug.Assert(pTimeEvent != null);

            Debug.Assert(pCommand != null);
            Debug.Assert(deltaTimeToTrigger >= 0.0f);

            pTimeEvent.set(name, pCommand, deltaTimeToTrigger);
            pMan.sortTimeEventList(pTimeEvent);
            return(pTimeEvent);
        }
Example #8
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;
            }
        }