From 3e396b416aed584cf3c00e1dc65009eab009fa4e Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 11 Jun 2015 02:45:42 -0500 Subject: [PATCH] One PFEH for execNextFrame and waitAndExec --- addons/common/XEH_postInit.sqf | 21 +++++++++++++++++ addons/common/XEH_preInit.sqf | 5 ++++ addons/common/functions/fnc_execNextFrame.sqf | 23 ++++--------------- .../common/functions/fnc_waitAndExecute.sqf | 13 ----------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index eb015a6264..97cddb84a3 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -3,6 +3,27 @@ //IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent"); +//Singe PFEH to handle execNextFrame and waitAndExec: +[{ + private ["_entry"]; + + //Handle the waitAndExec array: + while {((count GVAR(waitAndExecArray)) > 0) && {((GVAR(waitAndExecArray) select 0) select 0) <= ACE_Time}} do { + _entry = GVAR(waitAndExecArray) deleteAt 0; + (_entry select 2) call (_entry select 1); + }; + + //Handle the execNextFrame array: + { + (_x select 0) call (_x select 1); + } forEach GVAR(nextFrameBufferA); + //Swap double-buffer: + GVAR(nextFrameBufferA) = GVAR(nextFrameBufferB); + GVAR(nextFrameBufferB) = []; + GVAR(nextFrameNo) = diag_frameno + 1; +}, 0, []] call CBA_fnc_addPerFrameHandler; + + // Listens for global "SettingChanged" events, to update the force status locally ["SettingChanged", { PARAMS_2(_name,_value); diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 4d93705898..d16f4878be 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -287,7 +287,12 @@ PREP(_handleRequestSyncedEvent); PREP(_handleRequestAllSyncedEvents); GVAR(syncedEvents) = HASH_CREATE; + +//GVARS for execNextFrame and waitAndExec GVAR(waitAndExecArray) = []; +GVAR(nextFrameNo) = diag_frameno; +GVAR(nextFrameBufferA) = []; +GVAR(nextFrameBufferB) = []; // @TODO: Generic local-managed global-synced objects (createVehicleLocal) diff --git a/addons/common/functions/fnc_execNextFrame.sqf b/addons/common/functions/fnc_execNextFrame.sqf index 39fef16519..ddd36be073 100644 --- a/addons/common/functions/fnc_execNextFrame.sqf +++ b/addons/common/functions/fnc_execNextFrame.sqf @@ -14,21 +14,8 @@ PARAMS_2(_func,_params); -[ - { - EXPLODE_2_PVT(_this,_params,_pfhId); - EXPLODE_2_PVT(_params,_delayedExecParams,_startFrame); - EXPLODE_2_PVT(_delayedExecParams,_func,_funcParams); - - // Exit if we are still on the same frame - if (diag_frameno == _startFrame) exitWith {}; - - // Remove the PFH - [_pfhId] call cba_fnc_removePerFrameHandler; - - // Execute the function - _funcParams call _func; - }, - 0, - [_this, diag_frameno] -] call CBA_fnc_addPerFrameHandler +if (diag_frameno != GVAR(nextFrameNo)) then { + GVAR(nextFrameBufferA) pushBack [_params, _func]; +} else { + GVAR(nextFrameBufferB) pushBack [_params, _func]; +}; diff --git a/addons/common/functions/fnc_waitAndExecute.sqf b/addons/common/functions/fnc_waitAndExecute.sqf index f7318ac1c8..977e4f146d 100644 --- a/addons/common/functions/fnc_waitAndExecute.sqf +++ b/addons/common/functions/fnc_waitAndExecute.sqf @@ -22,16 +22,3 @@ PARAMS_3(_func,_params,_delay); GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params]; GVAR(waitAndExecArray) sort true; - -if ((count GVAR(waitAndExecArray)) == 1) then { - [{ - while {((count GVAR(waitAndExecArray)) > 0) && {((GVAR(waitAndExecArray) select 0) select 0) <= ACE_Time}} do { - private ["_entry"]; - _entry = GVAR(waitAndExecArray) deleteAt 0; - (_entry select 2) call (_entry select 1); - }; - if ((count GVAR(waitAndExecArray)) == 0) then { - [(_this select 1)] call cba_fnc_removePerFrameHandler; - }; - }, 0, []] call CBA_fnc_addPerFrameHandler; -};