DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
OFSMBase.c
См. документацию.
7class OFSMBase<Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase>
8{
12
19
28
33 {
34 m_InitialStates = initial_states;
35
36 for (int s = 0; s < initial_states.Count(); ++s)
37 m_States.Insert(initial_states[s]);
38 }
39
44 void Start (array<ref FSMEventBase> initial_events = null)
45 {
46 if (LogManager.IsInventoryHFSMLogEnable()) fsmbDebugPrint("[ofsm] " + this.ToString() + "::Start(" + initial_events.ToString() + "), init_state=" + m_InitialStates.ToString());
47
48 for (int s = 0; s < m_States.Count(); ++s)
49 {
51
52 if (initial_events)
53 m_States[s].OnEntry(initial_events[s]);
54 else
55 m_States[s].OnEntry(null);
56 }
57 }
58
62 bool IsRunning ()
63 {
64 int sc = m_States.Count();
65 if (sc)
66 {
67 for (int s = 0; s < sc; ++s)
68 if (m_States[s] != null)
69 return true;
70 }
71 return false;
72 }
73
77 void Terminate (array<ref FSMEventBase> terminal_events = null)
78 {
79 if (IsRunning())
80 {
81 for (int s = 0; s < m_States.Count(); ++s)
82 {
83 if (terminal_events)
84 m_States[s].OnExit(terminal_events[s]);
85 else
86 m_States[s].OnExit(null);
87
88 m_States[s] = null;
89 }
90 }
91 }
92
96 void Update (float dt)
97 {
98 if (IsRunning())
99 {
100 for (int s = 0; s < m_States.Count(); ++s)
101 {
102 m_States[s].OnUpdate(dt);
103 }
104 }
105 }
106
114
121 {
122 int count = m_Transitions.Count();
123 for (int i = 0; i < count; ++i)
124 {
126 if (row.m_event.Type() == e.Type())
127 {
128 for (int s = 0; s < m_States.Count(); ++s)
129 {
130 if (row.m_srcState.Type() == m_States[s].Type() && row.m_event.Type() == e.Type())
131 {
133 bool hasGuard = t.m_guard != NULL;
134 if (!hasGuard || (hasGuard && t.m_guard.GuardCondition(e))) // 1) exec guard (if any)
135 {
136 ProcessLocalTransition(s, t, e); // 2) process transition allowed by guard
137 }
138 }
139 }
140 }
141 }
142 return ProcessEventResult.FSM_NO_TRANSITION;
143 }
144
152 {
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());
154
155 m_States[s].OnExit(e); // 1) call onExit on old state
156
157 if (t.m_action)
158 t.m_action.Action(e); // 2) execute transition action (if any)
159
160 m_States[s] = t.m_dstState; // 3) change state to new
161
162 if (t.m_dstState != NULL)
163 {
164 m_States[s].OnEntry(e); // 4a) call onEntry on new state
165 return ProcessEventResult.FSM_OK;
166 }
167 else
168 {
169 if (LogManager.IsInventoryHFSMLogEnable()) fsmbDebugPrint("[ofsm] terminating fsm: state=" + t.m_srcState.ToString() + " event=" + e.ToString());
170 return ProcessEventResult.FSM_TERMINATED; // 4b) or terminate
171 }
172 }
173};
174
proto string ToString()
ProcessEventResult
Определения FSMBase.c:41
void fsmbDebugPrint(string s)
Определения FSMBase.c:1
Super root of all classes in Enforce script.
Определения EnScript.c:11
represents transition src -— event[guard]/action -—|> dst
static bool IsInventoryHFSMLogEnable()
Определения Debug.c:668
Определения Debug.c:594
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...
Определения OFSMBase.c:44
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
Определения OFSMBase.c:151
bool IsRunning()
returns true if machine is in running state
Определения OFSMBase.c:62
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
adds transition into transition table
Определения OFSMBase.c:110
void Update(float dt)
if machine running, call OnUpdate() on current state
Определения OFSMBase.c:96
ref array< ref FSMStateBase > m_InitialStates
current fsm state
Определения OFSMBase.c:10
void SetInitialStates(array< ref FSMStateBase > initial_states)
Определения OFSMBase.c:32
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_Transitions
configurable initial state of the machine
Определения OFSMBase.c:11
ProcessEventResult ProcessEvent(FSMEventBase e)
instructs the state machine to process the event e
Определения OFSMBase.c:120
void Terminate(array< ref FSMEventBase > terminal_events=null)
terminates the state machine
Определения OFSMBase.c:77
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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