Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General - Optimize some if statements #10302

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions addons/common/functions/fnc_claim.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ _target setVariable [QGVAR(owner), _unit, true];

// lock target object
if (_lockTarget) then {
if (!isNull _unit) then {
[QGVAR(lockVehicle), _target, _target] call CBA_fnc_targetEvent;
} else {
if (isNull _unit) then {
[QGVAR(unlockVehicle), _target, _target] call CBA_fnc_targetEvent;
} else {
[QGVAR(lockVehicle), _target, _target] call CBA_fnc_targetEvent;
};
};

Expand Down
6 changes: 3 additions & 3 deletions addons/common/functions/fnc_getDeathAnim.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ private _unitActionsCfg = configFile >> "CfgMovesBasic" >> "Actions" >> getText

TRACE_2("Animation/Action",configName _unitAnimationCfg,configName _unitActionsCfg);

if (!isNull objectParent _unit) then {
if (isNull objectParent _unit) then {
_returnAnimation = getText (_unitActionsCfg >> "die");
} else {
private _interpolateArray = getArray (_unitAnimationCfg >> "interpolateTo");

for "_index" from 0 to (count _interpolateArray - 1) step 2 do {
Expand All @@ -42,8 +44,6 @@ if (!isNull objectParent _unit) then {
_returnAnimation = _indexAnimation;
};
};
} else {
_returnAnimation = getText (_unitActionsCfg >> "die");
};

//Fallback if nothing valid found:
Expand Down
8 changes: 4 additions & 4 deletions addons/field_rations/functions/fnc_getActionOffset.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
params ["_object"];

private _configOf = configOf _object;
if !(isNull _configOf) then {
if (isNull _configOf) then {
// Check for offset corresponding to p3d list
GVAR(waterSourceOffsets) param [GVAR(waterSourceP3ds) find (getModelInfo _object select 0), [0, 0, 0], [[]]];
} else {
// Check for offset in config since we have valid typeOf
private _offset = getArray (_configOf >> QXGVAR(offset));
if (_offset isEqualTo []) then {[0, 0, 0]} else {_offset};
} else {
// Check for offset corresponding to p3d list
GVAR(waterSourceOffsets) param [GVAR(waterSourceP3ds) find (getModelInfo _object select 0), [0, 0, 0], [[]]];
};
8 changes: 4 additions & 4 deletions addons/field_rations/functions/fnc_getRemainingWater.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ private _water = _source getVariable QGVAR(currentWaterSupply);

if (isNil "_water") then {
private _configOf = configOf _source;
if !(isNull _configOf) then {
if (isNull _configOf) then {
// Check the p3d name against list
_water = if ((getModelInfo _source select 0) in GVAR(waterSourceP3ds)) then {REFILL_WATER_INFINITE} else {REFILL_WATER_DISABLED};
} else {
// Check for waterSupply entry since we have valid typeOf
_water = getNumber (_configOf >> QXGVAR(waterSupply));
if (_water == 0) then {_water = REFILL_WATER_DISABLED};
Expand All @@ -35,9 +38,6 @@ if (isNil "_water") then {
_source setVariable [QGVAR(currentWaterSupply), _water, true];
};
};
} else {
// Check the p3d name against list
_water = if ((getModelInfo _source select 0) in GVAR(waterSourceP3ds)) then {REFILL_WATER_INFINITE} else {REFILL_WATER_DISABLED};
};
};

Expand Down
10 changes: 5 additions & 5 deletions addons/goggles/functions/fnc_applyRotorWashEffect.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ if !(_safe) then {
if !([_unit] call FUNC(isGogglesVisible)) exitWith {};

if (GETDUSTT(DAMOUNT) < 2) then {
if !(GETDUSTT(DACTIVE)) then {
SETDUST(DACTIVE,true);

call FUNC(applyDustEffect);
} else {
if (GETDUSTT(DACTIVE)) then {
if (_rotorWash select 1 > 0.5) then {
call FUNC(applyDustEffect);
};
} else {
SETDUST(DACTIVE,true);

call FUNC(applyDustEffect);
};
};

Expand Down
14 changes: 7 additions & 7 deletions addons/interact_menu/functions/fnc_keyDown.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ GVAR(selfMenuOffset) = (AGLToASL (positionCameraToWorld [0, 0, 2])) vectorDiff (
//Auto expand the first level when self, mounted vehicle or zeus (skips the first animation as there is only one choice)
if (GVAR(openedMenuType) == 0) then {
if (isNull curatorCamera) then {
if !(isNull (ACE_controlledUAV select 0)) then {
GVAR(menuDepthPath) = [["ACE_SelfActions", (ACE_controlledUAV select 0)]];
GVAR(expanded) = true;
GVAR(expandedTime) = diag_tickTime;
GVAR(lastPath) = +GVAR(menuDepthPath);
GVAR(startHoverTime) = -1000;
} else {
if (isNull (ACE_controlledUAV select 0)) then {
if (vehicle ACE_player != ACE_player) then {
GVAR(menuDepthPath) = [["ACE_SelfActions", (vehicle ACE_player)]];
GVAR(expanded) = true;
GVAR(expandedTime) = diag_tickTime;
GVAR(lastPath) = +GVAR(menuDepthPath);
GVAR(startHoverTime) = -1000;
};
} else {
GVAR(menuDepthPath) = [["ACE_SelfActions", (ACE_controlledUAV select 0)]];
GVAR(expanded) = true;
GVAR(expandedTime) = diag_tickTime;
GVAR(lastPath) = +GVAR(menuDepthPath);
GVAR(startHoverTime) = -1000;
};
} else {
GVAR(menuDepthPath) = [["ACE_ZeusActions", (getAssignedCuratorLogic player)]];
Expand Down
15 changes: 8 additions & 7 deletions addons/interact_menu/functions/fnc_renderActionPoints.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ private _fnc_renderSelfActions = {
// Iterate through base level class actions and render them if appropiate
private _classActions = GVAR(ActSelfNamespace) get typeOf _target;

private _pos = if !(GVAR(useCursorMenu)) then {
private _pos = if (GVAR(useCursorMenu)) then {
[0.5, 0.5]
} else {
//Convert to ASL, add offset and then convert back to AGL (handles waves when over water)
ASLToAGL ((AGLToASL (positionCameraToWorld [0, 0, 0])) vectorAdd GVAR(selfMenuOffset));
} else {
[0.5, 0.5]
};

{
Expand All @@ -123,10 +123,7 @@ GVAR(collectedActionPoints) resize 0;
// Render nearby actions, unit self actions or vehicle self actions as appropiate
if (GVAR(openedMenuType) == 0) then {
if (isNull curatorCamera) then {
if !(isNull (ACE_controlledUAV select 0)) then {
// Render UAV self actions when in control of UAV AI
(ACE_controlledUAV select 0) call _fnc_renderSelfActions;
} else {
if (isNull (ACE_controlledUAV select 0)) then {
if (vehicle ACE_player == ACE_player) then {
if (diag_tickTime > GVAR(lastTimeSearchedActions) + 0.20) then {
// Once every 0.2 secs, collect nearby objects active and visible action points and render them
Expand All @@ -139,6 +136,10 @@ if (GVAR(openedMenuType) == 0) then {
// Render vehicle self actions when in vehicle
(vehicle ACE_player) call _fnc_renderSelfActions;
};
} else {
// Render UAV self actions when in control of UAV AI
(ACE_controlledUAV select 0) call _fnc_renderSelfActions;

};
} else {
// Render zeus actions when zeus open
Expand Down
6 changes: 3 additions & 3 deletions addons/laser/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ if (hasInterface) then {
["ACE_controlledUAV", {
params ["_UAV", "_seatAI", "_turret", "_position"];
TRACE_4("ACE_controlledUAV EH",_UAV,_seatAI,_turret,_position);
if (!isNull _seatAI) then {
[_seatAI] call FUNC(showVehicleHud);
} else {
if (isNull _seatAI) then {
[ace_player] call FUNC(showVehicleHud);
} else {
[_seatAI] call FUNC(showVehicleHud);
};
}] call CBA_fnc_addEventHandler;
}] call CBA_fnc_addEventHandler;
Expand Down
10 changes: 5 additions & 5 deletions addons/medical_engine/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ if (_context == 2) then {
if (_environmentDamage) then {
// Any collision with terrain/vehicle/object has a shooter
// Check this first because burning can happen at any velocity
if !(isNull _shooter) then {
if (isNull _shooter) then {
// Anything else is almost guaranteed to be fire damage
_ammo = "fire";
TRACE_5("Fire Damage",_unit,_shooter,_instigator,_damage,_allDamages);
} else {
/*
If shooter != unit then they hit unit, otherwise it could be:
- Unit hitting anything at speed
Expand All @@ -180,10 +184,6 @@ if (_context == 2) then {
_ammo = "collision";
TRACE_5("Collision",_unit,_shooter,_instigator,_damage,_allDamages);
};
} else {
// Anything else is almost guaranteed to be fire damage
_ammo = "fire";
TRACE_5("Fire Damage",_unit,_shooter,_instigator,_damage,_allDamages);
};
};

Expand Down
2 changes: 1 addition & 1 deletion addons/microdagr/functions/fnc_showApplicationPage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (GVAR(currentApplicationPage) == APP_MODE_INFODISPLAY) then {
(_display displayCtrl IDC_MAPDETAILS) ctrlShow ((GVAR(currentApplicationPage) == APP_MODE_MAP) && {GVAR(mapShowTexture)});

if (GVAR(currentApplicationPage) == APP_MODE_MAP) then {
_theMap = if (!GVAR(mapShowTexture)) then {_display displayCtrl IDC_MAPPLAIN} else {_display displayCtrl IDC_MAPDETAILS};
_theMap = if (GVAR(mapShowTexture)) then {_display displayCtrl IDC_MAPDETAILS} else {_display displayCtrl IDC_MAPPLAIN};
_mapSize = (ctrlPosition _theMap) select 3;
_theMap ctrlMapAnimAdd [0, (GVAR(mapZoom) / _mapSize), GVAR(mapPosition)];
ctrlMapAnimCommit _theMap;
Expand Down
6 changes: 3 additions & 3 deletions addons/missileguidance/functions/fnc_checkLos.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ private _targetAimPos = aimPos _target;
private _seekerPos = getPosASL _seeker;
private _return = true;

if (!((terrainIntersectASL [_seekerPos, _targetPos]) && {terrainIntersectASL [_seekerPos, _targetAimPos]})) then {
if ((terrainIntersectASL [_seekerPos, _targetPos]) && {terrainIntersectASL [_seekerPos, _targetAimPos]}) then {
_return = false;
} else {
if (lineIntersects [_seekerPos, _targetPos, _seeker, _target]) then {
_return = false;
};
} else {
_return = false;
};

_return
8 changes: 4 additions & 4 deletions addons/missileguidance/functions/fnc_seekerType_SACLOS.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ _seekerStateParams params ["_memoryPointGunnerOptics", "_animationSourceBody", "
private _shooterPos = AGLToASL (_shooter modelToWorldVisual (_shooter selectionPosition _memoryPointGunnerOptics));
private _projPos = getPosASL _projectile;

private _lookDirection = if !(_shooter isKindOf "CAManBase" || {_shooter isKindOf "StaticWeapon"}) then {
private _lookDirection = if (_shooter isKindOf "CAManBase" || {_shooter isKindOf "StaticWeapon"}) then {
_shooterPos = eyePos _shooter;
_shooter weaponDirection _weapon
} else {
private _finalLookDirection = if (_usePilotCamera) then {
_shooterPos = _shooter modelToWorldVisualWorld getPilotCameraPosition _shooter;
private _trackingTarget = getPilotCameraTarget _shooter;
Expand All @@ -43,9 +46,6 @@ private _lookDirection = if !(_shooter isKindOf "CAManBase" || {_shooter isKindO
_shooter vectorModelToWorldVisual ([1, _gBody, _gGun] call CBA_fnc_polar2vect);
};
_finalLookDirection
} else {
_shooterPos = eyePos _shooter;
_shooter weaponDirection _weapon
};

private _distanceToProj = _shooterPos vectorDistance _projPos;
Expand Down
6 changes: 3 additions & 3 deletions addons/nametags/functions/fnc_drawNameTagIcon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ _fnc_parameters = {
private _targetFaction = _target getVariable [QGVAR(faction), faction _target];
private _customRankIcons = GVAR(factionRanks) get _targetFaction;

if (!isNil "_customRankIcons") then {
_customRankIcons param [ALL_RANKS find rank _target, ""] // return
} else {
if (isNil "_customRankIcons") then {
// default rank icons
format ["\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa", rank _target] // return
} else {
_customRankIcons param [ALL_RANKS find rank _target, ""] // return
};
};
};
Expand Down
6 changes: 3 additions & 3 deletions addons/nametags/functions/fnc_onDraw3d.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ if (_enabledTagsCursor) then {
private _target = cursorTarget;
if !(_target isKindOf "CAManBase") then {
// When cursorTarget is on a vehicle show the nametag for the commander.
if !(_target in allUnitsUAV) then {
_target = effectiveCommander _target;
} else {
if (_target in allUnitsUAV) then {
_target = objNull;
} else {
_target = effectiveCommander _target;
};
};
if (isNull _target) exitWith {};
Expand Down
8 changes: 4 additions & 4 deletions addons/quickmount/functions/fnc_addFreeSeatsActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ private _cargoNumber = -1;
if (_vehicle lockedTurret _turretPath) then {breakTo "crewLoop"};
if (_role == "gunner" && {unitIsUAV _vehicle}) then {breakTo "crewLoop"};
private _turretConfig = [_vehicleConfig, _turretPath] call CBA_fnc_getTurret;
if (!_isInVehicle) then {
_params = ["GetInTurret", _vehicle, _turretPath];
_statement = {_player action (_this select 2)};
} else {
if (_isInVehicle) then {
private _gunnerCompartments = (_turretConfig >> "gunnerCompartments") call BIS_fnc_getCfgData;
TO_COMPARTMENT_STRING(_gunnerCompartments);
if (_compartment != _gunnerCompartments) then {breakTo "crewLoop"};
_params = [{MOVE_IN_CODE(moveInTurret)}, [_vehicle, _turretPath], _currentTurret, _moveBackCode, _moveBackParams];
_statement = _fnc_move;
} else {
_params = ["GetInTurret", _vehicle, _turretPath];
_statement = {_player action (_this select 2)};
};
_name = getText (_turretConfig >> "gunnerName");
_icon = switch true do {
Expand Down
6 changes: 3 additions & 3 deletions addons/scopes/functions/fnc_calculateZeroAngleCorrection.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ private _vanillaZero = parseNumber (("ace" callExtension ["ballistics:replicate_
_vanillaZero = 0;
#endif

private _trueZero = if (!_advancedBallistics) then {
parseNumber (("ace" callExtension ["ballistics:zero_vanilla", [_newZeroRange, _initSpeed, _airFriction, _boreHeight]]) select 0)
} else {
private _trueZero = if (_advancedBallistics) then {
// Get Weapon and Ammo Configurations
private _AmmoCacheEntry = uiNamespace getVariable format[QEGVAR(advanced_ballistics,%1), _ammo];
if (isNil "_AmmoCacheEntry") then {
Expand Down Expand Up @@ -81,6 +79,8 @@ private _trueZero = if (!_advancedBallistics) then {
_atmosphereModel
]]) select 0
)
} else {
parseNumber (("ace" callExtension ["ballistics:zero_vanilla", [_newZeroRange, _initSpeed, _airFriction, _boreHeight]]) select 0)
};

private _zeroAngleCorrection = _trueZero - _vanillaZero;
Expand Down
6 changes: 3 additions & 3 deletions addons/spectator/functions/fnc_cam_tick.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ if (_cameraMode != MODE_FREE) then {
_camTarget = GVAR(camFocus);

// Focus get in / out of vehicle state
if !(isNull _camTarget) then {
if (isNull _camTarget) then {
GVAR(camTargetInVehicle) = false;
} else {
private _targetInVeh = GVAR(camTargetInVehicle);

if (GVAR(camHasTarget)) then {
Expand All @@ -72,8 +74,6 @@ if !(isNull _camTarget) then {
GVAR(camTargetInVehicle) = false;
};
};
} else {
GVAR(camTargetInVehicle) = false;
};

// Camera lights
Expand Down
6 changes: 3 additions & 3 deletions addons/vehicle_damage/functions/fnc_handleVehicleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ if (isNil "_multHit") then {
_ignoreHit = true;
} else {
// If the hitpoint isnt in the old array then that means that the time expired and a new array should be generated
if (!_hitPointInOldArray) then {
if (_hitPointInOldArray) then {
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, [_hitPoint]]];
} else {
private _oldHitPoints = _multHit select 2;
_oldHitPoints pushBack _hitPoint;
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, _oldHitPoints]];

_ignoreBailCheck = true;
} else {
_vehicle setVariable [QGVAR(hitTime), [CBA_missionTime, _source, [_hitPoint]]];
};
};
};
Expand Down
6 changes: 3 additions & 3 deletions addons/volume/XEH_postInitClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ if (!hasInterface) exitWith {};

if (!XGVAR(lowerInVehicles)) exitWith {};

if (!isNull objectParent _unit) then {
call FUNC(lowerVolume);
} else {
if (isNull objectParent _unit) then {
call FUNC(restoreVolume);
} else {
call FUNC(lowerVolume);
};
}] call CBA_fnc_addPlayerEventHandler;

Expand Down