Skip to content

Commit

Permalink
Cleanup private ARRAY (#941)
Browse files Browse the repository at this point in the history
* Cleanup use of private ARRAY

* Modernize fnc_vectCross

* stuff I forgot to save

* params

* newline eof

* params

* no semicolon for return value

* formatting, optimization

* formatting of array copy
  • Loading branch information
dedmen authored and commy2 committed Jun 30, 2018
1 parent 2741433 commit 667299c
Show file tree
Hide file tree
Showing 45 changed files with 315 additions and 438 deletions.
4 changes: 2 additions & 2 deletions addons/accessory/fnc_switchAttachment.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Author:

params ["_itemType", "_switchTo"];

private ["_currWeaponType", "_currItem", "_switchItem"];
private ["_currItem", "_switchItem"];
private _unit = call CBA_fnc_currentUnit;
private _cw = currentWeapon _unit;

_currWeaponType = call {
private _currWeaponType = call {
if (_cw == "") exitWith {_currItem = ""; -1};
if (_cw == primaryWeapon _unit) exitWith {_currItem = (primaryWeaponItems _unit) select _itemType; 0};
if (_cw == handgunWeapon _unit) exitWith {_currItem = (handgunItems _unit) select _itemType; 1};
Expand Down
3 changes: 1 addition & 2 deletions addons/ai/fnc_addWaypoint.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ params [
_group = _group call CBA_fnc_getGroup;
_position = _position call CBA_fnc_getPos;

private ["_waypoint"];
_waypoint = _group addWaypoint [_position, _radius];
private _waypoint = _group addWaypoint [_position, _radius];

_waypoint setWaypointType _type;
_waypoint setWaypointBehaviour _behaviour;
Expand Down
24 changes: 11 additions & 13 deletions addons/arrays/fnc_getArrayDiff.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ Author:

params ["_arrayA", "_arrayB"];

private ["_elmsA", "_elmsB", "_return", "_item", "_idx", "_cA", "_cB", "_case", "_cT"];

// Simplify the arrays to save on processing power
_elmsA = _arrayA call CBA_fnc_getArrayElements;
_elmsB = _arrayB call CBA_fnc_getArrayElements;
_return = [[], []];
private _elmsA = _arrayA call CBA_fnc_getArrayElements;
private _elmsB = _arrayB call CBA_fnc_getArrayElements;
private _return = [[], []];

for "_i" from 1 to (count _elmsA) step 2 do {
// Pick the first item
_item = _elmsA select 0;
_idx = _elmsB find _item; // O(n^2), TODO: Find a way to differentiate counts
_cA = _elmsA select 1;
private _item = _elmsA select 0;
private _idx = _elmsB find _item; // O(n^2), TODO: Find a way to differentiate counts
private _cA = _elmsA select 1;
if (_idx > -1) then {
// Differential code
_cB = _elmsB select (_idx + 1);
private _cB = _elmsB select (_idx + 1);

_case = -1;
_cT = _cA - _cB;
private _case = -1;
private _cT = _cA - _cB;
if (_cT < 0) then {
_case = 1; //Missing from B
_cT = abs _cT;
Expand Down Expand Up @@ -73,8 +71,8 @@ for "_i" from 1 to (count _elmsA) step 2 do {
};
// Now add all those missing from A
for "_i" from 0 to (count _elmsB - 1) step 2 do {
_item = _elmsB select _i;
_cB = _elmsB select (_i + 1);
private _item = _elmsB select _i;
private _cB = _elmsB select (_i + 1);
for "_j" from 0 to (_cB - 1) do {
(_return select 1) pushBack _item; // Fills array
};
Expand Down
12 changes: 5 additions & 7 deletions addons/arrays/fnc_getArrayElements.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ Author:
---------------------------------------------------------------------------- */

private ["_array", "_return", "_countA", "_var", "_countB"];

_array =+ _this;
_return = [];
_countA = count _array;
private _array = +_this;
private _return = [];
private _countA = count _array;

while {_countA > 0} do {
_var = _array select 0;
private _var = _array select 0;
_array = _array - [_var];
_countB = count _array;
private _countB = count _array;
_return = _return + [_var, _countA - _countB];
_countA = _countB;
};
Expand Down
16 changes: 8 additions & 8 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ LOG(MSG_INIT);
// Upgrade check - Registry for removed addons, warn the user if found
// TODO: Evaluate registry of 'current addons' and verifying that against available CfgPatches
TRACE_1("Upgrade Check",nil);
#define CFG configFile >> "CfgSettings" >> "CBA" >> "registry"
private ["_entry"];
for "_i" from 0 to ((count (CFG)) - 1) do {
_entry = (CFG) select _i;
if (isClass(_entry) && {isArray(_entry >> "removed")}) then {
private _config = configFile >> "CfgSettings" >> "CBA" >> "registry";

for "_i" from 0 to (count _config - 1) do {
private _entry = _config select _i;
if (isClass _entry && {isArray (_entry >> "removed")}) then {
{
if (isClass(configFile >> "CfgPatches" >> _x)) then {
format["WARNING: Found addon that should be removed: %1; Please remove and restart game", _x] call FUNC(log);
if (isClass (configFile >> "CfgPatches" >> _x)) then {
format ["WARNING: Found addon that should be removed: %1; Please remove and restart game", _x] call FUNC(log);
};
} forEach (getArray(_entry >> "removed"));
} forEach getArray (_entry >> "removed");
};
};

Expand Down
17 changes: 8 additions & 9 deletions addons/common/fnc_createMarker.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ Author:
#include "script_component.hpp"
SCRIPT(createMarker);

private ["_m", "_br", "_ty", "_co", "_tx", "_persist", "_global"];

_br = ["BRUSH:", "brush:", "", _this] call CBA_fnc_getArg;
_ty = ["TYPE:", "type:", "", _this] call CBA_fnc_getArg;
_co = ["COLOR:", "color:", "", _this] call CBA_fnc_getArg;
_tx = ["TEXT:", "text:", "", _this] call CBA_fnc_getArg;
_persist = "PERSIST" in _this;
_global = "GLOBAL" in _this || _persist;
private _m = "";
private _br = ["BRUSH:", "brush:", "", _this] call CBA_fnc_getArg;
private _ty = ["TYPE:", "type:", "", _this] call CBA_fnc_getArg;
private _co = ["COLOR:", "color:", "", _this] call CBA_fnc_getArg;
private _tx = ["TEXT:", "text:", "", _this] call CBA_fnc_getArg;
private _persist = "PERSIST" in _this;
private _global = "GLOBAL" in _this || _persist;
TRACE_6("",_br,_ty,_co,_tx,_persist,_global);


Expand All @@ -69,4 +68,4 @@ if (_global) then {
if (_tx!= "") then { _m setMarkerTextLocal _tx };
};

_m;
_m
8 changes: 3 additions & 5 deletions addons/common/fnc_getAnimType.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ Author:
#include "script_component.hpp"
SCRIPT(getAnimType);

private ["_anim", "_weapon", "_pos"];

params ["_man","_array"];
_anim = "";
_weapon = format["%1", currentWeapon _man];
_pos = "";
private _anim = "";
private _weapon = format["%1", currentWeapon _man];
private _pos = "";

if (_weapon != "") then {
_class = configFile >> "CfgWeapons" >> _weapon;
Expand Down
10 changes: 3 additions & 7 deletions addons/common/fnc_getArg.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ Author:
#include "script_component.hpp"
SCRIPT(getArg);

private["_cLC", "_cUC", "_arg", "_list", "_a", "_v"];
_cLC = _this select 0;
_cUC = _this select 1;
_arg = _this select 2;
_list = _this select 3;
params ["_cLC", "_cUC", "_arg", "_list"]

_a = -1;
private _a = -1;
{
_a = _a + 1;
_v = format["%1", _list select _a];
private _v = format["%1", _list select _a];
if (_v == _cLC || {_v == _cUC}) then {
_arg = (_list select _a+1);
};
Expand Down
16 changes: 6 additions & 10 deletions addons/common/fnc_getAspectRatio.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ Author:
#include "script_component.hpp"
SCRIPT(getAspectRatio);

private _output = toUpper _this;
private _aspectStr = "";
private _aspectArr = [];
private _return = 0;
private _ratio = (round ((safeZoneW / safeZoneH) * 1000)) / 1000;

private ["_output","_aspectStr","_aspectArr","_ratio","_return"];

_output = toUpper _this;

_aspectStr = "";
_aspectArr = [];
_return = 0;

_ratio = (round ((safeZoneW / safeZoneH) * 1000)) / 1000;
switch (_ratio) do {
case 1: {
_aspectStr = "4:3";
Expand Down Expand Up @@ -72,4 +68,4 @@ if (_output == "ARRAY") then {_return = _aspectArr;};
if (_output == "STRING") then {_return = _aspectStr;};
if (_output == "NUMBER") then {_return = _ratio;};

_return;;
_return;
21 changes: 11 additions & 10 deletions addons/common/fnc_getConfigEntry.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ Author:
#include "script_component.hpp"
SCRIPT(getConfigEntry);

private ["_r"];
switch (toLower(_this select 1)) do {
params ["_configEntry", "_entryType", "_defaultValue"];

private _r = _defaultValue;

switch (toLower _entryType) do {
case "text": {
if (isText (_this select 0)) then {
_r = getText (_this select 0);
if (isText _configEntry) then {
_r = getText _configEntry;
};
};
case "array": {
if (isArray (_this select 0)) then {
_r = getArray (_this select 0);
if (isArray _configEntry) then {
_r = getArray _configEntry;
};
};
case "number": {
if (isNumber (_this select 0)) then {
_r = getNumber (_this select 0);
if (isNumber _configEntry) then {
_r = getNumber _configEntry;
};
};
};

if (isNil "_r") then { _r = _this select 2 };

_r
34 changes: 16 additions & 18 deletions addons/common/fnc_getFov.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@ Authors:
#define __dist 10000
#define __xOff 5000

private ["_zoomRef", "_widthReal", "_safeZoneAspectRatio", "_screenAspectRatio", "_pos", "_xPos", "_deltaX", "_trigRatio", "_fovH", "_fovV", "_fovVRads", "_configFov", "_zoom"];

_zoomRef = if (IS_SCALAR(_this)) then {_this} else {0.75};

_widthReal = safeZoneW / 2;
_safeZoneAspectRatio = (safeZoneW / safeZoneH);
_screenAspectRatio = _safeZoneAspectRatio * (4 / 3);

_pos = positionCameraToWorld [__xOff, 0, __dist];
_xPos = (worldToScreen _pos) select 0;
_deltaX = _xPos - 0.5;

_trigRatio = ((_widthReal * __xOff) / (__dist * _deltaX));
_fovH = 2 * atan _trigRatio;
_fovV = _fovH / _screenAspectRatio;
_fovVRads = _fovV * pi / 180;
_configFov = _trigRatio / _safeZoneAspectRatio;
_zoom = _zoomRef / _configFov;
private _zoomRef = if (IS_SCALAR(_this)) then {_this} else {0.75};

private _widthReal = safeZoneW / 2;
private _safeZoneAspectRatio = (safeZoneW / safeZoneH);
private _screenAspectRatio = _safeZoneAspectRatio * (4 / 3);

private _pos = positionCameraToWorld [__xOff, 0, __dist];
private _xPos = (worldToScreen _pos) select 0;
private _deltaX = _xPos - 0.5;

private _trigRatio = ((_widthReal * __xOff) / (__dist * _deltaX));
private _fovH = 2 * atan _trigRatio;
private _fovV = _fovH / _screenAspectRatio;
private _fovVRads = _fovV * pi / 180;
private _configFov = _trigRatio / _safeZoneAspectRatio;
private _zoom = _zoomRef / _configFov;

[_fovVRads, _zoom]
18 changes: 9 additions & 9 deletions addons/common/fnc_getTerrainProfile.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ _posA = _posA call CBA_fnc_getPos;
_posB = _posB call CBA_fnc_getPos;
_posA set [2,0]; _posB set [2,0];

DEFAULT_PARAM(2,_resolution,10);
DEFAULT_PARAM(2, _resolution,10);

private ["_angle", "_2Ddistance", "_return", "_z", "_adj", "_pos", "_alt"];
_angle = [_posA, _posB] call BIS_fnc_dirTo;
_2Ddistance = [_posA, _posB] call BIS_fnc_distance2D;
private _angle = [_posA, _posB] call BIS_fnc_dirTo;
private _2Ddistance = [_posA, _posB] call BIS_fnc_distance2D;

_logic = "logic" createvehiclelocal _posA;
private _logic = "logic" createvehiclelocal _posA;
_logic setPosATL _posA;
_z = (getPosASL _logic) select 2;
_return = [];
private _z = (getPosASL _logic) select 2;
private _return = [];
private _pos = [];

for "_i" from 0 to (_2Ddistance / _resolution) do {
_adj = _resolution * _i;
_pos = [_posA, _adj, _angle] call BIS_fnc_relPos;
_logic setPosATL _pos;
_alt = ((getPosASL _logic) select 2) - _z;
private _alt = ((getPosASL _logic) select 2) - _z;
_return set [_i,[_alt, _adj, _pos]];
};
_logic setPosATL _posB;
_alt = ((getPosASL _logic) select 2) - _z;
private _alt = ((getPosASL _logic) select 2) - _z;
_return pushBack [_alt, _2Ddistance, _pos];

deletevehicle _logic;
Expand Down
Loading

0 comments on commit 667299c

Please sign in to comment.