From 2713acdd38d93e85ccc6b5e1c558ca0e2e41b1b1 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Fri, 19 Jul 2024 00:12:14 -0500 Subject: [PATCH] Optimized loop to find spall position using larger steps and fewer operations per loop --- addons/frag/functions/fnc_doSpall.sqf | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/frag/functions/fnc_doSpall.sqf b/addons/frag/functions/fnc_doSpall.sqf index dbfb53e07e..60e2661db5 100644 --- a/addons/frag/functions/fnc_doSpall.sqf +++ b/addons/frag/functions/fnc_doSpall.sqf @@ -60,15 +60,16 @@ private _unitDir = vectorNormalized _oldVelocity; private _spallPosAGL = []; if ((isNil "_oldPosASL") || {!(_oldPosASL isEqualTypeArray [0,0,0])}) exitWith {WARNING_1("Problem with hitPart data - bad pos [%1]",_oldPosASL);}; -for "_i" from 0 to 100 do { - private _pos1 = _oldPosASL vectorAdd (_unitDir vectorMultiply (0.01 * _i)); - private _pos2 = _oldPosASL vectorAdd (_unitDir vectorMultiply (0.01 * (_i + 1))); - - if (!lineIntersects [_pos1, _pos2]) exitWith { +private _pos1 = _oldPosASL; +private _searchStepSize = unitDir vectorMultiply 0.05; +for "_i" from 1 to 20 do { + _spallPosAGL = _pos1 vectorAdd _searchStepSize; + if (!lineIntersects [_pos1, _spallPosAGL]) exitWith { _spallPosAGL = ASLtoAGL _pos2; }; + _pos1 = _spallPosAGL; }; -if (_spallPosAGL isEqualTo []) exitWith { +if (_spallPosAGL isEqualTo _pos1) exitWith { TRACE_1("can't find other side",_oldPosASL); }; (_shotParents#1) setVariable [QGVAR(nextSpallEvent), CBA_missionTime + ACE_FRAG_SPALL_UNIT_HOLDOFF];