public void SwitchState(SpaceInvaders pGame, GameStateManager.GameState nextState) { // Detach current state input observers pGame.DetachStateInputObservers(); // Queue any Time Events for later TimeEvent pTimeEvent = TimerManager.Pop(); while (pTimeEvent != null) { this.GetQueuedTimeEventManager().Enqueue(pTimeEvent.GetName(), pTimeEvent.GetCommand(), pTimeEvent.GetDeltaTime()); pTimeEvent = TimerManager.Pop(); } // Change game state pGame.SetGameState(nextState); // Load up TimerManager with next state's Time Events QueuedTimeEvent qte = pGame.GetStateQueuedTimeEventManager().Dequeue(); while (qte != null) { TimerManager.Add(qte.GetTimeEventName(), qte.GetCommand(), qte.GetTimeEventDelta()); // Get next queued event qte = pGame.GetStateQueuedTimeEventManager().Dequeue(); } // Attach next state input observers pGame.AttachStateInputObservers(); }
public static void Reset() { // Get the instance TimerManager pMan = TimerManager.pActiveMan; Debug.Assert(pMan != null); // walk the list TimeEvent pEvent = (TimeEvent)pMan.BaseGetActive(); TimeEvent pNextEvent = null; while (pEvent != null) { // 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; TimerManager.poNodeCopy.Set(pEvent.GetName(), pEvent.GetCommand(), pEvent.deltaTime); TimerManager.Remove(pEvent); TimerManager.Add(TimerManager.poNodeCopy.GetName(), TimerManager.poNodeCopy.GetCommand(), TimerManager.poNodeCopy.deltaTime); pEvent = pNextEvent; } }