-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathfnc_create.sqf
68 lines (57 loc) · 2.21 KB
/
fnc_create.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_statemachine_fnc_create
Description:
Creates a state machine.
Parameters:
_list - list of anything over which the state machine will run
(type needs to support setVariable) <ARRAY>
OR
code that will generate this list, called once the list
has been cycled through <CODE>
_skipNull - skip list items that are null
Returns:
_stateMachine - a state machine <LOCATION>
Examples:
(begin example)
_stateMachine = call CBA_statemachine_fnc_create;
(end)
Author:
BaerMitUmlaut
---------------------------------------------------------------------------- */
SCRIPT(create);
params [
["_list", [], [[], {}]],
["_skipNull", false, [true]]
];
if (isNil QGVAR(stateMachines)) then {
GVAR(stateMachines) = [];
GVAR(nextUniqueID) = 0;
};
#ifdef STATEMACHINE_PERFORMANCE_COUNTERS
if (isNil QGVAR(performanceCounters)) then {GVAR(performanceCounters) = [];};
GVAR(performanceCounters) pushBack [];
#endif
private _updateCode = {};
if (_list isEqualType {}) then {
_updateCode = _list;
_list = [] call _updateCode;
} else {
// Filter list in case null elements were passed
if (_skipNull) then {
_list = _list select {!isNull _x};
};
};
private _stateMachine = call CBA_fnc_createNamespace;
_stateMachine setVariable [QGVAR(nextUniqueStateID), 0]; // Unique ID for autogenerated state names
_stateMachine setVariable [QGVAR(tick), 0]; // List index ticker
_stateMachine setVariable [QGVAR(states), []]; // State machine states
_stateMachine setVariable [QGVAR(list), _list]; // List state machine iterates over
_stateMachine setVariable [QGVAR(skipNull), _skipNull]; // Skip items that are null
_stateMachine setVariable [QGVAR(updateCode), _updateCode]; // List update code
_stateMachine setVariable [QGVAR(ID), GVAR(nextUniqueID)]; // Unique state machine ID
INC(GVAR(nextUniqueID));
if (isNil QGVAR(efID)) then {
GVAR(efID) = addMissionEventHandler ["EachFrame", {call FUNC(clockwork)}];
};
_stateMachine