24 ref FSMStateBase m_srcState;
26 ref FSMStateBase m_dstState;
28 ref FSMGuardBase m_guard;
30 void FSMTransition (FSMStateBase src, FSMEventBase e, FSMStateBase dst, FSMActionBase a = NULL, FSMGuardBase g = NULL)
56 protected ref FSMStateBase m_state;
57 protected ref FSMStateBase m_initialState;
58 protected ref FSMEventBase m_initialEvent;
70 FSMStateBase GetCurrentState ()
78 void SetInitialState (FSMStateBase initial_state)
80 m_initialState = initial_state;
87 void Start (FSMEventBase initial_event = NULL)
89 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[fsm] " + this.
ToString() +
"::Start(" + initial_event.ToString() +
"), init_state=" + m_initialState.ToString());
91 m_state = m_initialState;
92 m_state.OnEntry(initial_event);
98 bool IsRunning () {
return m_state != NULL; }
103 void Terminate (FSMEventBase terminal_event = NULL)
107 m_state.OnExit(terminal_event);
118 m_state.OnUpdate(dt);
126 m_transitions.Insert(t);
136 FSMStateBase curr_state = m_state;
138 int count = m_transitions.Count();
139 for (
int i = 0; i < count; ++i)
142 if (row.m_srcState.Type() == curr_state.Type() && row.m_event.Type() == e.Type())
145 bool hasGuard = t.m_guard != NULL;
146 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e)))
148 ProcessLocalTransition(t, e);
163 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[fsm] (local) state=" + t.m_srcState.ToString() +
"-------- event=" + e.ToString() +
"[G=" + t.m_guard.ToString() +
"]/A=" + t.m_action.ToString() +
" --------|> dst=" + t.m_dstState.ToString());
168 t.m_action.Action(e);
170 m_state = t.m_dstState;
172 if (t.m_dstState != NULL)
179 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[fsm] terminating fsm: state=" + t.m_srcState.ToString() +
" event=" + e.ToString());