Exemplo n.º 1
0
        public static void Update(float TotalTime)
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            //wasn't sure how we started the timer until i saw its use in the game.cs
            pTMan.mCurrentTime = TotalTime;

            TimeEvent pEvent = (TimeEvent)pTMan.BaseGetActive();

            //set the next to walk the list
            TimeEvent pNextEvent = null;

            while (pTMan.mCurrentTime >= pEvent.trigger)
            {
                //trigger event
                if (pTMan.mCurrentTime >= pEvent.trigger)
                {
                    pEvent.Process();

                    //intially i instantiated this outside of the loop "as-is" and it caused issues
                    pNextEvent = (TimeEvent)pEvent.pNext;

                    pTMan.BaseRemove(pEvent);
                }



                pEvent = pNextEvent;
            }
        }
Exemplo n.º 2
0
        public static void Update(float totalTime)
        {
            // Get the instance
            TimerMan pMan = TimerMan.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
            // ToDo Fix: List needs to be sorted
            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.pNext;

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

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

                // advance the pointer
                pEvent = pNextEvent;
            }
        }
Exemplo n.º 3
0
        public static void DumpTimeEvents()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            pTMan.BaseDumpNodes();
        }
Exemplo n.º 4
0
        public static float GetCurrTime()
        {
            // Get the instance
            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            // return time
            return(pTimerMan.mCurrTime);
        }
Exemplo n.º 5
0
        public static void Dump()
        {
            TimerMan pMan = TimerMan.PrivGetInstance();

            Debug.Assert(pMan != null);

            pMan.BaseDump();
        }
Exemplo n.º 6
0
        public static void StatDump()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            pTMan.BaseStatDump();
        }
Exemplo n.º 7
0
        public static void Remove(TimeEvent pTEnode)
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            Debug.Assert(pTEnode != null);
            pTMan.BaseRemove(pTEnode);
        }
Exemplo n.º 8
0
        public void PrivStatDump()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            Debug.WriteLine("");
            Debug.WriteLine("Timer Manager Stats---------------------");
            pTMan.BaseStatDump();
        }
Exemplo n.º 9
0
        private TimeEvent GetActiveList()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            TimeEvent pEvent = (TimeEvent)pTMan.BaseGetActive();

            return(pEvent);
        }
Exemplo n.º 10
0
        public static TimeEvent Find(TimeEvent.Name name)
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            pTMan.poNodeCompare.name = name;

            TimeEvent pTEnode = (TimeEvent)pTMan.BaseFind(pTMan.poNodeCompare);

            return(pTEnode);
        }
Exemplo n.º 11
0
        public static void UpdateMovementRange(int delta)
        {
            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTimerMan != null);
            TimerEvent pTimerEvent = (TimerEvent)pTimerMan.BaseGetActive();

            while (pTimerEvent != null)
            {
                pTimerEvent.GetCommand().UpdateRange(delta);
                pTimerEvent = (TimerEvent)pTimerEvent.pNext;
            }
        }
Exemplo n.º 12
0
        public static void UpdateEvent(float deltaTimeToTrigger)
        {
            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTimerMan != null);
            TimerEvent pTimerEvent = (TimerEvent)pTimerMan.BaseGetActive();

            while (pTimerEvent != null)
            {
                pTimerEvent.SetDeltaTime(deltaTimeToTrigger * pTimerEvent.GetDeltaTime());
                pTimerEvent = (TimerEvent)pTimerEvent.pNext;
            }
        }
Exemplo n.º 13
0
        private static TimerEvent PrivLocateNode(float triggerTime)
        {
            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTimerMan != null);
            TimerEvent pNode     = (TimerEvent)pTimerMan.BaseGetActive();
            TimerEvent pPrevNode = null;

            while (pNode != null && pNode.GetTriggerTime() < triggerTime)
            {
                pPrevNode = pNode;
                pNode     = (TimerEvent)pNode.pNext;
            }

            return(pPrevNode);
        }
Exemplo n.º 14
0
        public static TimeEvent Add(TimeEvent.Name timeName, Command pCommand, float deltaTimeToTrigger)
        {
            TimerMan pMan = TimerMan.PrivGetInstance();

            Debug.Assert(pMan != null);

            TimeEvent pNode = (TimeEvent)pMan.baseAddSorted(deltaTimeToTrigger + GetCurrTime());

            Debug.Assert(pNode != null);

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

            pNode.Set(timeName, pCommand, deltaTimeToTrigger);
            return(pNode);
        }
Exemplo n.º 15
0
        public static TimeEvent Find(TimeEvent.Name name)
        {
            TimerMan pMan = TimerMan.PrivGetInstance();

            Debug.Assert(pMan != null);

            // Compare functions only compares two Nodes

            // So:  Use the Compare Node - as a reference
            //      use in the Compare() function
            Debug.Assert(pMan.poNodeCompare != null);
            pMan.poNodeCompare.Wash();
            pMan.poNodeCompare.name = name;

            TimeEvent pData = (TimeEvent)pMan.BaseFind(pMan.poNodeCompare);

            return(pData);
        }
Exemplo n.º 16
0
        public static void ClearActiveList()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            TimeEvent pHead = pTMan.GetActiveList();
            TimeEvent pNode = pHead;

            while (pNode != null)
            {
                TimeEvent pNext = (TimeEvent)pNode.pNext;

                Remove(pNode);

                pNode = pNext;
            }
        }
