DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
FSMBase.c
См. документацию.
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
22class FSMTransition<Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase>
23{
24 ref FSMStateBase m_srcState;
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
27 ref FSMActionBase m_action;
28 ref FSMGuardBase m_guard;
29
30 void FSMTransition (FSMStateBase src, FSMEventBase e, FSMStateBase dst, FSMActionBase a = NULL, FSMGuardBase g = NULL)
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
54class FSMBase<Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase>
55{
56 protected ref FSMStateBase m_state;
57 protected ref FSMStateBase m_initialState;
58 protected ref FSMEventBase m_initialEvent;
60
65
70 FSMStateBase GetCurrentState ()
71 {
72 return m_state;
73 }
74
78 void SetInitialState (FSMStateBase initial_state)
79 {
80 m_initialState = initial_state;
81 }
82
87 void Start (FSMEventBase initial_event = NULL)
88 {
89 if (LogManager.IsInventoryHFSMLogEnable()) fsmbDebugPrint("[fsm] " + this.ToString() + "::Start(" + initial_event.ToString() + "), init_state=" + m_initialState.ToString());
90
92 m_state.OnEntry(initial_event);
93 }
94
98 bool IsRunning () { return m_state != NULL; }
99
103 void Terminate (FSMEventBase terminal_event = NULL)
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
proto string ToString()
ProcessEventResult
Определения FSMBase.c:41
@ FSM_ABORTED
Определения FSMBase.c:44
@ FSM_OK
Определения FSMBase.c:42
@ FSM_TERMINATED
Определения FSMBase.c:43
@ FSM_NO_TRANSITION
Определения FSMBase.c:45
void fsmbDebugPrint(string s)
Определения FSMBase.c:1
void fsmbDebugSpam(string s)
Определения FSMBase.c:9
Super root of all classes in Enforce script.
Определения EnScript.c:11
void Terminate(FSMEventBase terminal_event=NULL)
terminates the state machine
Определения FSMBase.c:103
FSMStateBase GetCurrentState()
returns currently active state
Определения FSMBase.c:70
ProcessEventResult ProcessLocalTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
instructs the state machine to process the event locally - no hierarchy is crossed
Определения FSMBase.c:161
void SetInitialState(FSMStateBase initial_state)
sets the initial_state for starting the machine
Определения FSMBase.c:78
void Start(FSMEventBase initial_event=NULL)
starts the state machine by entering the initial_state (using intial_event as argument to initial sta...
Определения FSMBase.c:87
void Update(float dt)
if machine running, call OnUpdate() on current state
Определения FSMBase.c:115
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
Определения FSMBase.c:124
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the state machine to process the event e
Определения FSMBase.c:134
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_transitions
configurable initial event to start the machine (null by default)
Определения FSMBase.c:59
bool IsRunning()
returns true if machine is in running state
Определения FSMBase.c:98
ref FSMEventBase m_initialEvent
configurable initial state of the machine
Определения FSMBase.c:58
void FSMTransition(FSMStateBase src, FSMEventBase e, FSMStateBase dst, FSMActionBase a=NULL, FSMGuardBase g=NULL)
Определения FSMBase.c:30
represents transition src -— event[guard]/action -—|> dst
static bool IsInventoryHFSMLogEnable()
Определения Debug.c:668
Определения Debug.c:594
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
bool IsRunning()
Определения tools.c:264