Move the litter cleanup PFH to a loop using waitAndExecute

This commit is contained in:
esteldunedain 2016-02-28 23:20:26 -03:00
parent 4b702f68df
commit 90a54397ae
3 changed files with 36 additions and 17 deletions

View File

@ -117,3 +117,4 @@ PREP(unconsciousPFH);
// Networked litter
PREP(createLitter);
PREP(handleCreateLitter);
PREP(litterCleanupLoop);

View File

@ -44,22 +44,7 @@ if((count GVAR(allCreatedLitter)) > _maxLitterCount ) then {
GVAR(allCreatedLitter) pushBack [ACE_time, [_litterObject]];
if(!GVAR(litterPFHRunning) && {GVAR(litterCleanUpDelay) > 0}) then {
// Start the litter cleanup loop
GVAR(litterPFHRunning) = true;
[{
{
_x params ["_time", "_objects"];
if (ACE_time - _time >= GVAR(litterCleanUpDelay)) then {
{
deleteVehicle _x;
} forEach _objects;
GVAR(allCreatedLitter) set[_forEachIndex, objNull];
};
} forEach GVAR(allCreatedLitter);
GVAR(allCreatedLitter) = GVAR(allCreatedLitter) - [objNull];
if ( (count GVAR(allCreatedLitter)) == 0) exitWith {
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
GVAR(litterPFHRunning) = false;
};
}, 30, []] call CBA_fnc_addPerFrameHandler;
call FUNC(litterCleanupLoop);
};

View File

@ -0,0 +1,33 @@
/*
* Author: Glowbal, esteldunedain
* Loop that cleans up litter
*
* Arguments:
* None
*
* ReturnValue:
* None
*
* Public: No
*/
#include "script_component.hpp"
{
_x params ["_time", "_objects"];
if (ACE_time - _time >= GVAR(litterCleanUpDelay)) then {
{
deleteVehicle _x;
} forEach _objects;
GVAR(allCreatedLitter) set[_forEachIndex, objNull];
};
} forEach GVAR(allCreatedLitter);
GVAR(allCreatedLitter) = GVAR(allCreatedLitter) - [objNull];
// If no more litter remaining, exit the loop
if ( (count GVAR(allCreatedLitter)) == 0) exitWith {
GVAR(litterPFHRunning) = false;
};
// Schedule the loop to be executed again 30 sec later
[DFUNC(litterCleanupLoop), [], 30] call EFUNC(common,waitAndExecute);