Advertisement
Guest User

Untitled

a guest
May 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 25.33 KB | None | 0 0
  1.  
  2. /*
  3.     File: init.sqf
  4.     Author: Karel Moricky, optimised headers by Killzone_Kid
  5.  
  6.     Description:
  7.     Function library initialization.
  8.  
  9.     Parameter(s):
  10.     _this select 0: 'Function manager' logic
  11.  
  12.     Returns:
  13.     Nothing
  14. */
  15.  
  16. #define VERSION 3.0
  17.  
  18. if (isNil "BIS_fnc_MP_packet") then {BIS_fnc_MP_packet = compileFinal ""}; //--- is not used anymore and so it should not be used anymore
  19.  
  20. //--- Check version, has to match config version
  21. if (getnumber (configfile >> "CfgFunctions" >> "version") != VERSION) exitwith {
  22.     textlogformat [
  23.         "Log: ERROR: Functions versions mismatch - config is %1, but script is %2",
  24.         getnumber (configfile >> "CfgFunctions" >> "version"),
  25.         VERSION
  26.     ];
  27. };
  28.  
  29. //--- Fake header
  30. _fnc_scriptName = if (isnil "_fnc_scriptName") then {"Functions Init"} else {_fnc_scriptName};
  31.  
  32.  
  33. /******************************************************************************************************
  34.     DEFINE HEADERS
  35.  
  36.     Headers are pieces of code inserted on the beginning of every function code before compiling.
  37.     Using 'BIS_fnc_functionsDebug', you can alter the headers to provide special debug output.
  38.  
  39.     Modes can be following:
  40.     0: No Debug - header saves parent script name and current script name into variables
  41.     1: Save script Map - header additionaly save an array of all parent scripts into variable
  42.     2: Save and log script map - apart from saving into variable, script map is also logged through debugLog
  43.  
  44.     Some system function are using simplified header unaffected to current debug mode.
  45.     These functions has headerType = 1; set in config.
  46.  
  47. ******************************************************************************************************/
  48.  
  49. private ["_this","_debug","_headerDefault","_fncCompile","_recompile"];
  50.  
  51. private _headerNoDebug = "
  52.     private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName};
  53.     private _fnc_scriptName = '%1';
  54.     scriptName _fnc_scriptName;
  55. ";
  56. private _headerSaveScriptMap = "
  57.     private _fnc_scriptMap = if (isNil '_fnc_scriptMap') then {[_fnc_scriptName]} else {_fnc_scriptMap + [_fnc_scriptName]};
  58. ";
  59. private _headerLogScriptMap = "
  60.     textLogFormat ['%1 : %2', _fnc_scriptMap joinString ' >> ', _this];
  61. ";
  62. private _headerSystem = "
  63.     private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'%1'} else {_fnc_scriptName};
  64.     scriptName '%1';
  65. ";
  66. private _headerNone = "";
  67. private _debugHeaderExtended = "";
  68.  
  69. //--- Compose headers based on current debug mode
  70. _debug = uinamespace getvariable ["bis_fnc_initFunctions_debugMode",0];
  71. _headerDefault = switch _debug do {
  72.  
  73.     //--- 0 - Debug mode off
  74.     default {
  75.         _headerNoDebug
  76.     };
  77.  
  78.     //--- 1 - Save script map (order of executed functions) to '_fnc_scriptMap' variable
  79.     case 1: {
  80.         _headerNoDebug + _headerSaveScriptMap
  81.     };
  82.  
  83.     //--- 2 - Save script map and log it
  84.     case 2: {
  85.         _headerNoDebug + _headerSaveScriptMap + _headerLogScriptMap
  86.     };
  87. };
  88.  
  89.  
  90. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  91. //--- Compile function
  92. _fncCompile = {
  93.     private ["_fncVar","_fncMeta","_fncPath","_fncHeader","_fncExt","_header","_debugMessage"];
  94.     _fncVar = _this select 0;
  95.     _fncMeta = _this select 1;
  96.     _fncHeader = _this select 2;
  97.     _fncFinal = _this select 3;
  98.  
  99.     _fncPath = _fncMeta select 0;
  100.     _fncExt = _fncMeta select 1;
  101.  
  102.     switch _fncExt do {
  103.  
  104.         //--- SQF
  105.         case ".sqf": {
  106.             _header = switch (_fncHeader) do {
  107.  
  108.                 //--- No header (used in low-level functions, like 'fired' event handlers for every weapon)
  109.                 case -1: {
  110.                     _headerNone
  111.                 };
  112.  
  113.                 //--- System functions' header (rewrite default header based on debug mode)
  114.                 case 1: {
  115.                     _headerSystem
  116.                 };
  117.  
  118.  
  119.                 //--- Full header
  120.                 default {
  121.                     _headerDefault
  122.                 }
  123.             };
  124.            
  125.             //--- Extend error report by including name of the function responsible
  126.             _debugHeaderExtended = format ["%4%1line 1 ""%2 [%3]""%4", "#", _fncPath, _fncVar, toString [13,10]];
  127.             _debugMessage = "Log: [Functions]%1 | %2";
  128.            
  129.             if (_fncFinal) then {
  130.                 compileFinal (format [_header, _fncVar, _debugMessage] + _debugHeaderExtended + preprocessFile _fncPath);
  131.             } else {
  132.                 compile (format [_header, _fncVar, _debugMessage] + _debugHeaderExtended + preprocessFile _fncPath);
  133.             };
  134.         };
  135.  
  136.         //--- FSM
  137.         case ".fsm": {
  138.             compileFinal format ["%1_fsm = _this execfsm '%2'; %1_fsm",_fncVar,_fncPath];
  139.         };
  140.  
  141.         default {0}
  142.     };
  143. };
  144.  
  145.  
  146. /******************************************************************************************************
  147.     COMPILE ONE FUNCTION
  148.  
  149.     When input is string containing function name instead of number, only the function is recompiled.
  150.  
  151.     The script stops here, reads function's meta data and recompile the function
  152.     based on its extension and header.
  153.  
  154.     Instead of creating missionNamespace shortcut, it saves the function directly. Use it only for debugging!
  155.  
  156. ******************************************************************************************************/
  157.  
  158. //--- Compile only selected
  159. if (isnil "_this") then {_this = [];};
  160. if (typename _this != typename []) then {_this = [_this];};
  161. _recompile = if (count _this > 0) then {_this select 0} else {0};
  162.  
  163. if (typename _recompile == typename "") exitwith {
  164.     private ["_fnc","_fncUINamespace","_fncMeta","_headerType","_var"];
  165.  
  166.     //--- Recompile specific function
  167.     _fncUINamespace = true;
  168.     _fnc = uinamespace getvariable _recompile;
  169.     if (isnil "_fnc") then {_fnc = missionnamespace getvariable _recompile; _fncUINamespace = false;};
  170.     if !(isnil "_fnc") then {
  171.         _fncMeta = _recompile call (uinamespace getvariable "bis_fnc_functionMeta");
  172.         _headerType = if (count _this > 1) then {_this select 1} else {0};
  173.         _var = [_recompile,[_recompile,_fncMeta,_headerType,false] call _fncCompile];
  174.         if (cheatsenabled && {_fncUINamespace}) then {uinamespace setvariable _var;}; //--- Cannot recompile compileFinal functions in public version
  175.         missionnamespace setvariable _var;
  176.         if (isnil "_functions_listRecompile") then {
  177.             textlogformat ["Log: [Functions]: %1 recompiled with meta %2",_recompile,_fncMeta];
  178.         };
  179.     } else {
  180.         _fncError = uinamespace getvariable "bis_fnc_error";
  181.         if !(isnil "_fncError") then {
  182.             ["%1 is not a function.",_recompile] call _fncError;
  183.         } else {
  184.             textlogformat ["Log: [Functions]: ERROR: %1 is not a function.",_recompile];
  185.         };
  186.     };
  187. };
  188.  
  189.  
  190. /******************************************************************************************************
  191.     COMPILE EVERYTHING IN GIVEN NAMESPACE(S)
  192.  
  193.     Function codes are present only in uiNamespace. Mission variables contains only shortcuts to uiNamespace.
  194.     To executed only required compilation section, input param can be one of following numbers:
  195.  
  196.     0 - Autodetect what compile type should be used
  197.     1 - Forced recompile of all the things
  198.     2 - Create only uiNamespace variables (used in UI)
  199.     3 - Create missionNamespace variables and initialize mission
  200.     4 - Create only missionNamespace variables
  201.     5 - Recompile all functions, and initialize mission (used for editor preview with function recompile)
  202.  
  203. ******************************************************************************************************/
  204.  
  205. RscDisplayLoading_progressMission = nil;
  206.  
  207. //--- Get existing lists (create new ones when they doesn't exist)
  208. private ["_functions_list","_functions_listPreInit","_functions_listPostInit","_functions_listPreStart","_functions_listRecompile","_file","_cfgSettings","_listConfigs","_recompileNames"];
  209.  
  210. _functions_listPreStart = [];
  211. _functions_list = call (uinamespace getvariable ["bis_functions_list",{[]}]);
  212. _functions_listPreInit = [call (uinamespace getvariable ["bis_functions_listPreInit",{[]}]),[]];
  213. _functions_listPostInit = [call (uinamespace getvariable ["bis_functions_listPostInit",{[]}]),[]];
  214. _functions_listRecompile = call (uinamespace getvariable ["bis_functions_listRecompile",{[]}]);
  215.  
  216. //--- When not forced, recompile only mission if uiNamespace functions exists
  217. if (typename _recompile != typename 1) then {
  218.     _recompile = if (count _functions_list > 0) then {3} else {0};
  219. };
  220.  
  221. //--- When autodetect, recognize what recompile type is required
  222. if (_recompile == 0 && !isnil {uinamespace getvariable "bis_fnc_init"}) then {_recompile = 3;};
  223. if (_recompile == 3 && !isnil {missionnamespace getvariable "bis_fnc_init"}) then {_recompile = 4;};
  224. if (_recompile == 3 && !is3DEN && ("Preferences" get3DENMissionAttribute "RecompileFunctions")) then {_recompile = 5;};
  225.  
  226. _file = gettext (configfile >> "cfgFunctions" >> "file");
  227. _cfgSettings = [
  228.     [   configfile,     _file,      0   ]//--- 0
  229.     [   campaignconfigfile, "functions",    1   ]//--- 1
  230.     [   missionconfigfile"functions",    1   ]   //--- 2
  231. ];
  232.  
  233. _listConfigs = switch _recompile do {
  234.     case 0: {
  235.         [0,1,2];
  236.     };
  237.     case 5;
  238.     case 1: {
  239.         _functions_list = [];
  240.         uinamespace setvariable ["bis_functions_list",_functions_list];
  241.         _functions_listPreInit = [[],[]];
  242.         uinamespace setvariable ["bis_functions_listPreInit",_functions_listPreInit];
  243.         _functions_listPostInit = [[],[]];
  244.         uinamespace setvariable ["bis_functions_listPostInit",_functions_listPostInit];
  245.         _functions_listRecompile = [];
  246.         uinamespace setvariable ["bis_functions_listRecompile",_functions_listRecompile];
  247.         [0,1,2];
  248.     };
  249.     case 2: {
  250.         [0];
  251.     };
  252.     case 3: {
  253.         [1,2];
  254.     };
  255.     case 4: {
  256.         [1,2];
  257.     };
  258. };
  259.  
  260.  
  261. /******************************************************************************************************
  262.     SCAN CFGFUNCTIONS
  263.  
  264.     Go through CfgFunctions, scan categories and declare all functions.
  265.  
  266.     Following variables are stored:
  267.     <tag>_fnc_<functionName> - actual code of the function
  268.     <tag>_fnc_<functionName>_meta - additional meta data of this format
  269.         [<path>,<extension>,<header>,<preInit>,<postInit>,<recompile>,<category>]
  270.         * path - path to actual file
  271.         * extension - file extension, either ".sqf" or ".fsm"
  272.         * header - header type. Usually 0, system functions are using 1 (see DEFINE HEADERS section)
  273.         * preInit - function is executed automatically upon mission start, before objects are initalized
  274.         * postInit - function is executed automatically upon mission start, after objects are initialized
  275.         * recompile - function is recompiled upon mission start
  276.         * category - function's category based on config structure
  277.  
  278. ******************************************************************************************************/
  279.  
  280. //--- Allow recompile in dev version, in the editor and when description.ext contains 'allowFunctionsRecompile = 1;'
  281. _compileFinal =
  282.     //--- Dev version
  283.     !cheatsEnabled
  284.     &&
  285.     //--- Editor mission
  286.     ((uinamespace getvariable ["gui_displays",[]]) find (finddisplay 26) != 1)
  287.     &&
  288.     //--- Manual toggle
  289.     getnumber (missionconfigfile >> "allowFunctionsRecompile") == 0;
  290.  
  291. for "_t" from 0 to (count _listConfigs - 1) do {
  292.     private ["_cfg","_pathConfig","_pathFile","_pathAccess","_cfgFunctions"];
  293.     _cfg = _cfgSettings select (_listConfigs select _t);
  294.     _pathConfig = _cfg select 0;
  295.     _pathFile = _cfg select 1;
  296.     _pathAccess = _cfg select 2;
  297.  
  298.     _cfgFunctions = (_pathConfig >> "cfgfunctions");
  299.     for "_c" from 0 to (count _cfgFunctions - 1) do {
  300.         private ["_currentTag"];
  301.         _currentTag = _cfgFunctions select _c;
  302.  
  303.         //--- Is Tag
  304.         if (isclass _currentTag) then {
  305.  
  306.             //--- Check of all required patches are in CfgPatches
  307.             private ["_requiredAddons","_requiredAddonsMet"];
  308.             _requiredAddons = getarray (_currentTag >> "requiredAddons");
  309.             _requiredAddonsMet = true;
  310.             {
  311.                 _requiredAddonsMet = _requiredAddonsMet && isclass (configfile >> "CfgPatches" >> _x);
  312.             } foreach _requiredAddons;
  313.  
  314.             if (_requiredAddonsMet) then {
  315.  
  316.                 //--- Initialize tag
  317.                 private ["_tag","_tagName","_itemPathRag"];
  318.                 _tag = configname _currentTag;
  319.                 _tagName = gettext (_currentTag >> "tag");
  320.                 if (_tagName == "") then {_tagName = configname _currentTag};
  321.                 _itemPathTag = gettext (_currentTag >> "file");
  322.  
  323.                 for "_i" from 0 to (count _currentTag - 1) do {
  324.                     private ["_currentCategory"];
  325.                     _currentCategory = _currentTag select _i;
  326.  
  327.                     //--- Is Category
  328.                     if (isclass _currentCategory) then {
  329.                         private ["_categoryName","_itemPathCat"];
  330.                         _categoryName = configname _currentCategory;
  331.                         _itemPathCat = gettext (_currentCategory >> "file");
  332.  
  333.                         for "_n" from 0 to (count _currentCategory - 1) do {
  334.                             private ["_currentItem"];
  335.                             _currentItem = _currentCategory select _n;
  336.  
  337.                             //--- Is Item
  338.                             if (isclass _currentItem) then {
  339.                                 private ["_itemName","_itemPathItem","_itemExt","_itemPath","_itemVar","_itemCompile","_itemPreInit","_itemPostInit","_itemPreStart","_itemRecompile","_itemCheatsEnabled"];
  340.  
  341.                                 //--- Read function
  342.                                 _itemName = configname _currentItem;
  343.                                 _itemPathItem = gettext (_currentItem >> "file");
  344.                                 _itemExt = gettext (_currentItem >> "ext");
  345.                                 _itemPreInit = getnumber (_currentItem >> "preInit");
  346.                                 _itemPostInit = getnumber (_currentItem >> "postInit");
  347.                                 _itemPreStart = getnumber (_currentItem >> "preStart");
  348.                                 _itemRecompile = getnumber (_currentItem >> "recompile");
  349.                                 _itemCheatsEnabled = getnumber (_currentItem >> "cheatsEnabled");
  350.                                 if (_itemExt == "") then {_itemExt = ".sqf"};
  351.                                 _itemPath = if (_itemPathItem != "") then {
  352.                                     if (_tagName == "BIS" && _pathAccess == 0) then {
  353.                                         //--- Disable rewriting of global BIS functions from outside (ToDo: Make it dynamic, so anyone can protect their functions)
  354.                                         private ["_itemPathItemA3","_itemPathSlash"];
  355.                                         _itemPathItemA3 = (tolower _itemPathItem) find "a3";
  356.                                         _itemPathSlash = (tolower _itemPathItem) find "\";
  357.                                         if ((_itemPathItemA3 < 0 || _itemPathItemA3 > 1) && _itemPathSlash > 0) then {_itemPathItem = "";};
  358.                                     };
  359.                                     _itemPathItem
  360.                                 } else {
  361.                                     ""
  362.                                 };
  363.                                 if (_itemPath == "") then {
  364.                                     _itemPath = if (_itemPathCat != "") then {_itemPathCat + "\fn_" + _itemName + _itemExt} else {
  365.                                         if (_itemPathTag != "") then {_itemPathTag + "\fn_" + _itemName + _itemExt} else {""};
  366.                                     };
  367.                                 };
  368.                                 _itemHeader = getnumber (_currentItem >> "span class="re5"> headerType");
  369.  
  370.                                 //--- Compile function
  371.                                 if (_itemPath == "") then {_itemPath = _pathFile + "\" + _categoryName + "\fn_" + _itemName + _itemExt};
  372.                                 _itemVar = _tagName + "_fnc_" + _itemName;
  373.                                 _itemMeta = [_itemPath,_itemExt,_itemHeader,_itemPreInit > 0,_itemPostInit > 0,_itemRecompile> 0,_tag,_categoryName,_itemName];
  374.                                 _itemCompile = if (_itemCheatsEnabled == 0 || (_itemCheatsEnabled > 0 && cheatsEnabled)) then {
  375.                                     [_itemVar,_itemMeta,_itemHeader,_compileFinal] call _fncCompile;
  376.                                 } else {
  377.                                     compilefinal "false" //--- Function not available in retail version
  378.                                 };
  379.  
  380.                                 //--- Register function
  381.                                 if (typename _itemCompile == typename {}) then {
  382.                                     if !(_itemVar in _functions_list) then {
  383.                                         private ["_namespaces"];
  384.                                         _namespaces = if (_pathAccess == 0) then {[uinamespace]} else {[missionnamespace]};
  385.                                         {
  386.                                             //---- Save function
  387.                                             _x setvariable [
  388.                                                 _itemVar,
  389.                                                 _itemCompile
  390.                                             ];
  391.                                             //--- Save function meta data
  392.                                             _x setvariable [
  393.                                                 _itemVar + "_meta",
  394.                                                 compileFinal str _itemMeta
  395.                                             ];
  396.                                         } foreach _namespaces;
  397.                                         if (_pathAccess == 0) then {_functions_list set [count _functions_list,_itemVar];};
  398.                                     };
  399.  
  400.                                     //--- Add to list of functions executed upon mission start
  401.                                     if (_itemPreInit > 0) then {
  402.                                         _functions_listPreInitAccess = _functions_listPreInit select _pathAccess;
  403.                                         if !(_itemVar in _functions_listPreInitAccess) then {
  404.                                             _functions_listPreInitAccess set [count _functions_listPreInitAccess,_itemVar];
  405.                                         };
  406.                                     };
  407.                                     if (_itemPostInit > 0) then {
  408.                                         _functions_listPostInitAccess = _functions_listPostInit select _pathAccess;
  409.                                         if !(_itemVar in _functions_listPostInitAccess) then {
  410.                                             _functions_listPostInitAccess set [count _functions_listPostInitAccess,_itemVar];
  411.                                         };
  412.                                     };
  413.  
  414.                                     //--- Add to list of functions executed upon game start
  415.                                     if (_itemPreStart > 0) then {
  416.                                         if (_pathAccess == 0) then {
  417.                                             if !(_itemVar in _functions_listPreStart) then {
  418.                                                 _functions_listPreStart set [count _functions_listPreStart,_itemVar];
  419.                                             };
  420.                                         } else {
  421.                                             _errorFnc = uinamespace getvariable "span class="re5"> bis_fnc_error";
  422.                                             _errorText = "%1 is a mission / campaign function and cannot contain 'preStart = 1;' param";
  423.                                             if !(isnil {_errorFnc}) then {[_errorText,_itemVar] call _errorFnc;} else {diag_log format ["Log: [Functions]: " + _errorText,_itemVar];};
  424.                                         };
  425.                                     };
  426.  
  427.                                     //--- Add to list of functions recompiled upon mission start
  428.                                     if (_itemRecompile > 0) then {
  429.                                         if (_pathAccess == 0) then {
  430.                                             if !(_itemVar in _functions_listRecompile) then {
  431.                                                 _functions_listRecompile set [count _functions_listRecompile,_itemVar];
  432.                                             };
  433.                                         } else {
  434.                                             _errorFnc = uinamespace getvariable "span class="re5"> bis_fnc_error";
  435.                                             _errorText = "span class="re5"> Redundant use of 'recompile = 1;' in %1 - mission / campaign functions are recompiled on start by default.";
  436.                                             if !(isnil {_errorFnc}) then {[_errorText,_itemVar] call _errorFnc;} else {diag_log format ["Log: [Functions]: " + _errorText,_itemVar];};
  437.                                         };
  438.                                     };
  439.  
  440.                                     //if (_itemRecompile > 0) then {
  441.                                     //  _functions_listRecompileAccess = _functions_listRecompile select _pathAccess;
  442.                                     //  _functions_listRecompileAccess set [count _functions_listRecompileAccess,_itemVar];
  443.                                     //};
  444.                                     //--- Debug
  445.                                     //debuglog ["Log:::::::::::::::::::Function",_itemVar,_itemPath,_pathAccess];
  446.                                 };
  447.                             };
  448.                         };
  449.                     };
  450.                 };
  451.             };
  452.         };
  453.     };
  454. };
  455.  
  456. //--- Save the lists (only when they're undefined, or in dev version where compileFinal variables can be rewritten)
  457. if (isnil {uinamespace getvariable "span class="re5"> BIS_functions_list"} || {cheatsenabled}) then {
  458.     uinamespace setvariable ["span class="re5"> BIS_functions_list",compileFinal str (_functions_list)];
  459.     uinamespace setvariable ["span class="re5"> BIS_functions_listPreInit",compileFinal str (_functions_listPreInit select 0)];
  460.     uinamespace setvariable ["span class="re5"> BIS_functions_listPostInit",compileFinal str (_functions_listPostInit select 0)];
  461.     uinamespace setvariable ["span class="re5"> BIS_functions_listRecompile",compileFinal str (_functions_listRecompile)];
  462. };
  463.  
  464. /******************************************************************************************************
  465.     FINISH
  466.  
  467.     When functions are saved, following operations are executed:
  468.     1. MissionNamespace shortcuts are created
  469.     2. Functions with 'recompile' param set to 1 are recompiled
  470.     3. Functions with 'preInit' param set to 1 are executed
  471.     4. Multiplayer framework is initialized
  472.     5. Modules are initialized (running their own scripts, functions just wait until those scripts are ready)
  473.     6. Automatic scripts "span class="re5"> initServer.sqf", "span class="re5"> initPlayerServer.sqf" and "span class="re5"> initPlayerLocal.sqf" are executed
  474.     7. Functions with 'postInit' param set to 1 are executed
  475.  
  476.     When done, system will set 'bis_fnc_init' to true so other systems can catch it.
  477.  
  478. ******************************************************************************************************/
  479.  
  480. //--- Not core
  481. if (_recompile in [0,1,3,4,5]) then {
  482.     {
  483.         _allowRecompile = (_x call (uinamespace getvariable "span class="re5"> bis_fnc_functionMeta")) select 5;
  484.  
  485.         _xCode = uinamespace getvariable _x;
  486.         if (_allowRecompile || !_compileFinal) then {
  487.             _xCode = call compile str (uinamespace getvariable _x);
  488.         };
  489.         missionnamespace setvariable [_x,_xCode];
  490.     } foreach (_functions_list - _functions_listRecompile); //--- Exclude functions marker for recompile to avoid double-compile
  491. };
  492.  
  493. //--- Core only
  494. if (_recompile == 2) then {
  495.     //--- Call preStart functions
  496.     if (isnull (finddisplay 0)) then {
  497.         {
  498.             ["span class="re5"> preStart %1",_x] call bis_fnc_logFormat;
  499.             _function = [] call (uinamespace getvariable _x);
  500.             uinamespace setvariable [_x + "_preStart",_function];
  501.         } foreach _functions_listPreStart;
  502.     };
  503. };
  504.  
  505. //--- Mission only
  506. if (_recompile in [3,5]) then {
  507.  
  508.     //--- Switch to mission loading bar
  509.     RscDisplayLoading_progressMission = true;
  510.  
  511.     //--- Execute script preload
  512.     [] call bis_fnc_preload;
  513.  
  514.     //--- Create functions logic (cannot be created when game is launching; server only)
  515.     if (isserver && isnull (missionnamespace getvariable ["span class="re5"> bis_functions_mainscope",objnull]) && !isnil {uinamespace getvariable "span class="re5"> bis_fnc_init"} && worldname != "") then {
  516.         private ["_grpLogic"];
  517.         createcenter sidelogic;
  518.         _grpLogic = creategroup sidelogic;
  519.         bis_functions_mainscope = _grpLogic createunit ["span class="re5"> Logic",[9,9,9],[],0,"span class="re5"> none"];
  520.         bis_functions_mainscope setvariable ["isDedicated",isDedicated,true];
  521.        
  522.         //--- Support for netId in SP (used in BIS_fnc_netId, BIS_fnc_objectFromNetId, BIS_fnc_groupFromNetId)
  523.         //--- Format [netId1,grpOrObj1,netId2,grpOrObj2,...]
  524.         if (!isMultiplayer) then {bis_functions_mainscope setVariable ["span class="re5"> BIS_fnc_netId_globIDs_SP", []]};
  525.        
  526.         publicvariable "span class="re5"> bis_functions_mainscope";
  527.     };
  528.     (group bis_functions_mainscope) setgroupid [localize "span class="re5"> str_dn_modules"]; //--- Name the group for curator
  529.  
  530.     if (!isNil "span class="re5"> bis_functions_mainscope") then {
  531.         private ["_test", "_test2"];
  532.         _test = bis_functions_mainscope setPos (position bis_functions_mainscope); if (isnil "_test") then {_test = false};
  533.         _test2 = bis_functions_mainscope playMove ""; if (isnil "_test2") then {_test2 = false};
  534.         if (_test || _test2) then {0 call (compile (preprocessFileLineNumbers "span class="re5"> a3\functions_f\misc\fn_initCounter.sqf"))};
  535.     };
  536.    
  537.     //--- Recompile selected functions
  538.     if (!is3DEN) then
  539.     {
  540.         _fnc_scriptname = "span class="re5"> recompile";
  541.         {
  542.             ["span class="re5"> recompile %1",_x] call bis_fnc_logFormat;
  543.             _x call bis_fnc_recompile;
  544.         } foreach _functions_listRecompile;
  545.  
  546.         //--- Call preInit functions
  547.         _fnc_scriptname = "span class="re5"> preInit";
  548.         {
  549.             {
  550.                 _time = diag_ticktime;
  551.                 [_x]call {
  552.                     private ["_recompile","_functions_list","_functions_listPreInit","_functions_listPostInit","_functions_listRecompile","_time"];
  553.                     ["span class="re5"> preInit"] call (missionnamespace getvariable (_this select 0))
  554.                 };
  555.                 ["%1 (%2 ms)",_x,(diag_ticktime - _time) * 1000] call bis_fnc_logFormat;
  556.             } foreach _x;
  557.         } foreach _functions_listPreInit;
  558.     };
  559.  
  560.     //--- Call postInit functions once player is present
  561.     _functions_listPostInit spawn
  562.     {
  563.         _fnc_scriptName = "span class="re5"> script";
  564.         0.15 call bis_fnc_progressloadingscreen;
  565.  
  566.         //--- Wait until server is initialized (to avoid running scripts before the server)
  567.         waituntil {call (missionnamespace getvariable ["span class="re5"> BIS_fnc_preload_server",{isserver}]) || getClientState == "span class="re5"> LOGGED IN"};
  568.         if (getClientState == "span class="re5"> LOGGED IN") exitwith {}; //--- Server lost
  569.         0.30 call bis_fnc_progressloadingscreen;
  570.  
  571.         //--- After JIP, units cannot be initialized during the loading screen
  572.         if !(isserver) then
  573.         {
  574.             endloadingscreen;
  575.             waituntil{!isnull cameraon && {getClientState != "span class="re5"> MISSION RECEIVED" && {getClientState != "span class="re5"> GAME LOADED"}}};
  576.  
  577.             ["span class="re5"> bis_fnc_initFunctions"] call bis_fnc_startLoadingScreen;
  578.         };
  579.         if (isnil "span class="re5"> bis_functions_mainscope") exitwith {endloadingscreen; ["[x] Error while loading the mission!"] call bis_fnc_errorMsg;}; //--- Error while loading
  580.         bis_functions_mainscope setvariable ["span class="re5"> didJIP",didJIP];
  581.         0.45 call bis_fnc_progressloadingscreen;
  582.  
  583.         //wait for functions mainscope to get initialized (overruled by escape condition at line: 577)
  584.         //waituntil {!isnil "span class="re5"> bis_functions_mainscope" && {!isnull bis_functions_mainscope}};
  585.         0.60 call bis_fnc_progressloadingscreen;
  586.  
  587.         //--- Wait until module inits are initialized
  588.         [] call bis_fnc_initModules;
  589.         0.75 call bis_fnc_progressloadingscreen;
  590.  
  591.         //--- Execute automatic scripts
  592.         if (!is3DEN) then
  593.         {
  594.             if (isserver) then {
  595.                 [] execvm "span class="re5"> initServer.sqf";
  596.                 "span class="re5"> initServer.sqf" call bis_fnc_logFormat;
  597.             };
  598.  
  599.             //--- Run mission scripts
  600.             if !(isDedicated) then {
  601.                 [player,didJIP] execvm "span class="re5"> initPlayerLocal.sqf";
  602.                 [[[player,didJIP],"span class="re5"> initPlayerServer.sqf"],"span class="re5"> bis_fnc_execvm",false,false] call bis_fnc_mp;
  603.                 "span class="re5"> initPlayerLocal.sqf" call bis_fnc_logFormat;
  604.                 "span class="re5"> initPlayerServer.sqf" call bis_fnc_logFormat;
  605.             };
  606.             0.90 call bis_fnc_progressloadingscreen;
  607.  
  608.             //--- Call postInit functions
  609.             _fnc_scriptname = "span class="re5"> postInit";
  610.             {
  611.                 {
  612.                     _time = diag_ticktime;
  613.                     [_x,didJIP] call {
  614.                         private ["_didJIP","_time"];
  615.                         ["span class="re5"> postInit",_this select 1] call (missionnamespace getvariable (_this select 0))
  616.                     };
  617.                     ["%1 (%2 ms)",_x,(diag_ticktime - _time) * 1000] call bis_fnc_logFormat;
  618.                 } foreach _x;
  619.             } foreach _this;
  620.             1.0 call bis_fnc_progressloadingscreen;
  621.         };
  622.  
  623.         //--- MissionNamespace init
  624.         missionnamespace setvariable ["span class="re5"> bis_fnc_init",true];
  625.  
  626.         if !(isserver) then
  627.         {
  628.             ["span class="re5"> bis_fnc_initFunctions"] call bis_fnc_endLoadingScreen;
  629.         };
  630.     };
  631. };
  632.  
  633. //--- Not mission
  634. if (_recompile in [0,1,2]) then {
  635.  
  636.     //--- UInameSpace init
  637.     uinamespace setvariable ["span class="re5"> bis_fnc_init",true]
  638. };
  639.  
  640. //--- Only mission variables
  641. if (_recompile in [4]) then {
  642.  
  643.     //--- MissionNameSpace init
  644.     missionnamespace setvariable ["span class="re5"> bis_fnc_init",true];
  645. };
  646.  
  647. //--- Only mission variables
  648. if (_recompile in [1,5]) then {
  649.     _fnc_scriptname = "span class="re5"> initFunctions";
  650.     "span class="re5"> Functions recompiled" call bis_fnc_log;
  651. };
  652.  
  653. //--- Log the info about selected recompile type
  654. _recompileNames = [
  655.     "span class="re5"> ERROR: Autodetect failed",
  656.     "span class="re5"> Forced",
  657.     "span class="re5"> Core Only",
  658.     "span class="re5"> Mission/Campaign Only"
  659. ];
  660. //["span class="re5"> Initialized: %1.",_recompileNames select _recompile] call (uinamespace getvariable "span class="re5"> bis_fnc_logFormat");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement