From 9e682253f39f1e369f2163cd8912b95c3f71e4af Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sun, 28 Feb 2016 23:33:51 -0300 Subject: [PATCH] Move the dead body cleanup PFH to a loop using waitAndExecute --- addons/medical/XEH_PREP.hpp | 1 + .../medical/functions/fnc_bodyCleanupLoop.sqf | 30 +++++++++++++++++++ .../functions/fnc_serverRemoveBody.sqf | 20 ++----------- 3 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 addons/medical/functions/fnc_bodyCleanupLoop.sqf diff --git a/addons/medical/XEH_PREP.hpp b/addons/medical/XEH_PREP.hpp index 7c030ecf98..d7322082c6 100644 --- a/addons/medical/XEH_PREP.hpp +++ b/addons/medical/XEH_PREP.hpp @@ -18,6 +18,7 @@ PREP(addUnconsciousCondition); PREP(addUnloadPatientActions); PREP(addVitalLoop); PREP(adjustPainLevel); +PREP(bodyCleanupLoop); PREP(canAccessMedicalEquipment); PREP(canTreat); PREP(canTreatCached); diff --git a/addons/medical/functions/fnc_bodyCleanupLoop.sqf b/addons/medical/functions/fnc_bodyCleanupLoop.sqf new file mode 100644 index 0000000000..03c1234713 --- /dev/null +++ b/addons/medical/functions/fnc_bodyCleanupLoop.sqf @@ -0,0 +1,30 @@ +/* + * Author: Glowbal, esteldunedain + * Loop that cleans up litter + * + * Arguments: + * None + * + * ReturnValue: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +{ + TRACE_2("body",_x,isPlayer _x); + if ((!isNull _x) && {!isPlayer _x}) then {deleteVehicle _x}; +} forEach GVAR(bodiesToDelete); + +// deleteVehicle doesn't have instant results so it won't usualy be filtered until next run +GVAR(bodiesToDelete) = GVAR(bodiesToDelete) - [objNull]; + +// If no more bodies remain, exit the loop +if (GVAR(bodiesToDelete) isEqualTo []) exitWith { + TRACE_1("array emptied - rem PFEH",GVAR(bodiesToDelete)); +}; + +// Schedule the loop to be executed again 20 sec later +[DFUNC(bodyCleanupLoop), [], 20] call EFUNC(common,waitAndExecute); diff --git a/addons/medical/functions/fnc_serverRemoveBody.sqf b/addons/medical/functions/fnc_serverRemoveBody.sqf index de089b199b..311199b1b8 100644 --- a/addons/medical/functions/fnc_serverRemoveBody.sqf +++ b/addons/medical/functions/fnc_serverRemoveBody.sqf @@ -26,23 +26,9 @@ TRACE_2("",_target,isPlayer _target); if (isNil QGVAR(bodiesToDelete)) then {GVAR(bodiesToDelete) = [];}; GVAR(bodiesToDelete) pushBack _target; -//Start up PFEH to wait for bodies to be free to delete -if ((count GVAR(bodiesToDelete)) == 1) then { - TRACE_1("starting PFEH",GVAR(bodiesToDelete)); - [{ - { - TRACE_2("body",_x,isPlayer _x); - if ((!isNull _x) && {!isPlayer _x}) then {deleteVehicle _x}; - } forEach GVAR(bodiesToDelete); - - //deleteVehicle doesn't have instant results so it won't usualy be filtered until next run - GVAR(bodiesToDelete) = GVAR(bodiesToDelete) - [objNull]; - - if (GVAR(bodiesToDelete) isEqualTo []) then { - TRACE_1("array emptied - rem PFEH",GVAR(bodiesToDelete)); - [_this select 1] call CBA_fnc_removePerFrameHandler; - }; - }, 20, []] call CBA_fnc_addPerFrameHandler; +// Start up a loop to wait for bodies to be free to delete +if ((count GVAR(bodiesToDelete)) > 0) then { + [] call FUNC(bodyCleanupLoop); }; nil