fix Issue with forEach Loops and deleteAt Index

This commit is contained in:
jokoho48 2015-11-17 04:31:17 +01:00
parent bc09b50fa5
commit f3c5c64390
4 changed files with 24 additions and 29 deletions

View File

@ -26,19 +26,19 @@ _aceTimeSecond = floor ACE_time;
_bulletSpeed = vectorMagnitude _bulletVelocity; _bulletSpeed = vectorMagnitude _bulletVelocity;
if (!alive _bullet || _bulletSpeed < 100) exitWith { if (!alive _bullet || _bulletSpeed < 100) then {
GVAR(allBullets) deleteAt (_forEachIndex - _deleted); GVAR(allBullets) deleteAt (GVAR(allBullets) find _x);
_deleted = _deleted + 1; } else {
_bulletPosition = getPosASL _bullet;
if (_bulletTraceVisible && _bulletSpeed > 500) then {
drop ["\A3\data_f\ParticleEffects\Universal\Refract","","Billboard",1,0.1,getPos _bullet,[0,0,0],0,1.275,1,0,[0.02*_caliber,0.01*_caliber],[[0,0,0,0.65],[0,0,0,0.2]],[1,0],0,0,"","",""];
};
call compile ("ace_advanced_ballistics" callExtension format["simulate:%1:%2:%3:%4:%5:%6:%7", _index, _bulletVelocity, _bulletPosition, ACE_wind, ASLToATL(_bulletPosition) select 2, _aceTimeSecond, ACE_time - _aceTimeSecond]);
}; };
nil
_bulletPosition = getPosASL _bullet; } count +GVAR(allBullets);
if (_bulletTraceVisible && _bulletSpeed > 500) then {
drop ["\A3\data_f\ParticleEffects\Universal\Refract","","Billboard",1,0.1,getPos _bullet,[0,0,0],0,1.275,1,0,[0.02*_caliber,0.01*_caliber],[[0,0,0,0.65],[0,0,0,0.2]],[1,0],0,0,"","",""];
};
call compile ("ace_advanced_ballistics" callExtension format["simulate:%1:%2:%3:%4:%5:%6:%7", _index, _bulletVelocity, _bulletPosition, ACE_wind, ASLToATL(_bulletPosition) select 2, _aceTimeSecond, ACE_time - _aceTimeSecond]);
} forEach GVAR(allBullets);
if (GVAR(allBullets) isEqualTo []) then { if (GVAR(allBullets) isEqualTo []) then {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_this select 1] call CBA_fnc_removePerFrameHandler;

View File

@ -8,7 +8,7 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
//Singe PFEH to handle execNextFrame, waitAndExec and waitUntilAndExec: //Singe PFEH to handle execNextFrame, waitAndExec and waitUntilAndExec:
[{ {
BEGIN_COUNTER(waitAndExec); BEGIN_COUNTER(waitAndExec);
//Handle the waitAndExec array: //Handle the waitAndExec array:
@ -29,17 +29,16 @@
GVAR(nextFrameNo) = diag_frameno + 1; GVAR(nextFrameNo) = diag_frameno + 1;
//Handle the waitUntilAndExec array: //Handle the waitUntilAndExec array:
local _deleted = 0;
{ {
// if condition is satisifed call statement // if condition is satisifed call statement
if ((_x select 2) call (_x select 0)) then { if ((_x select 2) call (_x select 0)) then {
// make sure to delete the correct handle when multiple conditions are met in one frame // make sure to delete the correct handle when multiple conditions are met in one frame
GVAR(waitUntilAndExecArray) deleteAt (_forEachIndex - _deleted); GVAR(waitUntilAndExecArray) deleteAt (GVAR(waitUntilAndExecArray) find _x);
_deleted = _deleted + 1;
(_x select 2) call (_x select 1); (_x select 2) call (_x select 1);
}; };
} forEach GVAR(waitUntilAndExecArray); nil
} count +GVAR(waitUntilAndExecArray);
END_COUNTER(waitAndExec); END_COUNTER(waitAndExec);
}, 0, []] call CBA_fnc_addPerFrameHandler; }, 0, []] call CBA_fnc_addPerFrameHandler;

View File

@ -38,19 +38,16 @@ GVAR(setVariablePublicArray) pushBack [_object, _varName, _syncTime, _idName];
if (isNil QGVAR(setVariablePublicPFH)) exitWith {}; if (isNil QGVAR(setVariablePublicPFH)) exitWith {};
GVAR(setVariablePublicPFH) = [{ GVAR(setVariablePublicPFH) = [{
private "_delete";
_delete = 0;
{ {
_x params ["_object", "_varName", "_syncTime", "_idName"]; _x params ["_object", "_varName", "_syncTime", "_idName"];
if (ACE_diagTime > _syncTime) then { if (ACE_diagTime > _syncTime) then {
// set value public // set value public
_object setVariable [_varName, _object getVariable _varName, true]; _object setVariable [_varName, _object getVariable _varName, true];
GVAR(setVariablePublicArray) deleteAt _forEachIndex - _delete; GVAR(setVariablePublicArray) deleteAt (GVAR(setVariablePublicArray) find _x);
GVAR(setVariableNames) deleteAt _forEachIndex - _delete; GVAR(setVariableNames) deleteAt (GVAR(setVariableNames) find _x);
_delete = _delete + 1;
}; };
} forEach GVAR(setVariablePublicArray); nil
} count +GVAR(setVariablePublicArray);
if (GVAR(setVariablePublicArray) isEqualTo []) then { if (GVAR(setVariablePublicArray) isEqualTo []) then {
[GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler; [GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler;

View File

@ -34,8 +34,7 @@
_bulletSpeed = vectorMagnitude _bulletVelocity; _bulletSpeed = vectorMagnitude _bulletVelocity;
if ((!alive _bullet) || {(_bullet isKindOf "BulletBase") && {_bulletSpeed < 100}}) then { if ((!alive _bullet) || {(_bullet isKindOf "BulletBase") && {_bulletSpeed < 100}}) then {
GVAR(trackedBullets) deleteAt (_forEachIndex - _deleted); GVAR(trackedBullets) deleteAt (GVAR(trackedBullets) find _x);
_deleted = _deleted + 1;
} else { } else {
if (_isWind) then { if (_isWind) then {
_trueVelocity = _bulletVelocity vectorDiff ACE_wind; _trueVelocity = _bulletVelocity vectorDiff ACE_wind;
@ -51,7 +50,7 @@
}; };
_bullet setVelocity _bulletVelocity; _bullet setVelocity _bulletVelocity;
}; };
nil
} forEach GVAR(trackedBullets); } count +GVAR(trackedBullets);
// END_COUNTER(pfeh); // END_COUNTER(pfeh);
}, GVAR(simulationInterval), [ACE_time]] call CBA_fnc_addPerFrameHandler; }, GVAR(simulationInterval), [ACE_time]] call CBA_fnc_addPerFrameHandler;