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(); } } }
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; } }
public static void Update(float totalTime) { TimerManager pTimerMan = TimerManager.privGetInstance(); Debug.Assert(pTimerMan != null); pTimerMan.mCurrentTime = totalTime; TimeEvent pTimeEvent = (TimeEvent)pTimerMan.baseGetActive(); TimeEvent pNextEvent = null; // for iterating while (pTimeEvent != null) { //cache pNextEvent = (TimeEvent)pTimeEvent.pNext; if (pTimerMan.mCurrentTime >= pTimeEvent.GetTriggerTime()) { // do it pTimeEvent.Process(); //remove it pTimerMan.baseRemove(pTimeEvent); } // go to next pTimeEvent = pNextEvent; } }
public static void PrintMe() { TimeEvent pNode = (TimeEvent)pInstance.BaseGetActive(); while (pNode != null) { Debug.WriteLine("\t\t{0}: {1}", pNode.name, pNode.GetTriggerTime()); pNode = (TimeEvent)pNode.pNext; } Debug.WriteLine("------------------------------------------------"); }