Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanplecki committed May 8, 2014
2 parents f9d4729 + bba3a4d commit af29622
Show file tree
Hide file tree
Showing 38 changed files with 964 additions and 400 deletions.
26 changes: 26 additions & 0 deletions core/boot.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*
Title: Core Framework Bootstrap
Author(s): Naught
*/

/* Don't Double Load */
if !(isNil "core_init") exitWith {};

/* Set Defines */
#define COMPONENT "Core-Init"

/* Load Version Number */
core_version = call compile preprocessFile "core\version";

/* Start Loading Screen */
startLoadingScreen [format["Loading Core Mission Framework v%1...", core_version]];

/* Load Data and Libraries */
#include "load.sqf"

/* Load Core Initialization */
#include "init.sqf"

/* End Loading Screen */
endLoadingScreen;
4 changes: 2 additions & 2 deletions core/execute.sqf → core/exec.sqf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

/*
File: execute.sqf
File: exec.sqf
Author(s): Naught
Description:
Executes code from an addAction event.
Syntax:
http://community.bistudio.com/wiki/addAction
Example:
player addAction ["Run free!", "core\execute.sqf", {_this call my_fnc_name}];
player addAction ["Run free!", "core\exec.sqf", {_this call my_fnc_name}];
Notes:
1. The argument (index 3) should be the code to run.
2. The code is called from the addAction runtime environment.
Expand Down
59 changes: 59 additions & 0 deletions core/headers/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

/*
Title: Core Macros
*/

/*
Section: General Macros
*/

#define QUOTE(var) #var
#define DOUBLES(var1,var2) ##var1##_##var2
#define TRIPLES(var1,var2,var3) ##var1##_##var2##_##var3
#define DEFAULT_PARAM(idx,dft) if ((count _this) > idx) then {_this select idx} else {dft}

/*
Section: Function Macros
*/

#define DEPRECATE(oldFnc,newFunc) \
oldFnc = {_this call newFunc} // Encapsulate in code brackets to disable copying of function

/*
Section: Logging Macros
*/

#define LOG_FORMAT(varLevel,varComponent,varText,varParams) \
[varLevel, varComponent, varText, varParams, __FILE__, __LINE__] call core_fnc_log

#define LOG(varLevel,varComponent,varText) \
LOG_FORMAT(varLevel,varComponent,varText,[])

#define LOG_INFO(varComponent,varText) \
LOG("Info",varComponent,varText)

#define LOG_NOTICE(varComponent,varText) \
LOG("Notice",varComponent,varText)

#define LOG_WARNING(varComponent,varText) \
LOG("Warning",varComponent,varText)

#define LOG_ERROR(varComponent,varText) \
LOG("Error",varComponent,varText)

#define LOG_CRITICAL(varComponent,varText) \
LOG("Critical",varComponent,varText)

/*
Section: Internal Macros
*/

#define ARRAY_1(var1) [var1]
#define ARRAY_2(var1,var2) [var1,var2]
#define ARRAY_3(var1,var2,var3) [var1,var2,var3]
#define ARRAY_4(var1,var2,var3,var4) [var1,var2,var3,var4]
#define ARRAY_5(var1,var2,var3,var4,var5) [var1,var2,var3,var4,var5]
#define ARRAY_6(var1,var2,var3,var4,var5,var6) [var1,var2,var3,var4,var5,var6]
#define ARRAY_7(var1,var2,var3,var4,var5,var6,var7) [var1,var2,var3,var4,var5,var6,var7]
#define ARRAY_8(var1,var2,var3,var4,var5,var6,var7,var8) [var1,var2,var3,var4,var5,var6,var7,var8]
#define ARRAY_9(var1,var2,var3,var4,var5,var6,var7,var8,var9) [var1,var2,var3,var4,var5,var6,var7,var8,var9]
143 changes: 46 additions & 97 deletions core/init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,115 @@
modules, parameters, and synchronizes machines.
*/

/* Don't Double Load */
if !(isNil "core_init") exitWith {};

/* Set Reference Variables */
#define COMPONENT "Core-Init"
core_init = false;

/* Immediately Send Server Status */
if (isServer) then {
core_serverInit = false;
publicVariable "core_serverInit";
};
core_version = call compile preprocessFile "core\version";

/* Start Loading Screen */
startLoadingScreen ["Loading Core Mission Framework..."];

/* Load Headers */
#include "headers\oop.h"

/* Load Libraries */
#include "libraries\arrays.sqf"
#include "libraries\chrono.sqf"
#include "libraries\config.sqf"
#include "libraries\conversions.sqf"
#include "libraries\diagnostics.sqf"
#include "libraries\filesystem.sqf"
#include "libraries\math.sqf"
#include "libraries\mission.sqf"
#include "libraries\rve.sqf"
#include "libraries\strings.sqf"
#include "libraries\ui.sqf"

