DayZ 1.24
Loading...
Searching...
No Matches
FSMBase.c
Go to the documentation of this file.
1void fsmbDebugPrint(string s)
2{
3#ifdef FSM_DEBUG
4 PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
5#else
6 //Print("" + s); // comment/uncomment to hide/see debug logs
7#endif
8}
9void fsmbDebugSpam(string s)
10{
11#ifdef FSM_DEBUG_SPAM
12 PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
13#else
14 //Print("" + s); // comment/uncomment to hide/see debug logs
15#endif
16}
17
18
23{
25 ref FSMEventBase m_event; // @NOTE: NULL event means "completion transition" in UML speak
26 ref FSMStateBase m_dstState; // @NOTE: NULL dst state == UML terminate pseudonode
29
31 {
32 m_srcState = src;
33 m_event = e;
34 m_dstState = dst;
35 m_action = a;
36 m_guard = g;
37 }
38};
39
47
55{
60
65
71 {
72 return m_state;
73 }
74
79 {
80 m_initialState = initial_state;
81 }
82
88 {
89 if (LogManager.IsInventoryHFSMLogEnable()) fsmbDebugPrint("[fsm] " + this.ToString() + "::Start(" + initial_event.ToString() + "), init_state=" + m_initialState.ToString());
90
91 m_state = m_initialState;
92 m_state.OnEntry(initial_event);
93 }
94
98 bool IsRunning() { return m_state != NULL; }
99
104 {
105 if (IsRunning())
106 {
107 m_state.OnExit(terminal_event);
108 m_state = NULL;
109 }
110 }
111
115 void Update(float dt)
116 {
117 if (IsRunning())
118 m_state.OnUpdate(dt);
119 }
120
128
135 {
136 FSMStateBase curr_state = m_state;
137
138 int count = m_transitions.Count();
139 for (int i = 0; i < count; ++i)
140 {
142 if (row.m_srcState.Type() == curr_state.Type() && row.m_event.Type() == e.Type())
143 {
145 bool hasGuard = t.m_guard != NULL;
146 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e))) // 1) exec guard (if any)
147 {
148 ProcessLocalTransition(t, e); // 2) process transition allowed by guard
149 }
150 }
151 }
152 return ProcessEventResult.FSM_NO_TRANSITION;
153 }
154
162 {
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());
164
165 m_state.OnExit(e); // 1) call onExit on old state
166
167 if (t.m_action)
168 t.m_action.Action(e); // 2) execute transition action (if any)
169
170 m_state = t.m_dstState; // 3) change state to new
171
172 if (t.m_dstState != NULL)
173 {
174 m_state.OnEntry(e); // 4a) call onEntry on new state
175 return ProcessEventResult.FSM_OK;
176 }
177 else
178 {
179 if (LogManager.IsInventoryHFSMLogEnable()) fsmbDebugPrint("[fsm] terminating fsm: state=" + t.m_srcState.ToString() + " event=" + e.ToString());
180 return ProcessEventResult.FSM_TERMINATED; // 4b) or terminate
181 }
182 }
183};
184
ref HandEventBase m_event
proto string ToString()
ProcessEventResult
Definition FSMBase.c:41
@ FSM_ABORTED
Definition FSMBase.c:44
@ FSM_OK
Definition FSMBase.c:42
@ FSM_TERMINATED
Definition FSMBase.c:43
@ FSM_NO_TRANSITION
Definition FSMBase.c:45
void fsmbDebugPrint(string s)
Definition FSMBase.c:1
void fsmbDebugSpam(string s)
Definition FSMBase.c:9
class WeaponEndAction extends WeaponStartAction m_action
Super root of all classes in Enforce script.
Definition EnScript.c:11
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the state machine to process the event e
Definition FSMBase.c:134
void Terminate(FSMEventBase terminal_event=NULL)
terminates the state machine
Definition FSMBase.c:103
void Start(FSMEventBase initial_event=NULL)
starts the state machine by entering the initial_state (using intial_event as argument to initial sta...
Definition FSMBase.c:87
void SetInitialState(FSMStateBase initial_state)
sets the initial_state for starting the machine
Definition FSMBase.c:78
ProcessEventResult ProcessLocalTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
instructs the state machine to process the event locally - no hierarchy is crossed
Definition FSMBase.c:161
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_transitions
configurable initial event to start the machine (null by default)
Definition FSMBase.c:59
void Update(float dt)
if machine running, call OnUpdate() on current state
Definition FSMBase.c:115
ref FSMEventBase m_initialEvent
configurable initial state of the machine
Definition FSMBase.c:58
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
Definition FSMBase.c:124
base class for finite state machine
void FSMTransition(FSMStateBase src, FSMEventBase e, FSMStateBase dst, FSMActionBase a=NULL, FSMGuardBase g=NULL)
Definition FSMBase.c:30
represents transition src -— event[guard]/action -—|> dst
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:749
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
bool IsRunning()
Definition tools.c:252