From 863692625dd7fefc80051ffcbdbc6b3e9eb67ce0 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Thu, 18 Jan 2024 18:21:39 -0600 Subject: [PATCH] optimization, see https://github.com/acemod/ACE3/pull/9728#discussion_r1458112339 --- addons/frag/functions/fnc_doFragTargeted.sqf | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/addons/frag/functions/fnc_doFragTargeted.sqf b/addons/frag/functions/fnc_doFragTargeted.sqf index 9532b908f8..09336623d7 100644 --- a/addons/frag/functions/fnc_doFragTargeted.sqf +++ b/addons/frag/functions/fnc_doFragTargeted.sqf @@ -50,24 +50,20 @@ if (_objects isEqualTo []) exitWith { }; // grab crews and add them in so that targets stay approx. sorted by distance +private _targets = []; { - private _crew = crew _x; - if (_crew isNotEqualTo []) then { - private _arr = [_x]; - { - _arr pushBackUnique _x; - } forEach _crew; + private _crew = crew _x; + _crew pushBackUnique _x; + _targets append _crew; - _objects set [_forEachIndex, _arr]; - }; } forEach _objects; -_objects = flatten _objects; -TRACE_3("Targets found",_posASL,_fragRange,count _objects); + +TRACE_3("Targets found",_posASL,_fragRange,count _targets); // limit number of fragments per direction (2D) to 10 using _fragArcs private _fragArcs = createHashMap; private _totalFragCount = 0; -{ // Begin of forEach iterating on _objects +{ // Begin of forEach iterating on _targets if (!alive _x) then { continue; }; @@ -168,7 +164,7 @@ private _totalFragCount = 0; TRACE_2("maxFrags", _totalFragCount, _maxFrags); break; }; -} forEach _objects; +} forEach _targets; #ifdef DEBUG_MODE_FULL systemChat ("fragCount cnt: " + str _totalFragCount);