Exemplo n.º 17
0
        public static TimerEvent Add(TimerEvent.Name timeName, Command pCommand, float deltaTimeToTrigger, bool repeat = true)
        {
            Debug.Assert(pCommand != null);
            Debug.Assert(deltaTimeToTrigger >= 0.0f);

            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTimerMan != null);

            float      triggerTime = deltaTimeToTrigger + pTimerMan.mCurrTime;
            TimerEvent pPreNode    = PrivLocateNode(triggerTime);

            TimerEvent pNode = (TimerEvent)pTimerMan.BaseAddToPosition(pPreNode);

            Debug.Assert(pNode != null);
            pNode.Set(timeName, pCommand, deltaTimeToTrigger, pTimerMan.mCurrTime, repeat);

            return(pNode);
        }
Exemplo n.º 18
0
        public static void Destroy()
        {
            // Get the instance
            TimerMan pMan = TimerMan.PrivGetInstance();

            Debug.Assert(pMan != null);
#if (TRACK_DESTRUCTOR_MAN)
            Debug.WriteLine("--->TimerMan.Destroy()");
#endif
            pMan.BaseDestroy();

#if (TRACK_DESTRUCTOR_MAN)
            Debug.WriteLine("     {0} ({1})", pMan.poNodeCompare, pMan.poNodeCompare.GetHashCode());
            Debug.WriteLine("     {0} ({1})", TimerMan.pInstance, TimerMan.pInstance.GetHashCode());
#endif

            pMan.poNodeCompare = null;
            TimerMan.pInstance = null;
        }
Exemplo n.º 19
0
        public static void Update(float totalTime)
        {
            TimerMan pTimerMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTimerMan != null);

            pTimerMan.mCurrTime = totalTime;

            TimerEvent pEvent     = (TimerEvent)pTimerMan.BaseGetActive();
            TimerEvent pNextEvent = null;

            while (pEvent != null && (pTimerMan.mCurrTime >= pEvent.GetTriggerTime()))
            {
                pNextEvent = (TimerEvent)pEvent.pNext;
                if (pTimerMan.mCurrTime >= pEvent.GetTriggerTime())
                {
                    pEvent.Process();
                    pTimerMan.BaseRemove(pEvent);
                }

                pEvent = pNextEvent;
            }
        }
Exemplo n.º 20
0
        //needs to insert as a priority queue
        public static TimeEvent Add(TimeEvent.Name name, Command pCommand, float deltaTime)
        {
            Debug.Assert(pCommand != null);

            //real-time systems  must be causal
            //cant have an event occur before current time
            Debug.Assert(deltaTime >= 0.0f);

            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            TimeEvent pTEnode = (TimeEvent)pTMan.GrabNode();

            Debug.Assert(pTEnode != null);

            //the TimeEvent class does the updated trigger time
            pTEnode.Set(name, pCommand, deltaTime);


            Insert(pTEnode);
            return(pTEnode);
        }
Exemplo n.º 21
0
        public static float GetCurrentTime()
        {
            TimerMan pTMan = TimerMan.PrivGetInstance();

            return(pTMan.mCurrentTime);
        }
Exemplo n.º 22
0
        //i definitely think the insert() needs to be cleaned up
        // i had alot of reference issues
        private static void Insert(TimeEvent pTEnode)
        {
            Debug.Assert(pTEnode != null);

            TimerMan pTMan = TimerMan.PrivGetInstance();

            Debug.Assert(pTMan != null);

            TimeEvent pEvent     = (TimeEvent)pTMan.BaseGetActive();
            TimeEvent pNextEvent = null;
            TimeEvent pPrevEvent = null;


            //very first node
            if (pEvent == null)
            {
                pTEnode.pPrev = null;
                pTEnode.pNext = null;
                DLink pTemp = (DLink)pTEnode;

                pEvent = (TimeEvent)pTMan.SetActive(ref pTemp);
            }

            //insert before the first node
            if (pTEnode.trigger < pEvent.trigger)
            {
                pTEnode.pNext = pEvent;
                pEvent.pPrev  = pTEnode;
                pTEnode.pPrev = null;


                DLink pTemp = (DLink)pTEnode;
                pEvent = (TimeEvent)pTMan.SetActive(ref pTemp);
            }

            while (pTEnode.trigger >= pEvent.trigger && pTEnode.GetHashCode() != pEvent.GetHashCode())
            {
                pNextEvent = (TimeEvent)pEvent.pNext;

                //then something is there
                if (pNextEvent != null)
                {
                    //insert into middle of list
                    if (pTEnode.trigger <= pNextEvent.trigger)
                    {
                        pPrevEvent = (TimeEvent)pEvent;

                        pTEnode.pNext = pNextEvent;
                        pTEnode.pPrev = pPrevEvent;

                        pPrevEvent.pNext = pTEnode;

                        pNextEvent.pPrev = pTEnode;

                        break;
                    }
                }

                //insert at the end of the list
                else
                {
                    pTEnode.pPrev = pEvent;
                    pEvent.pNext  = pTEnode;
                    pTEnode.pNext = null;

                    break;
                }
                pEvent = pNextEvent;
            }
        }