Merge pull request #2355 from acemod/settingInitDelayFunctions

Setting init delay functions
This commit is contained in:
Glowbal 2015-09-05 11:01:44 +02:00
commit a02f95ae06
3 changed files with 41 additions and 1 deletions

View File

@ -150,6 +150,15 @@ call FUNC(checkFiles);
//Event that settings are safe to use:
["SettingsInitialized", []] call FUNC(localEvent);
//Set init finished and run all delayed functions:
GVAR(settingsInitFinished) = true;
diag_log text format ["[ACE] %1 delayed functions running", (count GVAR(runAtSettingsInitialized))];
{
_x params ["_func", "_params"];
_params call _func;
} forEach GVAR(runAtSettingsInitialized);
GVAR(runAtSettingsInitialized) = nil; //cleanup
}, 0, [false]] call CBA_fnc_addPerFrameHandler;
@ -326,7 +335,7 @@ GVAR(OldIsCamera) = false;
if (didJip) then {
// We are jipping! Get ready and wait, and throw the event
[{
if(!(isNull player)) then {
if((!(isNull player)) && GVAR(settingsInitFinished)) then {
["PlayerJip", [player] ] call FUNC(localEvent);
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};

View File

@ -157,6 +157,7 @@ PREP(requestCallback);
PREP(resetAllDefaults);
PREP(restoreVariablesJIP);
PREP(revertKeyCodeLocalized);
PREP(runAfterSettingsInit);
PREP(sanitizeString);
PREP(sendRequest);
PREP(serverLog);
@ -303,6 +304,9 @@ GVAR(nextFrameNo) = diag_frameno;
GVAR(nextFrameBufferA) = [];
GVAR(nextFrameBufferB) = [];
GVAR(settingsInitFinished) = false;
GVAR(runAtSettingsInitialized) = [];
// @TODO: Generic local-managed global-synced objects (createVehicleLocal)
//Debug

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];
};