Exemplo n.º 1
0
        public void Tick()
        {
            Queue <StateChartEvent> tmp = inactiveEventQueue;

            inactiveEventQueue = activeEventQueue;
            activeEventQueue   = tmp;

            while (inactiveEventQueue.Count > 0)
            {
                StateChartEvent      evt        = inactiveEventQueue.Dequeue();
                StateChartTransition transition = rootState.HandleEvent(evt.GetType(), evt);

                if (transition != null)
                {
                    GoToState(transition.targetState, transition.from);
                }
            }

            StateChartState ptr = rootState;

            while (ptr != null)
            {
                if (ptr.updateFn != null)
                {
                    ptr.updateFn();
                }

                ptr = ptr.activeSubstate;
            }
        }
Exemplo n.º 2
0
            public StateChartTransition HandleEvent(Type evtType, StateChartEvent evt)
            {
                for (int i = 0; i < events.Count; i++)
                {
                    if (events[i].type == evtType)
                    {
                        events[i].callback(evt);
                    }
                }

                for (int i = 0; i < transitions.Count; i++)
                {
                    if (transitions[i].type == evtType && transitions[i].guardFn(evt))
                    {
                        return(new StateChartTransition(this, transitions[i].targetState));
                    }
                }

                return(activeSubstate != null?activeSubstate.HandleEvent(evtType, evt) : null);
            }
 private static bool DefaultGuardFn(StateChartEvent evt)
 {
     return(true);
 }