Skip to content

Commit af29622

Browse files
committed
Merge branch 'dev'
2 parents f9d4729 + bba3a4d commit af29622

File tree

38 files changed

+964
-400
lines changed

38 files changed

+964
-400
lines changed

core/boot.sqf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
Title: Core Framework Bootstrap
4+
Author(s): Naught
5+
*/
6+
7+
/* Don't Double Load */
8+
if !(isNil "core_init") exitWith {};
9+
10+
/* Set Defines */
11+
#define COMPONENT "Core-Init"
12+
13+
/* Load Version Number */
14+
core_version = call compile preprocessFile "core\version";
15+
16+
/* Start Loading Screen */
17+
startLoadingScreen [format["Loading Core Mission Framework v%1...", core_version]];
18+
19+
/* Load Data and Libraries */
20+
#include "load.sqf"
21+
22+
/* Load Core Initialization */
23+
#include "init.sqf"
24+
25+
/* End Loading Screen */
26+
endLoadingScreen;

core/execute.sqf renamed to core/exec.sqf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
/*
3-
File: execute.sqf
3+
File: exec.sqf
44
Author(s): Naught
55
Description:
66
Executes code from an addAction event.
77
Syntax:
88
http://community.bistudio.com/wiki/addAction
99
Example:
10-
player addAction ["Run free!", "core\execute.sqf", {_this call my_fnc_name}];
10+
player addAction ["Run free!", "core\exec.sqf", {_this call my_fnc_name}];
1111
Notes:
1212
1. The argument (index 3) should be the code to run.
1313
2. The code is called from the addAction runtime environment.

core/headers/macros.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
/*
3+
Title: Core Macros
4+
*/
5+
6+
/*
7+
Section: General Macros
8+
*/
9+
10+
#define QUOTE(var) #var
11+
#define DOUBLES(var1,var2) ##var1##_##var2
12+
#define TRIPLES(var1,var2,var3) ##var1##_##var2##_##var3
13+
#define DEFAULT_PARAM(idx,dft) if ((count _this) > idx) then {_this select idx} else {dft}
14+
15+
/*
16+
Section: Function Macros
17+
*/
18+
19+
#define DEPRECATE(oldFnc,newFunc) \
20+
oldFnc = {_this call newFunc} // Encapsulate in code brackets to disable copying of function
21+
22+
/*
23+
Section: Logging Macros
24+
*/
25+
26+
#define LOG_FORMAT(varLevel,varComponent,varText,varParams) \
27+
[varLevel, varComponent, varText, varParams, __FILE__, __LINE__] call core_fnc_log
28+
29+
#define LOG(varLevel,varComponent,varText) \
30+
LOG_FORMAT(varLevel,varComponent,varText,[])
31+
32+
#define LOG_INFO(varComponent,varText) \
33+
LOG("Info",varComponent,varText)
34+
35+
#define LOG_NOTICE(varComponent,varText) \
36+
LOG("Notice",varComponent,varText)
37+
38+
#define LOG_WARNING(varComponent,varText) \
39+
LOG("Warning",varComponent,varText)
40+
41+
#define LOG_ERROR(varComponent,varText) \
42+
LOG("Error",varComponent,varText)
43+
44+
#define LOG_CRITICAL(varComponent,varText) \
45+
LOG("Critical",varComponent,varText)
46+
47+
/*
48+
Section: Internal Macros
49+
*/
50+
51+
#define ARRAY_1(var1) [var1]
52+
#define ARRAY_2(var1,var2) [var1,var2]
53+
#define ARRAY_3(var1,var2,var3) [var1,var2,var3]
54+
#define ARRAY_4(var1,var2,var3,var4) [var1,var2,var3,var4]
55+
#define ARRAY_5(var1,var2,var3,var4,var5) [var1,var2,var3,var4,var5]
56+
#define ARRAY_6(var1,var2,var3,var4,var5,var6) [var1,var2,var3,var4,var5,var6]
57+
#define ARRAY_7(var1,var2,var3,var4,var5,var6,var7) [var1,var2,var3,var4,var5,var6,var7]
58+
#define ARRAY_8(var1,var2,var3,var4,var5,var6,var7,var8) [var1,var2,var3,var4,var5,var6,var7,var8]
59+
#define ARRAY_9(var1,var2,var3,var4,var5,var6,var7,var8,var9) [var1,var2,var3,var4,var5,var6,var7,var8,var9]

core/init.sqf

Lines changed: 46 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,148 +7,115 @@
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"
1511
core_init = false;
12+
13+
/* Immediately Send Server Status */
1614
if (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 */
5222
private ["_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")
6929
private ["_params"];
7030
_params = [];
71-
["Info", COMPONENT, "Loading mission parameters.", [], __FILE__, __LINE__] call core_fnc_log;
72-
#define PARAMS_CONFIG (missionConfigFile >> "Params")
31+
7332
if (isNil "paramsArray") then {paramsArray = []};
33+
7434
for "_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")
10370
private ["_modules"];
10471
_modules = [];
72+
10573
for "_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 */
135104
processInitCommands;
136105

137-
/* End Loading Screen */
138-
endLoadingScreen;
139-
140106
/* Finish world initialization*/
141107
finishMissionInit;
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

Comments
 (0)