/* Load Objects */
#include "objects\hashmap.sqf"

/* Load Logging Configuration */
#define GET_LOG_LEVEL(cfg) (missionConfigFile >> "Core" >> cfg)
{ // forEach
[_x, true] call core_fnc_setLogLevel;
} forEach ([(if (!isMultiplayer) then {GET_LOG_LEVEL("sp_log_level")} else {GET_LOG_LEVEL("mp_log_level")}), []] call core_fnc_getConfigValue);
core_logToDiary = [[missionConfigFile >> "Core" >> "log_to_diary", 0] call core_fnc_getConfigValue] call core_fnc_toBool;

LOG_NOTICE(COMPONENT, "Core initialization has started.");

/* Start Initialization */
private ["_startTime"];
_startTime = diag_tickTime;
["Notice", COMPONENT, "Core initialization has started.", [], __FILE__, __LINE__] call core_fnc_log;

/* Initialize Client ID System */
if (isServer) then {
core_clientId = -1;
"core_clientIdRequest" addPublicVariableEventHandler {
private ["_clientId"];
_clientId = owner(_this select 1);
core_clientId = _clientId;
_clientId publicVariableClient "core_clientId";
core_clientId = -1;
};
};
LOG_INFO(COMPONENT, "Loading mission parameters.");

/* Load Mission Parameters */
#define PARAMS_CONFIG (missionConfigFile >> "Params")
private ["_params"];
_params = [];
["Info", COMPONENT, "Loading mission parameters.", [], __FILE__, __LINE__] call core_fnc_log;
#define PARAMS_CONFIG (missionConfigFile >> "Params")

if (isNil "paramsArray") then {paramsArray = []};

for "_i" from 0 to ((count PARAMS_CONFIG) - 1) do {
private ["_param", "_var", "_value"];
_param = PARAMS_CONFIG select _i;

_var = if (isText(_param >> "variable")) then {
getText(_param >> "variable");
} else {
format["param_%1", (configName(_param))];
};

_value = if ((count paramsArray) > _i) then {
paramsArray select _i;
} else {
[_param >> "default"] call core_fnc_getConfigValue;
};

if ((isNumber(_param >> "boolean")) && {(getNumber(_param >> "boolean")) == 1}) then {
_value = [_value] call core_fnc_toBool;
};

if (isText(_param >> "execute")) then {
_value = _value call compile (getText(_param >> "execute"));
};

if (_var != "") then {
missionNameSpace setVariable [_var, _value];
};

[_params, [getText(_param >> "title"), _value]] call core_fnc_push;
paramsArray set [_i, _value];
};

LOG_INFO(COMPONENT, "Loading mission modules.");

/* Load Modules */
["Info", COMPONENT, "Loading mission modules.", [], __FILE__, __LINE__] call core_fnc_log;
#define MODULES_CONFIG (missionConfigFile >> "Modules")
private ["_modules"];
_modules = [];

for "_i" from 0 to ((count MODULES_CONFIG) - 1) do {
[_modules, (MODULES_CONFIG select _i)] call core_fnc_push;
};

LOG_INFO(COMPONENT, "Loading module settings.");

/* Load Module Settings */
["Info", COMPONENT, "Loading module settings.", [], __FILE__, __LINE__] call core_fnc_log;
{ // forEach
private ["_settings"];
_settings = _x >> "settings";

if (isClass _settings) then {
for "_i" from 0 to ((count _settings) - 1) do {
private ["_setting"];
_setting = _settings select _i;

if (!(isClass _setting)) then {
missionNamespace setVariable [
(configName _setting),
([_setting] call core_fnc_getConfigValue)
];
missionNamespace setVariable [(configName _setting), ([_setting] call core_fnc_getConfigValue)];
};
};
};
} forEach _modules;

LOG_INFO(COMPONENT, "Loading module preinits.");

/* Load Module Pre-Inits */
["Info", COMPONENT, "Loading module preinits.", [], __FILE__, __LINE__] call core_fnc_log;
{ // forEach
[_x, "preinit", false] call core_fnc_loadModule;
} forEach _modules;

/* Process Vehicle Init Code */
processInitCommands;

/* End Loading Screen */
endLoadingScreen;

/* Finish world initialization*/
finishMissionInit;

