73 FSMStateBase curr = state;
77 curr = curr.GetParentState();
79 return path.Count() > 0;
97 if (t.m_event == NULL)
99 Print(
"Warning (performance): FSM " +
this +
" has completion transition for src=" + t.m_srcState +
" ---NULL----|> dst=" + t.m_dstState);
108 void Start (FSMEventBase initial_event = NULL,
bool useExistingState =
false)
115 if (!useExistingState)
118 m_State.OnEntry(initial_event);
139 m_State.OnExit(terminal_event);
143 void Abort (FSMEventBase abort_event = NULL)
169 fsmDebugPrint(
"[hfsm] (local abort) state=" + t.m_srcState.ToString() +
"-------- ABORT event=" + e.ToString() +
"[G=" + t.m_guard.ToString() +
"]/A=" + t.m_action.ToString() +
" --------|> dst=" + t.m_dstState.ToString());
175 t.m_action.Action(e);
177 auto tmp = t.m_srcState.GetParentState();
178 if (tmp == t.m_dstState.GetParentState())
182 if (t.m_dstState != NULL)
191 fsmDebugPrint(
"[hfsm] abort & terminating fsm: state=" + t.m_srcState.ToString() +
" event=" + e.ToString());
219 fsmDebugPrint(
"[hfsm] root::FindAbortDestinationState(" + e.Type().ToString() +
")");
226 FSMStateBase abort_dst = a.FindAbortDestinationState(e);
240 fsmDebugPrint(
"[hfsm] abort event has no transition: src=" +
m_State.ToString() +
" e=" + e.Type().ToString());
265 fsmDebugPrint(
"[hfsm] root::ProcessAbortEvent(" + e.Type().ToString() +
")");
273 FSMStateBase abort_dst = a.ProcessAbortEvent(e, subfsm_res);
298 fsmDebugPrint(
"[hfsm] aborted sub machine=" +
m_State.ToString() +
" & abort destination reached.");
334 fsmDebugPrint(
"[hfsm] abort event has no transition: src=" +
m_State.ToString() +
" e=" + e.Type().ToString());
354 fsmDebugPrint(
"[hfsm] aborted sub machine=" +
m_State.ToString() +
" will fall-through to dst=" + t.m_dstState);
390 fsmDebugPrint(
"[hfsm] root::ProcessEvent(" + e.Type().ToString() +
" =" + e.DumpToString());
426 fsmDebugPrint(
"[hfsm] event has no transition: src=" +
m_State.ToString() +
" e=" + e.Type().ToString());
433 if (row.m_dstState != NULL)
436 if (row.m_srcState.GetParentState() == row.m_dstState.GetParentState())
439 Error(
"cross-hierarchy transition or misconfigured transition detected!");
448 Error(
"cross-hierarchy transition or misconfigured transition detected!");
456 FSMStateBase curr_state =
m_State;
459 for (
int i = 0; i < count; ++i)
462 if ((t.m_srcState == curr_state) && (t.m_event != NULL) && (t.m_event.Type() == e.Type()))
465 bool hasGuard = t.m_guard != NULL;
466 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e)))
478 FSMStateBase curr_state = s;
481 for (
int i = 0; i < count; ++i)
484 if ((t.m_srcState == curr_state) && (t.m_event != NULL) && (t.m_event.Type() == e.Type()))
494 FSMStateBase curr_state = s;
497 for (
int i = 0; i < count; ++i)
500 if ((t.m_srcState == curr_state) && (t.m_event != NULL) && (t.m_event.Type() == e.Type()))
502 bool hasGuard = t.m_guard != NULL;
503 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e)))
516 FSMStateBase curr_state =
m_State;
519 for (
int i = 0; i < count; ++i)
524 if ((t.m_srcState.Type() == curr_state.Type()) && (t.m_event == NULL))
526 bool hasGuard = t.m_guard != NULL;
527 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(NULL)))
548 fsmDebugPrint(
"[hfsm] (local) state=" + t.m_srcState.ToString() +
"-------- event=" + e.ToString() +
"[G=" + t.m_guard.ToString() +
"]/A=" + t.m_action.ToString() +
" --------|> dst=" + t.m_dstState.ToString());
554 t.m_action.Action(e);
558 if (t.m_dstState != NULL)
563 GetOwnerState().OnSubMachineChanged(t.m_srcState, t.m_dstState);
566 m_State.OnStateChanged(t.m_srcState, t.m_dstState);
574 fsmDebugPrint(
"[hfsm] terminating fsm: state=" + t.m_srcState.ToString() +
" event=" + e.ToString());
598 while (completionIdx != -1)
602 if (row.m_dstState != NULL)
605 if (row.m_srcState.GetParentState() == row.m_dstState.GetParentState())
608 Error(
"cross-hierarchy transition or misconfigured transition detected!");
617 Error(
"cross-hierarchy transition or misconfigured transition detected!");
Super root of all classes in Enforce script.
represents transition src -— event[guard]/action -—|> dst
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the hierarchical state machine to process the event e
ProcessEventResult ProcessAbortTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
ref FSMStateBase m_InitialState
state that owns this fsm (or null if root)
void HFSMBase(FSMStateBase ownerState=NULL)
FSMStateBase GetOwnerState()
ProcessEventResult ProcessCompletionTransitions()
void Update(float dt)
if machine running, call OnUpdate() on current state
bool IsRunning()
returns true if machine is in running state
FSMStateBase m_OwnerState
current fsm state
FSMStateBase FindGuardedTransitionState(FSMStateBase s, FSMEventBase e)
FSMStateBase FindTransitionState(FSMStateBase s, FSMEventBase e)
void Start(FSMEventBase initial_event=NULL, bool useExistingState=false)
starts the state machine by entering the initial_state (using intial_event as argument to initial sta...
void Abort(FSMEventBase abort_event=NULL)
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_Transitions
configurable initial state of the machine
bool GetHierarchyPath(FSMStateBase state, out array< FSMStateBase > path)
returns hierarchic state (path to root) of a state
void SetCurrentState(FSMStateBase state)
ProcessEventResult LocalTransition(int i, FSMEventBase e)
FSMStateBase ProcessAbortEvent(FSMEventBase e, out ProcessEventResult result)
instructs the hierarchical state machine to process the event e
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
FSMStateBase GetCurrentState()
int FindFirstCompletionTransition()
ProcessEventResult ProcessLocalTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
instructs the state machine to process the event locally - no hierarchy is crossed
FSMStateBase FindAbortDestinationState(FSMEventBase e)
i
bool m_HasCompletions
fsm transition table
int FindFirstUnguardedTransition(FSMEventBase e)
void SetInitialState(FSMStateBase initial_state)
void Terminate(FSMEventBase terminal_event=NULL)
terminates the state machine
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void Error(string err)
Messagebox with error message.
proto void Print(void var)
Prints content of variable to console/log.
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
void fsmDebugSpam(string s)
void fsmDebugPrint(string s)