Merge pull request #1394 from acemod/sortWaitAndExecute

Single PFEH for waitAndExecute - using sort
This commit is contained in:
Nicolás Badano 2015-05-26 16:40:17 -03:00
commit 32325fc784
2 changed files with 22 additions and 20 deletions

View File

@ -286,6 +286,7 @@ PREP(_handleRequestSyncedEvent);
PREP(_handleRequestAllSyncedEvents); PREP(_handleRequestAllSyncedEvents);
GVAR(syncedEvents) = HASH_CREATE; GVAR(syncedEvents) = HASH_CREATE;
GVAR(waitAndExecArray) = [];
// @TODO: Generic local-managed global-synced objects (createVehicleLocal) // @TODO: Generic local-managed global-synced objects (createVehicleLocal)

View File

@ -7,30 +7,31 @@
* 0: Code to execute (Code) * 0: Code to execute (Code)
* 1: Parameters to run the code with (Array) * 1: Parameters to run the code with (Array)
* 2: Delay in seconds before executing the code (Number) * 2: Delay in seconds before executing the code (Number)
* 3: Interval of ACE_time in which the execution is evaluated, 0 means every frame (Number)
* *
* Return value: * Return value:
* PFH handler ID * None
*
* Example:
* [{(_this select 0) setVelocity [0,0,200];}, [player], 10] call ace_common_fnc_waitAndExecute
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
PARAMS_4(_func,_params,_delay,_interval); PARAMS_3(_func,_params,_delay);
[ GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params];
{ GVAR(waitAndExecArray) sort true;
EXPLODE_2_PVT(_this,_params,_pfhId);
EXPLODE_2_PVT(_params,_delayedExecParams,_startTime);
EXPLODE_3_PVT(_delayedExecParams,_func,_funcParams,_delay);
// Exit if the ACE_time was not reached yet if ((count GVAR(waitAndExecArray)) == 1) then {
if (ACE_time < _startTime + _delay) exitWith {}; [{
while {((count GVAR(waitAndExecArray)) > 0) && {((GVAR(waitAndExecArray) select 0) select 0) <= ACE_Time}} do {
// Remove the PFH private ["_entry"];
[_pfhId] call cba_fnc_removePerFrameHandler; _entry = GVAR(waitAndExecArray) deleteAt 0;
(_entry select 2) call (_entry select 1);
// Execute the function };
_funcParams call _func; if ((count GVAR(waitAndExecArray)) == 0) then {
}, [(_this select 1)] call cba_fnc_removePerFrameHandler;
_interval, };
[_this, ACE_time] }, 0, []] call CBA_fnc_addPerFrameHandler;
] call CBA_fnc_addPerFrameHandler };