34 m_InitialStates = initial_states;
36 for (
int s = 0; s < initial_states.Count(); ++s)
37 m_States.Insert(initial_states[s]);
46 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[ofsm] " + this.
ToString() +
"::Start(" + initial_events.ToString() +
"), init_state=" + m_InitialStates.ToString());
48 for (
int s = 0; s < m_States.Count(); ++s)
50 m_States[s] = m_InitialStates[s];
53 m_States[s].OnEntry(initial_events[s]);
55 m_States[s].OnEntry(null);
64 int sc = m_States.Count();
67 for (
int s = 0; s < sc; ++s)
68 if (m_States[s] != null)
81 for (
int s = 0; s < m_States.Count(); ++s)
84 m_States[s].OnExit(terminal_events[s]);
86 m_States[s].OnExit(null);
100 for (
int s = 0; s < m_States.Count(); ++s)
102 m_States[s].OnUpdate(dt);
112 m_Transitions.Insert(t);
122 int count = m_Transitions.Count();
123 for (
int i = 0; i < count; ++i)
126 if (row.m_event.Type() == e.Type())
128 for (
int s = 0; s < m_States.Count(); ++s)
130 if (row.m_srcState.Type() == m_States[s].Type() && row.m_event.Type() == e.Type())
133 bool hasGuard = t.m_guard != NULL;
134 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e)))
136 ProcessLocalTransition(s, t, e);
153 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[ofsm] (local) state=" + t.m_srcState.ToString() +
"-------- event=" + e.ToString() +
"[G=" + t.m_guard.ToString() +
"]/A=" + t.m_action.ToString() +
" --------|> dst=" + t.m_dstState.ToString());
155 m_States[s].OnExit(e);
158 t.m_action.Action(e);
160 m_States[s] = t.m_dstState;
162 if (t.m_dstState != NULL)
164 m_States[s].OnEntry(e);
169 if (
LogManager.IsInventoryHFSMLogEnable())
fsmbDebugPrint(
"[ofsm] terminating fsm: state=" + t.m_srcState.ToString() +
" event=" + e.ToString());
Super root of all classes in Enforce script.
represents transition src -— event[guard]/action -—|> dst
void Start(array< ref FSMEventBase > initial_events=null)
starts the state machine by entering the initial_state (using intial_event as argument to initial sta...
ProcessEventResult ProcessLocalTransition(int s, FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
instructs the state machine to process the event locally - no hierarchy is crossed
bool IsRunning()
returns true if machine is in running state
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
ref array< ref FSMStateBase > m_States
void Update(float dt)
if machine running, call OnUpdate() on current state
void OFSMBase()
fsm transition table
ref array< ref FSMStateBase > m_InitialStates
current fsm state
void SetInitialStates(array< ref FSMStateBase > initial_states)
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_Transitions
configurable initial state of the machine
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the state machine to process the event e
void Terminate(array< ref FSMEventBase > terminal_events=null)
terminates the state machine
array< ref FSMStateBase > GetCurrentState()
base class for Orthogonal Finite State Machine
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void fsmbDebugPrint(string s)