From dfa6d71a641e2726a21e23b2d17baf78f6d272fb Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 00:55:58 +0200 Subject: [PATCH] more common code cleanup --- addons/common/functions/fnc_setProne.sqf | 2 + addons/common/functions/fnc_setVolume.sqf | 23 ++++---- addons/common/functions/fnc_showUser.sqf | 1 - .../functions/fnc_sortAlphabeticallyBy.sqf | 27 ++++++---- .../functions/fnc_stringRemoveWhiteSpace.sqf | 29 +++++----- .../functions/fnc_switchToGroupSide.sqf | 54 +++++++++++-------- addons/common/functions/fnc_targetEvent.sqf | 22 ++++---- addons/common/functions/fnc_timePFH.sqf | 17 ++++-- addons/common/functions/fnc_toBin.sqf | 7 ++- addons/common/functions/fnc_toBitmask.sqf | 6 +-- addons/common/functions/fnc_toHex.sqf | 18 ++++--- addons/common/functions/fnc_toNumber.sqf | 40 +++++++------- .../functions/fnc_translateToModelSpace.sqf | 31 ++++++----- .../functions/fnc_translateToWeaponSpace.sqf | 39 ++++++++------ 14 files changed, 181 insertions(+), 135 deletions(-) diff --git a/addons/common/functions/fnc_setProne.sqf b/addons/common/functions/fnc_setProne.sqf index ce61f923a2..75be8bac2d 100644 --- a/addons/common/functions/fnc_setProne.sqf +++ b/addons/common/functions/fnc_setProne.sqf @@ -9,6 +9,8 @@ * None * * Public: Yes + * + * Note: Not functional, because FUNC(localAnim) does no longer exist */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_setVolume.sqf b/addons/common/functions/fnc_setVolume.sqf index 133a09bd24..37e1f04cfa 100644 --- a/addons/common/functions/fnc_setVolume.sqf +++ b/addons/common/functions/fnc_setVolume.sqf @@ -1,21 +1,24 @@ -/** - * fn_setVolume_f.sqf - * @Descr: Sets the volume of the game, including third party radio modifications such as TFAR and ACRE. - * @Author: Glowbal +/* + * Author: Glowbal + * Sets the volume of the game, including third party radio modifications such as TFAR and ACRE. * - * @Arguments: [setVolume BOOL] - * @Return: void - * @PublicAPI: true + * Arguments: + * 0: setVolume (default: false) + * + * Return Value: + * None + * + * Public: Yes + * + * Note: Uses player */ - #include "script_component.hpp" #define MUTED_LEVEL 0.2 #define NORMAL_LEVEL 1 #define NO_SOUND 0 -private ["_setVolume"]; -_setVolume = [_this, 0, false, [false]] call BIS_fnc_Param; +params [["_setVolume", false]]; if (_setVolume) then { // Vanilla Game diff --git a/addons/common/functions/fnc_showUser.sqf b/addons/common/functions/fnc_showUser.sqf index 488dffbaa9..b783fb4ec5 100644 --- a/addons/common/functions/fnc_showUser.sqf +++ b/addons/common/functions/fnc_showUser.sqf @@ -1,6 +1,5 @@ /* * Author: commy2 - * * hint the Variable ACE_isUsedBy from the input Object every frame * * Argument: diff --git a/addons/common/functions/fnc_sortAlphabeticallyBy.sqf b/addons/common/functions/fnc_sortAlphabeticallyBy.sqf index db142b01b6..3380b181c8 100644 --- a/addons/common/functions/fnc_sortAlphabeticallyBy.sqf +++ b/addons/common/functions/fnc_sortAlphabeticallyBy.sqf @@ -1,18 +1,22 @@ -/** - * fn_sortAlphabeticallyBy.sqf - * @Descr: - * @Author: Glowbal +/* + * Author: Glowbal + * ? deprecated * - * @Arguments: [] - * @Return: - * @PublicAPI: true + * Arguments: + * ? + * + * Return Value: + * ? + * + * Public: Yes + * + * Deprecated */ - #include "script_component.hpp" -private ["_elements","_indexes", "_theElement", "_tmp", "_tempIndex", "_j", "_i", "_returnArray"]; +params ["_array", "_elementN"]; -PARAMS_2(_array,_elementN); +private ["_elements", "_indexes", "_theElement", "_tmp", "_tempIndex", "_returnArray"]; _indexes = []; _elements = []; @@ -37,8 +41,9 @@ for "_i" from 1 to (count _elements) - 1 do { }; _returnArray = []; + { _returnArray pushback (_array select _x); } forEach _indexes; -_returnArray; \ No newline at end of file +_returnArray diff --git a/addons/common/functions/fnc_stringRemoveWhiteSpace.sqf b/addons/common/functions/fnc_stringRemoveWhiteSpace.sqf index 19ca13de3b..7caf8cdf9f 100644 --- a/addons/common/functions/fnc_stringRemoveWhiteSpace.sqf +++ b/addons/common/functions/fnc_stringRemoveWhiteSpace.sqf @@ -1,21 +1,26 @@ -/** - * fn_stringTrim.sqf - * @Descr: Removes white spaces from string - * @Author: Glowbal +/* + * Author: Glowbal + * Removes white spaces from string * - * @Arguments: [string STRING] - * @Return: STRING copy of string - * @PublicAPI: true + * Arguments: + * 0: stringA + * 1: stringB + * + * Return Value: + * copy of string + * + * Public: Yes + * + * Deprecated */ - #include "script_component.hpp" -#define WHITE_SPACE [20] +params ["_string", ""]; + +private ["_charArray", "_returnString"]; -private ["_string", "_charArray", "_returnString"]; -_string = [_this, 0, "",[""]] call bis_fnc_param; _charArray = toArray _string; _charArray = _charArray - [((toArray " ") select 0)]; _returnString = toString _charArray; -_returnString; \ No newline at end of file +_returnString diff --git a/addons/common/functions/fnc_switchToGroupSide.sqf b/addons/common/functions/fnc_switchToGroupSide.sqf index 528d32853c..95f17a9c7b 100644 --- a/addons/common/functions/fnc_switchToGroupSide.sqf +++ b/addons/common/functions/fnc_switchToGroupSide.sqf @@ -1,45 +1,53 @@ -/** - * fn_switchToGroupSide_f.sqf - * @Descr: Stack group switches. Will always trace back to original group. - * @Author: Glowbal +/* + * Author: Glowbal + * Stack group switches. Will always trace back to original group. * - * @Arguments: [unit OBJECT, switch BOOL, id STRING, side SIDE] - * @Return: void - * @PublicAPI: true + * Arguments: + * 0: Unit + * 1: switch + * 2: id + * 3: side + * + * Return Value: + * None + * + * Public: Yes */ - #include "script_component.hpp" -private ["_unit","_side","_previousGroup","_newGroup", "_currentGroup", "_switch", "_originalSide", "_previousGroupsList", "_id"]; -_unit = [_this, 0,ObjNull,[ObjNull]] call BIS_fnc_Param; -_switch = [_this, 1, false,[false]] call BIS_fnc_Param; -_id = [_this, 2, "", [""]] call BIS_fnc_Param; -_side = [_this, 3, side _unit,[west]] call BIS_fnc_Param; +params [["_unit", objNull], ["_switch", false], ["_id", ""], ["_side", side _unit]]; + +private "_previousGroupsList"; +_previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo), []]; -_previousGroupsList = _unit getvariable [QGVAR(previousGroupSwitchTo),[]]; if (_switch) then { // go forward + private ["_previousGroup", "_originalSide", "_newGroup"]; + _previousGroup = group _unit; _originalSide = side group _unit; if (count units _previousGroup == 1 && _originalSide == _side) exitwith { - [format["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug); + [format ["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug); }; _newGroup = createGroup _side; [_unit] joinSilent _newGroup; - _previousGroupsList pushback [_previousGroup, _originalSide, _id, true]; - _unit setvariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true]; + _previousGroupsList pushBack [_previousGroup, _originalSide, _id, true]; + _unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true]; } else { // go one back + private ["_currentGroup", "_newGroup"]; + { if (_id == (_x select 2)) exitwith { _x set [ 3, false]; - _previousGroupsList set [_foreachIndex, _x]; + _previousGroupsList set [_forEachIndex, _x]; [format["found group with ID: %1", _id]] call FUNC(debug); }; - }foreach _previousGroupsList; + } forEach _previousGroupsList; + reverse _previousGroupsList; { @@ -55,10 +63,12 @@ if (_switch) then { if (count units _currentGroup == 0) then { deleteGroup _currentGroup; }; - _previousGroupsList set [_foreachIndex, ObjNull]; + _previousGroupsList set [_forEachIndex, objNull]; }; - }foreach _previousGroupsList; + } forEach _previousGroupsList; + _previousGroupsList = _previousGroupsList - [objNull]; reverse _previousGroupsList; // we have to reverse again, to ensure the list is in the right order. - _unit setvariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true]; + + _unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true]; }; diff --git a/addons/common/functions/fnc_targetEvent.sqf b/addons/common/functions/fnc_targetEvent.sqf index 75023a38b5..b9802f0835 100644 --- a/addons/common/functions/fnc_targetEvent.sqf +++ b/addons/common/functions/fnc_targetEvent.sqf @@ -1,24 +1,23 @@ /* * Author: Nou - * * Execute a event only on specific clients. * - * Argument: - * 0: Event name (string) - * 1: Event targets (object or array of objects) - * 2: Event args (any) + * Arguments: + * 0: Event name (STRING) + * 1: Event targets + * 2: Event args * * Note: If local executor is in list of targets, event will execute with * network delay, and not immediatly. * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ #include "script_component.hpp" -//IGNORE_PRIVATE_WARNING("_handleNetEvent"); - -PARAMS_3(_eventName,_eventTargets,_eventArgs); +params ["_eventName", "_eventTargets", "_eventArgs"]; #ifdef DEBUG_EVENTS ACE_LOGINFO_2("* Target Event: %1 - %2",_eventName,_eventTargets); @@ -26,7 +25,8 @@ PARAMS_3(_eventName,_eventTargets,_eventArgs); #endif ACEc = [_eventName, _eventTargets, _eventArgs]; -if(!isServer) then { + +if (!isServer) then { publicVariableServer "ACEc"; } else { ["ACEc", ACEc] call FUNC(_handleNetEvent); diff --git a/addons/common/functions/fnc_timePFH.sqf b/addons/common/functions/fnc_timePFH.sqf index 40fef519a8..1c66974c0d 100644 --- a/addons/common/functions/fnc_timePFH.sqf +++ b/addons/common/functions/fnc_timePFH.sqf @@ -1,7 +1,18 @@ -//#define DEBUG_MODE_FULL +/* + * Author: ? + * ? + * + * Arguments: + * ? + * + * Return Value: + * ? + * + * Public: ? + */ #include "script_component.hpp" -private["_lastTickTime", "_lastGameTime", "_delta"]; +private ["_lastTickTime", "_lastGameTime", "_delta"]; _lastTickTime = ACE_diagTime; _lastGameTime = ACE_gameTime; @@ -10,7 +21,7 @@ ACE_gameTime = time; ACE_diagTime = diag_tickTime; _delta = ACE_diagTime - _lastTickTime; -if(ACE_gameTime <= _lastGameTime) then { +if (ACE_gameTime <= _lastGameTime) then { TRACE_1("paused",_delta); ACE_paused = true; // Game is paused or not running diff --git a/addons/common/functions/fnc_toBin.sqf b/addons/common/functions/fnc_toBin.sqf index 5afc311511..9f3296597d 100644 --- a/addons/common/functions/fnc_toBin.sqf +++ b/addons/common/functions/fnc_toBin.sqf @@ -1,13 +1,12 @@ /* * Author: commy2 - * * Converts number to binary number * * Arguments: - * A number + * A number * * Return Value: - * A binary number, String + * A binary number as string * * Public: Yes */ @@ -32,4 +31,4 @@ while {count toArray _bin < _minLength} do { _bin = "0" + _bin; }; -_sign + _bin +_sign + _bin // return diff --git a/addons/common/functions/fnc_toBitmask.sqf b/addons/common/functions/fnc_toBitmask.sqf index 80d671741d..7c6beba733 100644 --- a/addons/common/functions/fnc_toBitmask.sqf +++ b/addons/common/functions/fnc_toBitmask.sqf @@ -1,13 +1,12 @@ /* * Author: commy2 - * * Convert an array of booleans into a number. * * Arguments: - * N: Booleans + * N: Booleans * * Return Value: - * Bitmask (Number) + * Bitmask * * Public: Yes */ @@ -18,6 +17,7 @@ private ["_array", "_result"]; _array = _this; _result = 0; + { if (_x) then {_result = _result + 2 ^ _forEachIndex}; } forEach _array; diff --git a/addons/common/functions/fnc_toHex.sqf b/addons/common/functions/fnc_toHex.sqf index 216d7a5c67..80d8757b80 100644 --- a/addons/common/functions/fnc_toHex.sqf +++ b/addons/common/functions/fnc_toHex.sqf @@ -1,26 +1,28 @@ /* * Author: commy2, esteldunedain - * * Converts number to hexadecimal number * * Arguments: * A number between 0 and 255 * * Return Value: - * A hexadecimal number, + * A hexadecimal number as string * * Public: Yes */ #include "script_component.hpp" -private ["_number"]; -_number = ((round abs (_this select 0)) max 0) min 255; +params ["_number"]; + +_number = ((round abs _number) max 0) min 255; if (isNil QGVAR(hexArray)) then { - private ["_minLength", "_i", "_num", "_hex", "_rest"]; - GVAR(hexArray) = []; + + private ["_minLength", "_num", "_hex", "_rest"]; + _minLength = 2; + for [{_i = 0;}, {_i < 256}, {_i = _i + 1}] do { _num = _i; _hex = ["", "0"] select (_i == 0); @@ -39,11 +41,13 @@ if (isNil QGVAR(hexArray)) then { _num = floor (_num / 16); _hex = _rest + _hex; }; + while {count toArray _hex < _minLength} do { _hex = "0" + _hex; }; + GVAR(hexArray) pushBack _hex; }; }; -(GVAR(hexArray) select _number) +GVAR(hexArray) select _number // return diff --git a/addons/common/functions/fnc_toNumber.sqf b/addons/common/functions/fnc_toNumber.sqf index 55a9ba2787..56d14f6d18 100644 --- a/addons/common/functions/fnc_toNumber.sqf +++ b/addons/common/functions/fnc_toNumber.sqf @@ -1,25 +1,23 @@ /* - Name: FUNC(toNumber) - - Author(s): - Garth de Wet (LH) - - Description: - Takes a string/number and returns the number. - - Parameters: - 0: TYPE - Value to attempt to convert to number or if number simply return number. - - Returns: - NUMBER - - Example: - number = ["102"] call FUNC(toNumber); -*/ + * Author: Garth de Wet (LH) + * + * Takes a string/number and returns the number. + * + * Arguments: + * 0: Value to attempt to convert to number or if number simply return number. + * + * Return Value: + * + * + * Example: + * number = ["102"] call ace_common_fnc_toNumber; + * + * Public: Yes + */ #include "script_component.hpp" -if (typeName (_this select 0) == "SCALAR") exitWith { - (_this select 0) -}; +params ["_value"]; -(parseNumber (_this select 0)) \ No newline at end of file +if (typeName _value == "SCALAR") exitWith {_value}; + +parseNumber _value // return diff --git a/addons/common/functions/fnc_translateToModelSpace.sqf b/addons/common/functions/fnc_translateToModelSpace.sqf index d2dfa38643..578feb8d5b 100644 --- a/addons/common/functions/fnc_translateToModelSpace.sqf +++ b/addons/common/functions/fnc_translateToModelSpace.sqf @@ -1,20 +1,25 @@ +/* + * Author: ? + * + * ? + * + * Arguments: + * ? + * + * Return Value: + * ? + * + * Public: ? + */ #include "script_component.hpp" -private["_matrix", "_object", "_offset", "_origin", "_out", "_xVec", "_y", "_yVec", "_z", "_zVec"]; +params ["_object", "_matrix", "_offset"]; -_object = _this select 0; +private "_origin"; _origin = getPosASL _object; -_matrix = _this select 1; -_xVec = _matrix select 0; -_yVec = _matrix select 1; -_zVec = _matrix select 2; -_offset = _this select 2; +_matrix params ["_xVec", "_yVec", "_zVec"]; -_x = _offset select 0; -_y = _offset select 1; -_z = _offset select 2; +_offset params ["_x", "_y", "_z"]; -_out = (((_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y)) vectorAdd (_zVec vectorMultiply _z)) vectorAdd _origin; - -_out; \ No newline at end of file +(_xVec vectorMultiply _x) vectorAdd (_yVec vectorMultiply _y) vectorAdd (_zVec vectorMultiply _z) vectorAdd _origin // return diff --git a/addons/common/functions/fnc_translateToWeaponSpace.sqf b/addons/common/functions/fnc_translateToWeaponSpace.sqf index ca1544b317..a226265987 100644 --- a/addons/common/functions/fnc_translateToWeaponSpace.sqf +++ b/addons/common/functions/fnc_translateToWeaponSpace.sqf @@ -1,26 +1,31 @@ +/* + * Author: ? + * + * ? + * + * Arguments: + * ? + * + * Return Value: + * ? + * + * Public: ? + */ #include "script_component.hpp" -private["_matrix", "_object", "_offset", "_origin", "_out", "_xVec", "_y", "_yVec", "_z", "_zVec"]; +params ["_object", "_matrix", "_offset"]; -_object = _this select 0; +private "_origin"; _origin = getPosASL _object; -_matrix = _this select 1; -_xVec = _matrix select 0; -_yVec = _matrix select 1; -_zVec = _matrix select 2; -_offset = _this select 2; +_matrix params ["_xVec", "_yVec", "_zVec"]; _offset = _offset vectorDiff _origin; -_x = _offset select 0; -_y = _offset select 1; -_z = _offset select 2; +_offset params ["_x", "_y", "_z"]; -_out = [ - ((_xVec select 0)*_x) + ((_xVec select 1)*_y) + ((_xVec select 2)*_z), - ((_yVec select 0)*_x) + ((_yVec select 1)*_y) + ((_yVec select 2)*_z), - ((_zVec select 0)*_x) + ((_zVec select 1)*_y) + ((_zVec select 2)*_z) - ]; - -_out; \ No newline at end of file +[ + ((_xVec select 0) * _x) + ((_xVec select 1) * _y) + ((_xVec select 2) * _z), + ((_yVec select 0) * _x) + ((_yVec select 1) * _y) + ((_yVec select 2) * _z), + ((_zVec select 0) * _x) + ((_zVec select 1) * _y) + ((_zVec select 2) * _z) +] // return