Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
fsmbase.c
Go to the documentation of this file.
1
void
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
}
9
void
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
22
class
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
40
enum
ProcessEventResult
41
{
42
FSM_OK
,
43
FSM_TERMINATED
,
44
FSM_ABORTED
,
45
FSM_NO_TRANSITION
,
46
};
47
54
class
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
;
59
protected
ref
array<ref FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
>
m_transitions
;
60
61
void
FSMBase
()
62
{
63
m_transitions
=
new
array<ref FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
>;
64
}
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
91
m_state
=
m_initialState
;
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
124
void
AddTransition
(
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t)
125
{
126
m_transitions
.Insert(t);
127
}
128
134
ProcessEventResult
ProcessEvent
(FSMEventBase e)
135
{
136
FSMStateBase curr_state =
m_state
;
137
138
int
count =
m_transitions
.Count();
139
for
(
int
i = 0; i < count; ++i)
140
{
141
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
row =
m_transitions
.Get(i);
142
if
(row.m_srcState.Type() == curr_state.Type() && row.m_event.Type() == e.Type())
143
{
144
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t =
m_transitions
.Get(i);
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
161
protected
ProcessEventResult
ProcessLocalTransition
(
FSMTransition<FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase>
t, FSMEventBase e)
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
Class
Super root of all classes in Enforce script.
Definition
enscript.c:11
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_initialEvent
ref FSMEventBase m_initialEvent
configurable initial state of the machine
Definition
fsmbase.c:58
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::SetInitialState
void SetInitialState(FSMStateBase initial_state)
Definition
fsmbase.c:78
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::ProcessEvent
ProcessEventResult ProcessEvent(FSMEventBase e)
Definition
fsmbase.c:134
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Terminate
void Terminate(FSMEventBase terminal_event=NULL)
Definition
fsmbase.c:103
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_state
ref FSMStateBase m_state
Definition
fsmbase.c:56
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::IsRunning
bool IsRunning()
returns true if machine is in running state
Definition
fsmbase.c:98
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_initialState
ref FSMStateBase m_initialState
current fsm state
Definition
fsmbase.c:57
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::AddTransition
void AddTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t)
Definition
fsmbase.c:124
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Start
void Start(FSMEventBase initial_event=NULL)
Definition
fsmbase.c:87
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::ProcessLocalTransition
ProcessEventResult ProcessLocalTransition(FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > t, FSMEventBase e)
Definition
fsmbase.c:161
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::Update
void Update(float dt)
Definition
fsmbase.c:115
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_transitions
ref array< ref FSMTransition< FSMStateBase, FSMEventBase, FSMActionBase, FSMGuardBase > > m_transitions
configurable initial event to start the machine (null by default)
Definition
fsmbase.c:59
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::FSMBase
void FSMBase()
fsm transition table
Definition
fsmbase.c:61
FSMBase< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::GetCurrentState
FSMStateBase GetCurrentState()
returns currently active state
Definition
fsmbase.c:70
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_guard
ref FSMGuardBase m_guard
Definition
fsmbase.c:28
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::FSMTransition
void FSMTransition(FSMStateBase src, FSMEventBase e, FSMStateBase dst, FSMActionBase a=NULL, FSMGuardBase g=NULL)
Definition
fsmbase.c:30
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_srcState
ref FSMStateBase m_srcState
Definition
fsmbase.c:24
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_event
ref FSMEventBase m_event
Definition
fsmbase.c:25
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_dstState
ref FSMStateBase m_dstState
Definition
fsmbase.c:26
FSMTransition< Class FSMStateBase, Class FSMEventBase, Class FSMActionBase, Class FSMGuardBase >::m_action
ref FSMActionBase m_action
Definition
fsmbase.c:27
FSMTransition
represents transition src -— event[guard]/action -—|> dst
LogManager
Definition
debug.c:692
LogManager::IsInventoryHFSMLogEnable
static bool IsInventoryHFSMLogEnable()
Definition
debug.c:766
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
ToString
proto string ToString()
ProcessEventResult
ProcessEventResult
Definition
fsmbase.c:41
FSM_ABORTED
@ FSM_ABORTED
Definition
fsmbase.c:44
FSM_OK
@ FSM_OK
Definition
fsmbase.c:42
FSM_TERMINATED
@ FSM_TERMINATED
Definition
fsmbase.c:43
FSM_NO_TRANSITION
@ FSM_NO_TRANSITION
Definition
fsmbase.c:45
fsmbDebugPrint
void fsmbDebugPrint(string s)
Definition
fsmbase.c:1
fsmbDebugSpam
void fsmbDebugSpam(string s)
Definition
fsmbase.c:9
PrintToRPT
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
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
fsmbase.c
Generated by
1.17.0