77 modules, parameters, and synchronizes machines.
88*/
99
10- /* Don't Double Load */
11- if ! (isNil " core_init" ) exitWith {};
12-
1310/* Set Reference Variables */
14- #define COMPONENT " Core-Init"
1511core_init = false ;
12+
13+ /* Immediately Send Server Status */
1614if (isServer) then {
1715 core_serverInit = false ;
1816 publicVariable " core_serverInit" ;
1917};
20- core_version = call compile preprocessFile " core\version" ;
21-
22- /* Start Loading Screen */
23- startLoadingScreen [" Loading Core Mission Framework..." ];
24-
25- /* Load Headers */
26- #include " headers\oop.h"
27-
28- /* Load Libraries */
29- #include " libraries\arrays.sqf"
30- #include " libraries\chrono.sqf"
31- #include " libraries\config.sqf"
32- #include " libraries\conversions.sqf"
33- #include " libraries\diagnostics.sqf"
34- #include " libraries\filesystem.sqf"
35- #include " libraries\math.sqf"
36- #include " libraries\mission.sqf"
37- #include " libraries\rve.sqf"
38- #include " libraries\strings.sqf"
39- #include " libraries\ui.sqf"
40-
41- /* Load Objects */
42- #include " objects\hashmap.sqf"
43-
44- /* Load Logging Configuration */
45- #define GET_LOG_LEVEL(cfg) (missionConfigFile >> " Core" >> cfg)
46- { // forEach
47- [_x , true ] call core_fnc_setLogLevel ;
48- } forEach ([(if (! isMultiplayer) then {GET_LOG_LEVEL(" sp_log_level" )} else {GET_LOG_LEVEL(" mp_log_level" )}), []] call core_fnc_getConfigValue );
49- core_logToDiary = [[missionConfigFile >> " Core" >> " log_to_diary" , 0 ] call core_fnc_getConfigValue ] call core_fnc_toBool ;
18+
19+ LOG_NOTICE(COMPONENT, " Core initialization has started." );
5020
5121/* Start Initialization */
5222private [" _startTime" ];
5323_startTime = diag_tickTime;
54- [" Notice" , COMPONENT, " Core initialization has started." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
5524
56- /* Initialize Client ID System */
57- if (isServer) then {
58- core_clientId = - 1 ;
59- " core_clientIdRequest" addPublicVariableEventHandler {
60- private [" _clientId" ];
61- _clientId = owner(_this select 1 );
62- core_clientId = _clientId ;
63- _clientId publicVariableClient " core_clientId" ;
64- core_clientId = - 1 ;
65- };
66- };
25+ LOG_INFO(COMPONENT, " Loading mission parameters." );
6726
6827/* Load Mission Parameters */
28+ #define PARAMS_CONFIG (missionConfigFile >> " Params" )
6929private [" _params" ];
7030_params = [];
71- [" Info" , COMPONENT, " Loading mission parameters." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
72- #define PARAMS_CONFIG (missionConfigFile >> " Params" )
31+
7332if (isNil " paramsArray" ) then {paramsArray = []};
33+
7434for " _i" from 0 to ((count PARAMS_CONFIG) - 1 ) do {
7535 private [" _param" , " _var" , " _value" ];
7636 _param = PARAMS_CONFIG select _i ;
37+
7738 _var = if (isText(_param >> " variable" )) then {
7839 getText(_param >> " variable" );
7940 } else {
8041 format [" param_%1" , (configName(_param ))];
8142 };
43+
8244 _value = if ((count paramsArray) > _i ) then {
8345 paramsArray select _i ;
8446 } else {
8547 [_param >> " default" ] call core_fnc_getConfigValue ;
8648 };
49+
8750 if ((isNumber(_param >> " boolean" )) && {(getNumber(_param >> " boolean" )) == 1 }) then {
8851 _value = [_value ] call core_fnc_toBool ;
8952 };
53+
9054 if (isText(_param >> " execute" )) then {
9155 _value = _value call compile (getText(_param >> " execute" ));
9256 };
57+
9358 if (_var ! = " " ) then {
9459 missionNameSpace setVariable [_var , _value ];
9560 };
61+
9662 [_params , [getText(_param >> " title" ), _value ]] call core_fnc_push ;
9763 paramsArray set [_i , _value ];
9864};
9965
66+ LOG_INFO(COMPONENT, " Loading mission modules." );
67+
10068/* Load Modules */
101- [" Info" , COMPONENT, " Loading mission modules." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
10269#define MODULES_CONFIG (missionConfigFile >> " Modules" )
10370private [" _modules" ];
10471_modules = [];
72+
10573for " _i" from 0 to ((count MODULES_CONFIG) - 1 ) do {
10674 [_modules , (MODULES_CONFIG select _i )] call core_fnc_push ;
10775};
10876
77+ LOG_INFO(COMPONENT, " Loading module settings." );
78+
10979/* Load Module Settings */
110- [" Info" , COMPONENT, " Loading module settings." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
11180{ // forEach
11281 private [" _settings" ];
11382 _settings = _x >> " settings" ;
83+
11484 if (isClass _settings ) then {
11585 for " _i" from 0 to ((count _settings ) - 1 ) do {
11686 private [" _setting" ];
11787 _setting = _settings select _i ;
88+
11889 if (! (isClass _setting )) then {
119- missionNamespace setVariable [
120- (configName _setting ),
121- ([_setting ] call core_fnc_getConfigValue )
122- ];
90+ missionNamespace setVariable [(configName _setting ), ([_setting ] call core_fnc_getConfigValue )];
12391 };
12492 };
12593 };
12694} forEach _modules ;
12795
96+ LOG_INFO(COMPONENT, " Loading module preinits." );
97+
12898/* Load Module Pre-Inits */
129- [" Info" , COMPONENT, " Loading module preinits." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
13099{ // forEach
131100 [_x , " preinit" , false ] call core_fnc_loadModule ;
132101} forEach _modules ;
133102
134103/* Process Vehicle Init Code */
135104processInitCommands;
136105
137- /* End Loading Screen */
138- endLoadingScreen;
139-
140106/* Finish world initialization*/
141107finishMissionInit;
142108
143109/* Start Delayed Execution */
144- [_startTime , _modules , _params ] spawn {
110+ private [" _postInit" ];
111+ _postInit = [_startTime , _modules , _params ] spawn {
145112 private [" _startTime" , " _modules" , " _params" ];
146113 _startTime = _this select 0 ;
147114 _modules = _this select 1 ;
148115 _params = _this select 2 ;
149116
150117 /* Wait for Player */
151- if (! isDedicated) then {
118+ if (isMultiplayer && { ! isDedicated} ) then {
152119 [{! (isNull player )}, - 1 , " Player Initialization" ] call core_fnc_wait ;
153120 };
154121
@@ -157,36 +124,24 @@ finishMissionInit;
157124 [{! (isNil " core_serverInit" ) && {core_serverInit}}, - 1 , " Core Server Initialization" ] call core_fnc_wait ;
158125 };
159126
160- /* Request Client ID */
161- if (! isDedicated) then {
162- if (isServer) then {
163- core_clientId = owner(player );
164- } else {
165- [" Info" , COMPONENT, " Requesting Client ID." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
166- core_clientIdRequest = player ;
167- publicVariableServer " core_clientIdRequest" ;
168- waitUntil {! isNil " core_clientId" };
169- };
170- };
171-
172127 /* Wait for XEH Post-Initialization */
173128 if (isClass(configFile >> " CfgPatches" >> " cba_xeh" )) then {
174129 [{! (isNil " SLX_XEH_MACHINE" ) && {SLX_XEH_MACHINE select 8 }}, - 1 , " XEH Initialization" ] call core_fnc_wait ;
175130 };
176131
132+ LOG_INFO(" Loading module post-inits." );
133+
177134 /* Load Module Post-Inits */
178- [" Info" , COMPONENT, " Loading module post-inits." , [], __FILE__ , __LINE__ ] call core_fnc_log ;
179135 { // forEach
180136 [_x , " postinit" , true ] call core_fnc_loadModule ;
181137 } forEach _modules ;
182138
183139 /* Load Framework Documentation */
184- #define DIARY_BUFFER_FLUSH_INTERVAL 1 // second(s)
185- if (! isDedicated) then {
186- player createDiarySubject [" core_docs" , " Core Framework" ];
140+ if (hasInterface) then {
187141 private [" _modDoc" , " _paramDoc" ];
188142 _modDoc = " <br/>Mission Modules:" ;
189143 _paramDoc = " <br/>Mission Parameters:<br/>" ;
144+
190145 { // forEach
191146 _modDoc = _modDoc + format [" <br/><br/>------------------------<br/><br/> Module: %1<br/> Version: %2<br/> Author(s): %3<br/> URL: %4" ,
192147 [_x >> " name" , " N/A" ] call core_fnc_getConfigValue ,
@@ -195,30 +150,26 @@ finishMissionInit;
195150 [_x >> " url" , " N/A" ] call core_fnc_getConfigValue
196151 ];
197152 } forEach _modules ;
153+
198154 { // forEach
199155 _paramDoc = _paramDoc + format [" <br/> %1: %2" , (_x select 0 ), (_x select 1 )];
200156 } forEach _params ;
201- player createDiaryRecord [" core_docs" , [" About" ,
202- format [" <br/>Core Mission Framework<br/><br/>Version: %1<br/>Authors: Naught, Olsen" , core_version]
203- ]];
204- player createDiaryRecord [" core_docs" , [" Modules" , _modDoc ]];
205- player createDiaryRecord [" core_docs" , [" Parameters" , _paramDoc ]];
206- if (core_logToDiary) then { // Ensure initial load of diary record
207- player createDiaryRecord [" core_docs" , [" Diagnostics Log" , " " ]];
208- };
209- [] spawn {
210- while {true } do {
211- if (core_logToDiary && {(count core_diaryLogQueue) > 0 }) then {
212- { // forEach
213- player createDiaryRecord [" core_docs" , [" Diagnostics Log" , _x ]];
214- } forEach core_diaryLogQueue;
215- core_diaryLogQueue = []; // Okay while SQF variable mutex is guaranteed
216- };
217- uiSleep DIARY_BUFFER_FLUSH_INTERVAL;
218- };
157+
158+ waitUntil {player diarySubjectExists C_DIARY_SUBJECT};
159+ player createDiaryRecord [C_DIARY_SUBJECT, [" About" , format [" <br/>Core Mission Framework<br/><br/>Version: %1<br/>Authors: Naught, Olsen" , core_version]]];
160+ player createDiaryRecord [C_DIARY_SUBJECT, [" Modules" , _modDoc ]];
161+ player createDiaryRecord [C_DIARY_SUBJECT, [" Parameters" , _paramDoc ]];
162+
163+ if (core_logToDiary) then { // Ensure initial load of logging diary record
164+ player createDiaryRecord [C_DIARY_SUBJECT, [" Diagnostics Log" , " " ]];
219165 };
220166 };
221167
168+ /* Wait For Post-Inits To Finish Processing */
169+ if ((count core_scheduledModules) > 0 ) then {
170+ [{{if ! (scriptDone _x ) exitWith {false }; true } forEach core_scheduledModules}, 15 , " Core Post-Initialization" ] call core_fnc_wait ;
171+ };
172+
222173 /* Finalize Reference Variables */
223174 core_init = true ;
224175 if (isServer) then {
@@ -227,7 +178,5 @@ finishMissionInit;
227178 };
228179
229180 /* Finalizing Initialization */
230- [" Notice" , COMPONENT, " Core initialization has finished. Benchmark: %1 sec." , [
231- (diag_tickTime - _startTime )
232- ], __FILE__ , __LINE__ ] call core_fnc_log ;
181+ LOG_FORMAT(" Notice" , COMPONENT, " Core initialization has finished. Benchmark: %1 sec." , [diag_tickTime - _startTime ]);
233182};
0 commit comments