From 20f40f8c555d5b7c9ad7a7651c21cda784a597c5 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 9 Nov 2016 13:00:18 -0600 Subject: [PATCH] Use single queue for blood cleanup (#4586) --- addons/medical_blood/XEH_PREP.hpp | 1 + addons/medical_blood/XEH_postInit.sqf | 12 ++++++---- .../functions/fnc_serverCleanupBlood.sqf | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 addons/medical_blood/functions/fnc_serverCleanupBlood.sqf diff --git a/addons/medical_blood/XEH_PREP.hpp b/addons/medical_blood/XEH_PREP.hpp index 0c6f6e245a..aa7d358388 100644 --- a/addons/medical_blood/XEH_PREP.hpp +++ b/addons/medical_blood/XEH_PREP.hpp @@ -3,4 +3,5 @@ PREP(handleWoundReceived); PREP(isBleeding); PREP(onBleeding); PREP(createBlood); +PREP(serverCleanupBlood); PREP(spurt); diff --git a/addons/medical_blood/XEH_postInit.sqf b/addons/medical_blood/XEH_postInit.sqf index d927797c56..78bf5c43f9 100644 --- a/addons/medical_blood/XEH_postInit.sqf +++ b/addons/medical_blood/XEH_postInit.sqf @@ -10,13 +10,17 @@ if (isServer) then { [QGVAR(bloodDropCreated), { params ["_bloodDrop"]; - GVAR(bloodDrops) pushBack _bloodDrop; + // Add to created queue with format [expireTime, object] + private _index = GVAR(bloodDrops) pushBack [(CBA_missionTime + BLOOD_OBJECT_LIFETIME), _bloodDrop]; + if (count GVAR(bloodDrops) >= MAX_BLOOD_OBJECTS) then { - private _deletedBloodDrop = GVAR(bloodDrops) deleteAt 0; + (GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"]; deleteVehicle _deletedBloodDrop; }; - [{deleteVehicle _this}, _bloodDrop, BLOOD_OBJECT_LIFETIME] call CBA_fnc_waitAndExecute; + if (_index == 1) then { // Start the waitAndExecute loop + [FUNC(serverCleanupBlood), [], BLOOD_OBJECT_LIFETIME] call CBA_fnc_waitAndExecute; + }; }] call CBA_fnc_addEventHandler; }; @@ -30,7 +34,7 @@ if (isServer) then { } else { {allUnits select {(local _x) && {[_x] call FUNC(isBleeding)}}}; // filter all local bleeding units }; - + private _stateMachine = [_listcode, true] call CBA_statemachine_fnc_create; [_stateMachine, {call FUNC(onBleeding)}, {}, {}, "Bleeding"] call CBA_statemachine_fnc_addState; diff --git a/addons/medical_blood/functions/fnc_serverCleanupBlood.sqf b/addons/medical_blood/functions/fnc_serverCleanupBlood.sqf new file mode 100644 index 0000000000..4adc304d8c --- /dev/null +++ b/addons/medical_blood/functions/fnc_serverCleanupBlood.sqf @@ -0,0 +1,23 @@ +/* + * Author: PabstMirror + * Loop that cleans up blood + * + * Arguments: + * None + * + * ReturnValue: + * None + * + * Public: No + */ +#include "script_component.hpp" + +(GVAR(bloodDrops) deleteAt 0) params ["", "_deletedBloodDrop"]; +deleteVehicle _deletedBloodDrop; + +// If we cleaned out the array, exit loop +if (GVAR(bloodDrops) isEqualTo []) exitWith {}; + +// Wait until the next blood drop in the queue will expire +(GVAR(bloodDrops) select 0) params ["_expireTime"]; +[FUNC(serverCleanupBlood), [], (_expireTime - CBA_missionTime)] call CBA_fnc_waitAndExecute;