From 80349658d61515abdcfffbb8973946c3f14ee1d8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 25 Mar 2015 22:50:28 +0100 Subject: [PATCH 1/5] tweak turret functions --- addons/common/functions/fnc_getConfigCommander.sqf | 4 ++-- addons/common/functions/fnc_getConfigGunner.sqf | 4 ++-- addons/common/functions/fnc_getDoorTurrets.sqf | 10 +++++----- addons/common/functions/fnc_getTurretCommander.sqf | 6 +++--- addons/common/functions/fnc_getTurretCopilot.sqf | 6 +++--- addons/common/functions/fnc_getTurretGunner.sqf | 6 +++--- addons/common/functions/fnc_getTurretIndex.sqf | 1 - addons/common/functions/fnc_getTurretsFFV.sqf | 6 +++--- addons/common/functions/fnc_getTurretsOther.sqf | 6 +++--- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/addons/common/functions/fnc_getConfigCommander.sqf b/addons/common/functions/fnc_getConfigCommander.sqf index 5fca3af81c..4003c2a51f 100644 --- a/addons/common/functions/fnc_getConfigCommander.sqf +++ b/addons/common/functions/fnc_getConfigCommander.sqf @@ -4,7 +4,7 @@ * Get the commander config of a vehicles turret. * * Argument: - * 0: vehicle type (String) + * 0: vehicle (Object) * * Return value: * Commander config (Config) @@ -15,7 +15,7 @@ private ["_vehicle", "_config", "_turret"]; _vehicle = _this select 0; -_config = configFile >> "CfgVehicles" >> _vehicle; +_config = configFile >> "CfgVehicles" >> typeOf _vehicle; _turret = [_vehicle] call FUNC(getTurretCommander); [_config, _turret] call FUNC(getTurretConfigPath) diff --git a/addons/common/functions/fnc_getConfigGunner.sqf b/addons/common/functions/fnc_getConfigGunner.sqf index 0c09461a04..80bdfb2cfa 100644 --- a/addons/common/functions/fnc_getConfigGunner.sqf +++ b/addons/common/functions/fnc_getConfigGunner.sqf @@ -4,7 +4,7 @@ * Get the gunner config of a vehicles turret. * * Argument: - * 0: vehicle type (String) + * 0: vehicle (Object) * * Return value: * Gunner config (Config) @@ -15,7 +15,7 @@ private ["_vehicle", "_config", "_turret"]; _vehicle = _this select 0; -_config = configFile >> "CfgVehicles" >> _vehicle; +_config = configFile >> "CfgVehicles" >> typeOf _vehicle; _turret = [_vehicle] call FUNC(getTurretGunner); [_config, _turret] call FUNC(getTurretConfigPath) diff --git a/addons/common/functions/fnc_getDoorTurrets.sqf b/addons/common/functions/fnc_getDoorTurrets.sqf index eadaeb2000..cfa7e0532c 100644 --- a/addons/common/functions/fnc_getDoorTurrets.sqf +++ b/addons/common/functions/fnc_getDoorTurrets.sqf @@ -4,23 +4,23 @@ * Gets the turret index of door gunners * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret indexes of the door gunner. Empty array means no gunner position. (Array) */ #include "script_component.hpp" -private ["_vehicleType", "_turrets", "_doorTurrets", "_config"]; +private ["_vehicle", "_turrets", "_doorTurrets", "_config"]; -_vehicleType = _this select 0; +_vehicle = _this select 0; -_turrets = [_vehicleType] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _doorTurrets = []; { - _config = configFile >> "CfgVehicles" >> _vehicleType; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); if ((getNumber (_config >> "isCopilot") == 0) && count (getArray (_config >> "weapons")) > 0 ) then { diff --git a/addons/common/functions/fnc_getTurretCommander.sqf b/addons/common/functions/fnc_getTurretCommander.sqf index 4c2b1139c8..b26060b221 100644 --- a/addons/common/functions/fnc_getTurretCommander.sqf +++ b/addons/common/functions/fnc_getTurretCommander.sqf @@ -4,7 +4,7 @@ * Get the turret index of a vehicles commander. * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret index of the vehicles commander. Empty array means no observer position. (Array) @@ -15,11 +15,11 @@ private ["_vehicle", "_turrets", "_turret", "_config"]; _vehicle = _this select 0; -_turrets = [_vehicle] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _turret = []; { - _config = configFile >> "CfgVehicles" >> _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); diff --git a/addons/common/functions/fnc_getTurretCopilot.sqf b/addons/common/functions/fnc_getTurretCopilot.sqf index c2a7e81778..9f51f8724c 100644 --- a/addons/common/functions/fnc_getTurretCopilot.sqf +++ b/addons/common/functions/fnc_getTurretCopilot.sqf @@ -4,7 +4,7 @@ * Get the turret index of a vehicles copilot. * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret index of the vehicles gunner. Empty array means no copilot position. (Array) @@ -15,11 +15,11 @@ private ["_vehicle", "_turrets", "_turret", "_config"]; _vehicle = _this select 0; -_turrets = [_vehicle] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _turret = []; { - _config = configFile >> "CfgVehicles" >> _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); diff --git a/addons/common/functions/fnc_getTurretGunner.sqf b/addons/common/functions/fnc_getTurretGunner.sqf index fd1134dc83..ba1802c37f 100644 --- a/addons/common/functions/fnc_getTurretGunner.sqf +++ b/addons/common/functions/fnc_getTurretGunner.sqf @@ -4,7 +4,7 @@ * Get the turret index of a vehicles gunner. * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret index of the vehicles gunner. Empty array means no gunner position. (Array) @@ -15,11 +15,11 @@ private ["_vehicle", "_turrets", "_turret", "_config"]; _vehicle = _this select 0; -_turrets = [_vehicle] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _turret = []; { - _config = configFile >> "CfgVehicles" >> _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); diff --git a/addons/common/functions/fnc_getTurretIndex.sqf b/addons/common/functions/fnc_getTurretIndex.sqf index fd75d221fd..85d69b6828 100644 --- a/addons/common/functions/fnc_getTurretIndex.sqf +++ b/addons/common/functions/fnc_getTurretIndex.sqf @@ -18,7 +18,6 @@ _vehicle = vehicle _unit; if (_unit == _vehicle) exitWith {[]}; -//_turrets = [typeOf _vehicle] call FUNC(getTurrets); _turrets = allTurrets [_vehicle, true]; _units = []; diff --git a/addons/common/functions/fnc_getTurretsFFV.sqf b/addons/common/functions/fnc_getTurretsFFV.sqf index b09dfed027..f915d6c096 100644 --- a/addons/common/functions/fnc_getTurretsFFV.sqf +++ b/addons/common/functions/fnc_getTurretsFFV.sqf @@ -4,7 +4,7 @@ * Get the turret indices of ffv turrets. * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret index of the vehicles gunner. Empty array means no ffv turrets. (Array) @@ -15,11 +15,11 @@ private ["_vehicle", "_turrets", "_turret", "_config"]; _vehicle = _this select 0; -_turrets = [_vehicle] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _turret = []; { - _config = configFile >> "CfgVehicles" >> _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); diff --git a/addons/common/functions/fnc_getTurretsOther.sqf b/addons/common/functions/fnc_getTurretsOther.sqf index 53673b5a8d..102c1a9d1c 100644 --- a/addons/common/functions/fnc_getTurretsOther.sqf +++ b/addons/common/functions/fnc_getTurretsOther.sqf @@ -4,7 +4,7 @@ * Get the turret indices of other turrets (not gunner, commander, copilot or ffv). * * Argument: - * 0: Vehicle type (String) + * 0: Vehicle (Object) * * Return value: * Turret index of the vehicles gunner. Empty array means no other turrets. (Array) @@ -15,11 +15,11 @@ private ["_vehicle", "_turrets", "_turret", "_config"]; _vehicle = _this select 0; -_turrets = [_vehicle] call FUNC(getTurrets); +_turrets = allTurrets [_vehicle, true]; _turret = []; { - _config = configFile >> "CfgVehicles" >> _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _config = [_config, _x] call FUNC(getTurretConfigPath); From b613ab86304cf9eb6f24b1a73c2405fe071bb4c9 Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 25 Mar 2015 23:03:45 +0100 Subject: [PATCH 2/5] adjust functions to new syntax --- addons/common/functions/fnc_canGetInPosition.sqf | 10 +++++----- addons/common/functions/fnc_getInPosition.sqf | 10 +++++----- addons/fcs/functions/fnc_keyDown.sqf | 2 +- addons/fcs/functions/fnc_keyUp.sqf | 2 +- .../weaponselect/functions/fnc_fireSmokeLauncher.sqf | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/common/functions/fnc_canGetInPosition.sqf b/addons/common/functions/fnc_canGetInPosition.sqf index 859d8ed461..5ac4c527fd 100644 --- a/addons/common/functions/fnc_canGetInPosition.sqf +++ b/addons/common/functions/fnc_canGetInPosition.sqf @@ -69,7 +69,7 @@ switch (_position) do { case "gunner" : { private "_turretConfig"; - _turret = [typeOf _vehicle] call FUNC(getTurretGunner); + _turret = [_vehicle] call FUNC(getTurretGunner); if (_turret isEqualTo []) exitWith {false}; _turretConfig = [_config, _turret] call FUNC(getTurretConfigPath); @@ -82,7 +82,7 @@ switch (_position) do { case "commander" : { private "_turretConfig"; - _turret = [typeOf _vehicle] call FUNC(getTurretCommander); + _turret = [_vehicle] call FUNC(getTurretCommander); if (_turret isEqualTo []) exitWith {false}; _turretConfig = [_config, _turret] call FUNC(getTurretConfigPath); @@ -95,7 +95,7 @@ switch (_position) do { case "copilot" : { private "_turretConfig"; - _turret = [typeOf _vehicle] call FUNC(getTurretCopilot); + _turret = [_vehicle] call FUNC(getTurretCopilot); if (_turret isEqualTo []) exitWith {false}; _turretConfig = [_config, _turret] call FUNC(getTurretConfigPath); @@ -108,7 +108,7 @@ switch (_position) do { case "turret" : { private ["_turrets", "_turretConfig"]; - _turrets = [typeOf _vehicle] call FUNC(getTurretsOther); + _turrets = [_vehicle] call FUNC(getTurretsOther); if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX @@ -136,7 +136,7 @@ switch (_position) do { case "ffv" : { private ["_turrets", "_turretConfig"]; - _turrets = [typeOf _vehicle] call FUNC(getTurretsFFV); + _turrets = [_vehicle] call FUNC(getTurretsFFV); if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX diff --git a/addons/common/functions/fnc_getInPosition.sqf b/addons/common/functions/fnc_getInPosition.sqf index 0cfce1e124..062cc6cae4 100644 --- a/addons/common/functions/fnc_getInPosition.sqf +++ b/addons/common/functions/fnc_getInPosition.sqf @@ -64,7 +64,7 @@ switch (_position) do { }; case "gunner" : { - _turret = [typeOf _vehicle] call FUNC(getTurretGunner); + _turret = [_vehicle] call FUNC(getTurretGunner); if (CANGETINTURRETINDEX) then { _script = [ @@ -75,7 +75,7 @@ switch (_position) do { }; case "commander" : { - _turret = [typeOf _vehicle] call FUNC(getTurretCommander); + _turret = [_vehicle] call FUNC(getTurretCommander); if (CANGETINTURRETINDEX) then { _script = [ @@ -86,7 +86,7 @@ switch (_position) do { }; case "copilot" : { - _turret = [typeOf _vehicle] call FUNC(getTurretCopilot); + _turret = [_vehicle] call FUNC(getTurretCopilot); if (CANGETINTURRETINDEX) then { _script = [ @@ -100,7 +100,7 @@ switch (_position) do { case "turret" : { private "_turrets"; - _turrets = [typeOf _vehicle] call FUNC(getTurretsOther); + _turrets = [_vehicle] call FUNC(getTurretsOther); if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX}) then { _script = [ @@ -127,7 +127,7 @@ switch (_position) do { case "ffv" : { private "_turrets"; - _turrets = [typeOf _vehicle] call FUNC(getTurretsFFV); + _turrets = [_vehicle] call FUNC(getTurretsFFV); if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX}) then { _script = [ diff --git a/addons/fcs/functions/fnc_keyDown.sqf b/addons/fcs/functions/fnc_keyDown.sqf index 7699b82a20..8646ce8468 100644 --- a/addons/fcs/functions/fnc_keyDown.sqf +++ b/addons/fcs/functions/fnc_keyDown.sqf @@ -30,7 +30,7 @@ if (_distance == 0) then { _weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets -if (_turret isEqualTo ([typeOf _vehicle] call EFUNC(common,getTurretCommander))) then { +if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then { _weaponDirection = eyeDirection _vehicle; }; diff --git a/addons/fcs/functions/fnc_keyUp.sqf b/addons/fcs/functions/fnc_keyUp.sqf index 1e5878f0b5..d33bd08893 100644 --- a/addons/fcs/functions/fnc_keyUp.sqf +++ b/addons/fcs/functions/fnc_keyUp.sqf @@ -35,7 +35,7 @@ private ["_weaponDirection", "_angleTarget"]; _weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets -if (_turret isEqualTo ([typeOf _vehicle] call EFUNC(common,getTurretCommander))) then { +if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then { _weaponDirection = eyeDirection _vehicle; }; diff --git a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf index 14c86f78dd..6b58fc7bc5 100644 --- a/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf +++ b/addons/weaponselect/functions/fnc_fireSmokeLauncher.sqf @@ -5,7 +5,7 @@ private ["_vehicle", "_turret", "_weapons"]; _vehicle = _this select 0; -_turret = [typeOf _vehicle] call EFUNC(common,getTurretCommander); +_turret = [_vehicle] call EFUNC(common,getTurretCommander); _weapons = _vehicle weaponsTurret _turret; From cb29f1a6c9c738648e4463c0c3e7a7bb055a8faf Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 01:58:49 +0100 Subject: [PATCH 3/5] tweak, pushBack vs + Array --- addons/common/functions/fnc_hadamardProduct.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_hadamardProduct.sqf b/addons/common/functions/fnc_hadamardProduct.sqf index dd614f8dd0..db52a48d80 100644 --- a/addons/common/functions/fnc_hadamardProduct.sqf +++ b/addons/common/functions/fnc_hadamardProduct.sqf @@ -19,7 +19,7 @@ _vector2 = _this select 1; _newVector = []; for "_i" from 0 to (((count _vector1) min (count _vector2)) - 1) do { - _newVector = _newVector + [(_vector1 select _i) * (_vector2 select _i)]; + _newVector pushBack ((_vector1 select _i) * (_vector2 select _i)); }; _newVector From 6a0ca8590f406cdf5629a2b26c29367333ee4916 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 02:26:09 +0100 Subject: [PATCH 4/5] speed up some debug functions by 99.99% --- addons/common/functions/fnc_logControls.sqf | 13 +------------ addons/common/functions/fnc_logDisplays.sqf | 13 +------------ 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/addons/common/functions/fnc_logControls.sqf b/addons/common/functions/fnc_logControls.sqf index 5a0a17c317..5bcaea779b 100644 --- a/addons/common/functions/fnc_logControls.sqf +++ b/addons/common/functions/fnc_logControls.sqf @@ -1,15 +1,4 @@ // by commy2 #include "script_component.hpp" -private ["_array", "_index"]; - -_array = []; - -for "_index" from 0 to 10000 do { - if (str (findDisplay _this displayCtrl _index) != "No control") then { - diag_log text str (findDisplay _this displayCtrl _index); - _array pushBack _index; - }; -}; - -_array; +[allControls findDisplay _this, {ctrlIDC _this}] call FUNC(map) diff --git a/addons/common/functions/fnc_logDisplays.sqf b/addons/common/functions/fnc_logDisplays.sqf index 81598facf4..0ab4fbe5bc 100644 --- a/addons/common/functions/fnc_logDisplays.sqf +++ b/addons/common/functions/fnc_logDisplays.sqf @@ -1,15 +1,4 @@ // by commy2 #include "script_component.hpp" -private ["_array", "_index"]; - -_array = []; - -for "_index" from 0 to 10000 do { - if (str (findDisplay _index) != "No Display") then { - diag_log text str findDisplay _index; - _array pushBack _index; - }; -}; - -_array; +[allDisplays, {ctrlIDD _this}] call FUNC(map) From 91b63fbb7d8f5b12fa90b3f969e188ad6faacf88 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 03:20:17 +0100 Subject: [PATCH 5/5] tweaks --- .../common/functions/fnc_numberToDigits.sqf | 34 ++++++++----------- .../functions/fnc_numberToDigitsString.sqf | 24 +++++++++---- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/addons/common/functions/fnc_numberToDigits.sqf b/addons/common/functions/fnc_numberToDigits.sqf index 465955b455..fe62ab626b 100644 --- a/addons/common/functions/fnc_numberToDigits.sqf +++ b/addons/common/functions/fnc_numberToDigits.sqf @@ -12,33 +12,29 @@ */ #include "script_component.hpp" -private ["_number", "_minLength", "_length", "_digits", "_index", "_count"]; +private ["_number", "_minLength", "_length", "_digits"]; _number = _this select 0; _minLength = _this select 1; _number = _number min 999999; -_length = floor (log _number + 1); -if !(isNil "_minLength") then {_length = (_length max _minLength) min 6}; +_number = str _number; + +_length = count _number; + +if (isNil "_minLength") then {_minLength = _length}; + +_minLength = _minLength min 6; + +while {_length < _minLength} do { + _number = "0" + _number; + _length = _length + 1; +}; _digits = []; - -if (_number < 1) exitWith { - for "_index" from 0 to (_length - 1) do { - _digits set [_index, 0]; - }; - _digits +for "_x" from 0 to (_length - 1) do { + _digits pushBack parseNumber (_number select [_x, 1]); }; -while { - _count = count _digits; - _count < _length -} do { - _digit = floor (_number / (10 ^ (_length - _count - 1))); - { - _digit = _digit - _x * (10 ^ (_count - _forEachIndex)); - } forEach _digits; - _digits set [_count, _digit]; -}; _digits diff --git a/addons/common/functions/fnc_numberToDigitsString.sqf b/addons/common/functions/fnc_numberToDigitsString.sqf index db4e33e6cb..24b3791d68 100644 --- a/addons/common/functions/fnc_numberToDigitsString.sqf +++ b/addons/common/functions/fnc_numberToDigitsString.sqf @@ -12,14 +12,24 @@ */ #include "script_component.hpp" -private ["_digits", "_count", "_string", "_index"]; +private ["_number", "_minLength", "_length"]; -_digits = _this call FUNC(numberToDigits); +_number = _this select 0; +_minLength = _this select 1; -_count = count _digits; +_number = _number min 999999; -_string = ""; -for "_index" from 0 to (_count - 1) do { - _string = _string + str (_digits select _index); +_number = str _number; + +_length = count _number; + +if (isNil "_minLength") then {_minLength = _length}; + +_minLength = _minLength min 6; + +while {_length < _minLength} do { + _number = "0" + _number; + _length = _length + 1; }; -_string + +_number