runAfterSettingsInit helper func

This commit is contained in:
PabstMirror 2015-09-03 00:11:49 -05:00
parent cbccd898ea
commit 789de9d111
3 changed files with 31 additions and 3 deletions

View File

@ -152,10 +152,10 @@ call FUNC(checkFiles);
//Set init finished and run all delayed functions:
GVAR(settingsInitFinished) = true;
diag_log text format ["%1 delayed functions", (count GVAR(runAtSettingsInitialized))];
diag_log text format ["[ACE] %1 delayed functions running", (count GVAR(runAtSettingsInitialized))];
{
_x params ["_args", "_code"];
_args call _code;
_x params ["_func", "_params"];
_params call _func;
} forEach GVAR(runAtSettingsInitialized);
}, 0, [false]] call CBA_fnc_addPerFrameHandler;

View File

@ -157,6 +157,7 @@ PREP(requestCallback);
PREP(resetAllDefaults);
PREP(restoreVariablesJIP);
PREP(revertKeyCodeLocalized);
PREP(runAfterSettingsInit);
PREP(sanitizeString);
PREP(sendRequest);
PREP(serverLog);

View File

@ -0,0 +1,27 @@
/*
* Author: PabstMirror
* Executes code after setting are initilized.
*
* Argument:
* 0: Code to execute <CODE>
* 1: Parameters to run the code with <ANY>
*
* Return value:
* None
*
* Example:
* [{if (GVAR(setting) then {x} else {y};}, []] call ace_common_fnc_runAfterSettingsInit
*
* Public: No
*/
#include "script_component.hpp"
params ["_func", "_params"];
if (GVAR(settingsInitFinished)) then {
//Setting Already Finished, Direct Run the code
_params call _func;
} else {
//Waiting on settings, throw it on the delayed run array
GVAR(runAtSettingsInitialized) pushBack [_func, _params];
};