Skip to content

Commit

Permalink
General - Optimize some loops with forEachReversed (#10191)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror authored Aug 11, 2024
1 parent 3ff635f commit 285f903
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions addons/medical_vitals/functions/fnc_handleUnitVitals.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ if (_adjustments isNotEqualTo []) then {
private _timeInSystem = CBA_missionTime - _timeAdded;
if (_timeInSystem >= _maxTimeInSystem) then {
_deleted = true;
_adjustments set [_forEachIndex, objNull];
_adjustments deleteAt _forEachIndex;
} else {
private _effectRatio = (((_timeInSystem / _timeTillMaxEffect) ^ 2) min 1) * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem;
if (_hrAdjust != 0) then { _hrTargetAdjustment = _hrTargetAdjustment + _hrAdjust * _effectRatio; };
if (_painAdjust != 0) then { _painSupressAdjustment = _painSupressAdjustment + _painAdjust * _effectRatio; };
if (_flowAdjust != 0) then { _peripheralResistanceAdjustment = _peripheralResistanceAdjustment + _flowAdjust * _effectRatio; };
};
} forEach _adjustments;
} forEachReversed _adjustments;

if (_deleted) then {
_unit setVariable [VAR_MEDICATIONS, _adjustments - [objNull], true];
_unit setVariable [VAR_MEDICATIONS, _adjustments, true];
_syncValues = true;
};
};
Expand Down
10 changes: 2 additions & 8 deletions addons/winddeflection/functions/fnc_updateTrajectoryPFH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
_args set [0, CBA_missionTime];
private _isWind = (vectorMagnitude wind > 0);

private _deleted = false;
{
_x params ["_bullet", "_airFriction"];

private _bulletVelocity = velocity _bullet;
private _bulletSpeedSqr = vectorMagnitudeSqr _bulletVelocity;

if ((!alive _bullet) || {(_bullet isKindOf "BulletBase") && {_bulletSpeedSqr < 10000}}) then {
GVAR(trackedBullets) set [_forEachIndex, objNull];
_deleted = true;
GVAR(trackedBullets) deleteAt _forEachIndex;
} else {
if (_isWind) then {
private _trueVelocity = _bulletVelocity vectorDiff wind;
Expand All @@ -50,11 +48,7 @@
};
_bullet setVelocity _bulletVelocity;
};
} forEach GVAR(trackedBullets);

if (_deleted) then {
GVAR(trackedBullets) = GVAR(trackedBullets) - [objNull];
};
} forEachReversed GVAR(trackedBullets);

// END_COUNTER(pfeh);
}, GVAR(simulationInterval), [CBA_missionTime]] call CBA_fnc_addPerFrameHandler;

0 comments on commit 285f903

Please sign in to comment.