Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
ofsmbase.c
Go to the documentation of this file.
1
7
class
OFSMBase
<
Class
FSMStateBase,
Class
FSMEventBase,
Class
FSMActionBase,
Class
FSMGuardBase>
8
{
9
protected
ref
array<ref FSMStateBase>
m_States
;
10
protected
ref
array<ref FSMStateBase>
m_InitialStates
;
11
protected
ref
array<ref FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
>
m_Transitions
;
12
13
void
OFSMBase
()
14
{
15
m_States
=
new
array<ref FSMStateBase>
;
16
m_InitialStates
=
new
array<ref FSMStateBase>
;
17
m_Transitions
=
new
array<ref FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
>;
18
}
19
24
array<ref FSMStateBase>
GetCurrentState
()
25
{
26
return
m_States
;
27
}
28
32
void
SetInitialStates
(
array<ref FSMStateBase>
initial_states)
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
{
50
m_States
[s] =
m_InitialStates
[s];
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
110
void
AddTransition
(
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t)
111
{
112
m_Transitions
.Insert(t);
113
}
114
120
ProcessEventResult
ProcessEvent
(FSMEventBase e)
121
{
122
int
count =
m_Transitions
.Count();
123
for
(
int
i = 0; i < count; ++i)
124
{
125
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
row =
m_Transitions
.Get(i);
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
{
132
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t =
m_Transitions
.Get(i);
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
151
protected
ProcessEventResult
ProcessLocalTransition
(
int
s,
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t, FSMEventBase e)
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
Class
Super root of all classes in Enforce script.
Definition
enscript.c:11
FSMTransition
represents transition src -— event[guard]/action -—|> dst
LogManager
Definition
debug.c:692
LogManager::IsInventoryHFSMLogEnable
static bool IsInventoryHFSMLogEnable()
Definition
debug.c:766
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::SetInitialStates
void SetInitialStates(array< ref FSMStateBase > initial_states)
Definition
ofsmbase.c:32
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::ProcessEvent
ProcessEventResult ProcessEvent(FSMEventBase e)
Definition
ofsmbase.c:120
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::IsRunning
bool IsRunning()
returns true if machine is in running state
Definition
ofsmbase.c:62
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::AddTransition
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
Definition
ofsmbase.c:110
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Start
void Start(array< ref FSMEventBase > initial_events=null)
Definition
ofsmbase.c:44
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_InitialStates
ref array< ref FSMStateBase > m_InitialStates
current fsm state
Definition
ofsmbase.c:10
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Terminate
void Terminate(array< ref FSMEventBase > terminal_events=null)
Definition
ofsmbase.c:77
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Update
void Update(float dt)
Definition
ofsmbase.c:96
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_Transitions
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_Transitions
configurable initial state of the machine
Definition
ofsmbase.c:11
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_States
ref array< ref FSMStateBase > m_States
Definition
ofsmbase.c:9
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::GetCurrentState
array< ref FSMStateBase > GetCurrentState()
Definition
ofsmbase.c:24
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::ProcessLocalTransition
ProcessEventResult ProcessLocalTransition(int s, FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
Definition
ofsmbase.c:151
OFSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::OFSMBase
void OFSMBase()
fsm transition table
Definition
ofsmbase.c:13
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
ToString
proto string ToString()
ProcessEventResult
ProcessEventResult
Definition
fsmbase.c:41
fsmbDebugPrint
void fsmbDebugPrint(string s)
Definition
fsmbase.c:1
string::ToString
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
IsRunning
bool IsRunning()
Definition
tools.c:264
Games
Dayz
scripts
3_game
systems
ofsmbase.c
Generated by
1.17.0