/* Start Delayed Execution */
[_startTime, _modules, _params] spawn {
private ["_postInit"];
_postInit = [_startTime, _modules, _params] spawn {
private ["_startTime", "_modules", "_params"];
_startTime = _this select 0;
_modules = _this select 1;
_params = _this select 2;

/* Wait for Player */
if (!isDedicated) then {
if (isMultiplayer && {!isDedicated}) then {
[{!(isNull player)}, -1, "Player Initialization"] call core_fnc_wait;
};

Expand All @@ -157,36 +124,24 @@ finishMissionInit;
[{!(isNil "core_serverInit") && {core_serverInit}}, -1, "Core Server Initialization"] call core_fnc_wait;
};

/* Request Client ID */
if (!isDedicated) then {
if (isServer) then {
core_clientId = owner(player);
} else {
["Info", COMPONENT, "Requesting Client ID.", [], __FILE__, __LINE__] call core_fnc_log;
core_clientIdRequest = player;
publicVariableServer "core_clientIdRequest";
waitUntil {!isNil "core_clientId"};
};
};

/* Wait for XEH Post-Initialization */
if (isClass(configFile >> "CfgPatches" >> "cba_xeh")) then {
[{!(isNil "SLX_XEH_MACHINE") && {SLX_XEH_MACHINE select 8}}, -1, "XEH Initialization"] call core_fnc_wait;
};

LOG_INFO("Loading module post-inits.");

/* Load Module Post-Inits */
["Info", COMPONENT, "Loading module post-inits.", [], __FILE__, __LINE__] call core_fnc_log;
{ // forEach
[_x, "postinit", true] call core_fnc_loadModule;
} forEach _modules;

/* Load Framework Documentation */
#define DIARY_BUFFER_FLUSH_INTERVAL 1 // second(s)
if (!isDedicated) then {
player createDiarySubject ["core_docs", "Core Framework"];
if (hasInterface) then {
private ["_modDoc", "_paramDoc"];
_modDoc = "<br/>Mission Modules:";
_paramDoc = "<br/>Mission Parameters:<br/>";

{ // forEach
_modDoc = _modDoc + format["<br/><br/>------------------------<br/><br/> Module: %1<br/> Version: %2<br/> Author(s): %3<br/> URL: %4",
[_x >> "name", "N/A"] call core_fnc_getConfigValue,
Expand All @@ -195,30 +150,26 @@ finishMissionInit;
[_x >> "url", "N/A"] call core_fnc_getConfigValue
];
} forEach _modules;

{ // forEach
_paramDoc = _paramDoc + format["<br/> %1: %2", (_x select 0), (_x select 1)];
} forEach _params;
player createDiaryRecord ["core_docs", ["About",
format["<br/>Core Mission Framework<br/><br/>Version: %1<br/>Authors: Naught, Olsen", core_version]
]];
player createDiaryRecord ["core_docs", ["Modules", _modDoc]];
player createDiaryRecord ["core_docs", ["Parameters", _paramDoc]];
if (core_logToDiary) then { // Ensure initial load of diary record
player createDiaryRecord ["core_docs", ["Diagnostics Log", ""]];
};
[] spawn {
while {true} do {
if (core_logToDiary && {(count core_diaryLogQueue) > 0}) then {
{ // forEach
player createDiaryRecord ["core_docs", ["Diagnostics Log", _x]];
} forEach core_diaryLogQueue;
core_diaryLogQueue = []; // Okay while SQF variable mutex is guaranteed
};
uiSleep DIARY_BUFFER_FLUSH_INTERVAL;
};

waitUntil {player diarySubjectExists C_DIARY_SUBJECT};
player createDiaryRecord [C_DIARY_SUBJECT, ["About", format["<br/>Core Mission Framework<br/><br/>Version: %1<br/>Authors: Naught, Olsen", core_version]]];
player createDiaryRecord [C_DIARY_SUBJECT, ["Modules", _modDoc]];
player createDiaryRecord [C_DIARY_SUBJECT, ["Parameters", _paramDoc]];

if (core_logToDiary) then { // Ensure initial load of logging diary record
player createDiaryRecord [C_DIARY_SUBJECT, ["Diagnostics Log", ""]];
};
};

/* Wait For Post-Inits To Finish Processing */
if ((count core_scheduledModules) > 0) then {
[{{if !(scriptDone _x) exitWith {false}; true} forEach core_scheduledModules}, 15, "Core Post-Initialization"] call core_fnc_wait;
};

/* Finalize Reference Variables */
core_init = true;
if (isServer) then {
Expand All @@ -227,7 +178,5 @@ finishMissionInit;
};

/* Finalizing Initialization */
["Notice", COMPONENT, "Core initialization has finished. Benchmark: %1 sec.", [
(diag_tickTime - _startTime)
], __FILE__, __LINE__] call core_fnc_log;
LOG_FORMAT("Notice", COMPONENT, "Core initialization has finished. Benchmark: %1 sec.", [diag_tickTime - _startTime]);
};
Loading

0 comments on commit af29622

Please sign in to comment.