From 36a279012c6eb90e4902de925e2e9e07b759e5f7 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 17 Sep 2015 18:25:02 +0200 Subject: [PATCH] cleanup common --- addons/common/functions/fnc_ASLToPosition.sqf | 6 +- addons/common/functions/fnc_monitor.sqf | 27 +++-- .../common/functions/fnc_numberToDigits.sqf | 18 ++-- .../functions/fnc_numberToDigitsString.sqf | 14 +-- .../common/functions/fnc_numberToString.sqf | 17 ++-- addons/common/functions/fnc_owned.sqf | 5 +- addons/common/functions/fnc_player.sqf | 4 +- addons/common/functions/fnc_playerSide.sqf | 14 ++- addons/common/functions/fnc_setName.sqf | 16 +-- addons/common/functions/fnc_showUser.sqf | 24 ++++- .../functions/fnc_stringToColoredText.sqf | 25 ++--- addons/common/functions/fnc_toBin.sqf | 29 +++--- addons/common/functions/fnc_toBitmask.sqf | 8 +- addons/common/functions/fnc_toHex.sqf | 23 ++--- addons/common/functions/fnc_unhideUnit.sqf | 8 +- addons/common/functions/fnc_unmuteUnit.sqf | 14 +-- .../common/functions/fnc_waitAndExecute.sqf | 12 +-- addons/common/functions/fnc_waveHeightAt.sqf | 10 +- .../functions/fnc_worldToScreenBounds.sqf | 99 ++++++++++++------- addons/common/functions/script_component.hpp | 2 +- 20 files changed, 225 insertions(+), 150 deletions(-) diff --git a/addons/common/functions/fnc_ASLToPosition.sqf b/addons/common/functions/fnc_ASLToPosition.sqf index 4ff880c019..a5afb1db75 100644 --- a/addons/common/functions/fnc_ASLToPosition.sqf +++ b/addons/common/functions/fnc_ASLToPosition.sqf @@ -3,9 +3,9 @@ * Converts ASL to Arma "Position" * * Arguments: - * 0: position x - * 1: position y - * 2: position z + * 0: position x + * 1: position y + * 2: position z * * Return Value: * None diff --git a/addons/common/functions/fnc_monitor.sqf b/addons/common/functions/fnc_monitor.sqf index f77aa2dd7c..a05abb68c4 100644 --- a/addons/common/functions/fnc_monitor.sqf +++ b/addons/common/functions/fnc_monitor.sqf @@ -1,11 +1,22 @@ -// by commy2 +/* + * Author: commy2 + * + * hint retun value of given function every frame + * + * Argument: + * + * + * Return Value: + * None + * + * Public: Yes + */ #include "script_component.hpp" -terminate (missionNamespace getVariable [QGVAR(MonitorFnc), scriptNull]); - -GVAR(MonitorFnc) = _this spawn { - waitUntil { - hintSilent str (call _this); - false - }; +if (!isNil QGVAR(MonitorFnc)) then { + [GVAR(MonitorFnc)] call CBA_fnc_removePerFrameHandler; }; + +GVAR(MonitorFnc) = [{ + hintSilent str (call (_this select 0)); +}, 0, _this] call CBA_fnc_addPerFrameHandler; diff --git a/addons/common/functions/fnc_numberToDigits.sqf b/addons/common/functions/fnc_numberToDigits.sqf index 3545b53257..851ce1bb48 100644 --- a/addons/common/functions/fnc_numberToDigits.sqf +++ b/addons/common/functions/fnc_numberToDigits.sqf @@ -3,23 +3,23 @@ * * Transforms a number to an array of the correspondending digits. * - * Argument: - * 0: Number to 'digitize' (Number) - * 1: Set the minimal length of the returned array. Useful for getting left hand zeroes. (Number, optional) + * Arguments: + * 0: Number to 'digitize' + * 1: Set the minimal length of the returned array. Useful for getting left hand zeroes. , optional * - * Return value: + * Return Value: * Digits. The maximum count is six digits. (Array) + * + * Public: Yes */ #include "script_component.hpp" -private ["_length", "_digits"]; - -PARAMS_2(_number,_minLength); +params ["_number", "_minLength"]; _number = _number min 999999; - _number = str _number; +private "_length"; _length = count _number; if (isNil "_minLength") then {_minLength = _length}; @@ -31,7 +31,9 @@ while {_length < _minLength} do { _length = _length + 1; }; +private "_digits"; _digits = []; + for "_x" from 0 to (_length - 1) do { _digits pushBack parseNumber (_number select [_x, 1]); }; diff --git a/addons/common/functions/fnc_numberToDigitsString.sqf b/addons/common/functions/fnc_numberToDigitsString.sqf index e42f246460..b507545573 100644 --- a/addons/common/functions/fnc_numberToDigitsString.sqf +++ b/addons/common/functions/fnc_numberToDigitsString.sqf @@ -3,23 +3,23 @@ * * Transforms a number to an string of the correspondending digits. * - * Argument: - * 0: Number to 'digitize' (Number) + * Arguments: + * 0: Number to 'digitize' * 1: Set the minimal length of the returned string. Useful for getting left hand zeroes. (Number, optional) * - * Return value: + * Return Value: * Digits. The maximum length is six digits. (String) + * + * Public: Yes */ #include "script_component.hpp" -private ["_length"]; - -PARAMS_2(_number,_minLength); +params ["_number", "_minLength"]; _number = _number min 999999; - _number = str _number; +private "_length"; _length = count _number; if (isNil "_minLength") then {_minLength = _length}; diff --git a/addons/common/functions/fnc_numberToString.sqf b/addons/common/functions/fnc_numberToString.sqf index 30efcd8955..4e11668cd8 100644 --- a/addons/common/functions/fnc_numberToString.sqf +++ b/addons/common/functions/fnc_numberToString.sqf @@ -3,23 +3,24 @@ * * Converts a number to a string without losing as much precission as str or format. * - * Argument: - * 0: A number (Number) + * Arguments: + * 0: A number * - * Return value: + * Return Value: * The number as string (String) + * + * Public: Yes */ #include "script_component.hpp" -private ["_decimals"]; +params ["_number"]; -PARAMS_1(_number); - -_decimals = str (abs(_number) mod 1); +private "_decimals"; +_decimals = str (abs _number mod 1); _decimals = toArray _decimals; _decimals deleteAt 0; if (_number < 0) exitWith { - format ["-%1%2", floor abs(_number), toString _decimals]; + format ["-%1%2", floor abs _number, toString _decimals]; }; format ["%1%2", floor _number, toString _decimals]; diff --git a/addons/common/functions/fnc_owned.sqf b/addons/common/functions/fnc_owned.sqf index b76edb31c1..d94e3975db 100644 --- a/addons/common/functions/fnc_owned.sqf +++ b/addons/common/functions/fnc_owned.sqf @@ -4,14 +4,15 @@ * Counterpart of ace_common_fnc_claim. Check if the given object is claimed by another unit. * * Arguments: - * 0: Any object. (Object) + * 0: Any object. * * Return Value: * Is this object claimed by someone? * + * Public: No */ #include "script_component.hpp" -PARAMS_1(_target); +params ["_target"]; !isNull (_target getVariable [QGVAR(owner), objNull]) diff --git a/addons/common/functions/fnc_player.sqf b/addons/common/functions/fnc_player.sqf index 3e5990f84b..5f6f272e5e 100644 --- a/addons/common/functions/fnc_player.sqf +++ b/addons/common/functions/fnc_player.sqf @@ -8,7 +8,9 @@ * NONE. * * Return Value: - * Player controlled unit (object) + * Player controlled unit + * + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_playerSide.sqf b/addons/common/functions/fnc_playerSide.sqf index 632cf11abf..a264e82942 100644 --- a/addons/common/functions/fnc_playerSide.sqf +++ b/addons/common/functions/fnc_playerSide.sqf @@ -1,4 +1,16 @@ -// by commy2 +/* + * Author: commy2 + * + * Return the current side of the player + * + * Arguments: + * None + * + * Return Value: + * current local side (Side) + * + * Public: Yes + */ #include "script_component.hpp" side group ACE_player diff --git a/addons/common/functions/fnc_setName.sqf b/addons/common/functions/fnc_setName.sqf index 980408fb12..8a32dd669d 100644 --- a/addons/common/functions/fnc_setName.sqf +++ b/addons/common/functions/fnc_setName.sqf @@ -3,23 +3,23 @@ * * Sets the name variable of the object. Used to prevent issues with the name command. * - * Argument: - * 0: Object (Object) + * Arguments: + * 0: Object * - * Return value: - * Nothing. + * Return Value: + * None + * + * Public: No */ #include "script_component.hpp" -private ["_name"]; - -PARAMS_1(_unit); +params ["_unit"]; if (isNull _unit || {!alive _unit}) exitWith {}; if (_unit isKindOf "CAManBase") then { _name = [name _unit, true] call FUNC(sanitizeString); - + //if (_name != _unit getVariable ["ACE_Name", ""]) then { _unit setVariable ["ACE_Name", _name, true]; //}; diff --git a/addons/common/functions/fnc_showUser.sqf b/addons/common/functions/fnc_showUser.sqf index a88d39ce0d..488dffbaa9 100644 --- a/addons/common/functions/fnc_showUser.sqf +++ b/addons/common/functions/fnc_showUser.sqf @@ -1,8 +1,22 @@ -// by commy2 +/* + * Author: commy2 + * + * hint the Variable ACE_isUsedBy from the input Object every frame + * + * Argument: + * + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -GVAR(Debug_Object) = _this select 0; - -onEachFrame { - hintSilent str (GVAR(Debug_Object) getVariable ["ACE_isUsedBy", objNull]); +if (!isNil QGVAR(showUserPFH)) then { + [GVAR(showUserPFH)] call CBA_fnc_removePerFrameHandler; }; + +GVAR(showUserPFH) = [{ + hintSilent str ((_this select 0) getVariable ["ACE_isUsedBy", objNull]); +}, 0, _this] call CBA_fnc_addPerFrameHandler; diff --git a/addons/common/functions/fnc_stringToColoredText.sqf b/addons/common/functions/fnc_stringToColoredText.sqf index 4f6b1e7143..5cbf280320 100644 --- a/addons/common/functions/fnc_stringToColoredText.sqf +++ b/addons/common/functions/fnc_stringToColoredText.sqf @@ -3,26 +3,27 @@ * * Create a centered, colored text. * - * Argument: - * 0: Text (Anything) - * 2: Color (Array) + * Arguments: + * 0: Text + * 1: Color * - * Return value: - * Text + * Return Value: + * Text + * + * Public: Yes */ #include "script_component.hpp" -private ["_string", "_color"]; +params ["_string", "_color"]; -_string = format ["%1", _this select 0]; -_color = _this select 1; +_string = format ["%1", _string]; _color = ( - [255 * (_color select 0), 2] call FUNC(toHex) + [255 * (_color select 0), 2] call FUNC(toHex) ) + ( - [255 * (_color select 1), 2] call FUNC(toHex) + [255 * (_color select 1), 2] call FUNC(toHex) ) + ( - [255 * (_color select 2), 2] call FUNC(toHex) + [255 * (_color select 2), 2] call FUNC(toHex) ); -parseText format ["%1", _string, _color]; +parseText format ["%1", _string, _color] diff --git a/addons/common/functions/fnc_toBin.sqf b/addons/common/functions/fnc_toBin.sqf index 7c666f2f73..5afc311511 100644 --- a/addons/common/functions/fnc_toBin.sqf +++ b/addons/common/functions/fnc_toBin.sqf @@ -1,23 +1,22 @@ /* -Author: commy2 - -Description: -Converts number to binary number - -Arguments: -A number - -Return Value: -A binary number, String -*/ + * Author: commy2 + * + * Converts number to binary number + * + * Arguments: + * A number + * + * Return Value: + * A binary number, String + * + * Public: Yes + */ #include "script_component.hpp" +params ["_number", ["_minLength", 1]]; + private ["_sign", "_bin", "_rest"]; -PARAMS_2(_number,_minLength); - -if (isNil "_minLength") then {_minLength = 1}; - _sign = ["", "-"] select (_number < 0); _number = round abs _number; diff --git a/addons/common/functions/fnc_toBitmask.sqf b/addons/common/functions/fnc_toBitmask.sqf index 14ddb90541..80d671741d 100644 --- a/addons/common/functions/fnc_toBitmask.sqf +++ b/addons/common/functions/fnc_toBitmask.sqf @@ -3,11 +3,13 @@ * * Convert an array of booleans into a number. * - * Argument: - * 0: Booleans (Array of Booleans) + * Arguments: + * N: Booleans * - * Return value: + * Return Value: * Bitmask (Number) + * + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_toHex.sqf b/addons/common/functions/fnc_toHex.sqf index 2d7d7a383e..216d7a5c67 100644 --- a/addons/common/functions/fnc_toHex.sqf +++ b/addons/common/functions/fnc_toHex.sqf @@ -1,15 +1,16 @@ /* -Author: commy2, esteldunedain - -Description: -Converts number to hexadecimal number - -Arguments: -A number between 0 and 255 - -Return Value: -A hexadecimal number, String -*/ + * Author: commy2, esteldunedain + * + * Converts number to hexadecimal number + * + * Arguments: + * A number between 0 and 255 + * + * Return Value: + * A hexadecimal number, + * + * Public: Yes + */ #include "script_component.hpp" private ["_number"]; diff --git a/addons/common/functions/fnc_unhideUnit.sqf b/addons/common/functions/fnc_unhideUnit.sqf index 190be47664..488c4475fd 100644 --- a/addons/common/functions/fnc_unhideUnit.sqf +++ b/addons/common/functions/fnc_unhideUnit.sqf @@ -1,5 +1,6 @@ /* * Author: SilentSpike (based on unmuteUnit) + * * Globally unhides a unit. Only unhides if the last reason was removed. * * Arguments: @@ -7,17 +8,16 @@ * 1: Reason to unhide the unit * * Return Value: - * nil + * None * * Example: * [ACE_Player, "SpectatorMode"] call ace_common_fnc_unhideUnit * - * Public: No + * Public: Yes */ - #include "script_component.hpp" -PARAMS_2(_unit,_reason); +params ["_unit", "_reason"]; if (isNull _unit) exitWith {}; diff --git a/addons/common/functions/fnc_unmuteUnit.sqf b/addons/common/functions/fnc_unmuteUnit.sqf index 24b74785de..e234cb80db 100644 --- a/addons/common/functions/fnc_unmuteUnit.sqf +++ b/addons/common/functions/fnc_unmuteUnit.sqf @@ -3,16 +3,18 @@ * * Unmutes the unit. Only unmutes if the last reason was removed. * - * Argument: - * 0: Unit (Object) - * 1: Reason to unmute the unit. (String) + * Arguments: + * 0: Unit + * 1: Reason to unmute the unit. * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ #include "script_component.hpp" -PARAMS_2(_unit,_reason); +params ["_unit", "_reason"]; if (isNull _unit) exitWith {}; diff --git a/addons/common/functions/fnc_waitAndExecute.sqf b/addons/common/functions/fnc_waitAndExecute.sqf index 977e4f146d..6fcf83a58f 100644 --- a/addons/common/functions/fnc_waitAndExecute.sqf +++ b/addons/common/functions/fnc_waitAndExecute.sqf @@ -3,12 +3,12 @@ * * Executes a code once with a given game ACE_time delay, using a PFH * - * Argument: - * 0: Code to execute (Code) - * 1: Parameters to run the code with (Array) - * 2: Delay in seconds before executing the code (Number) + * Arguments: + * 0: Code to execute + * 1: Parameters to run the code with + * 2: Delay in seconds before executing the code * - * Return value: + * Return Value: * None * * Example: @@ -18,7 +18,7 @@ */ #include "script_component.hpp" -PARAMS_3(_func,_params,_delay); +params ["_func", "_params", "_delay"]; GVAR(waitAndExecArray) pushBack [(ACE_time + _delay), _func, _params]; GVAR(waitAndExecArray) sort true; diff --git a/addons/common/functions/fnc_waveHeightAt.sqf b/addons/common/functions/fnc_waveHeightAt.sqf index e05e4219b7..ac9eed10bb 100644 --- a/addons/common/functions/fnc_waveHeightAt.sqf +++ b/addons/common/functions/fnc_waveHeightAt.sqf @@ -9,12 +9,16 @@ * Return Value: * Wave height in meters * + * + * Public: No */ #include "script_component.hpp" -if(isNil QGVAR(waveHeightLogic)) then { +params ["_position"]; + +if (isNil QGVAR(waveHeightLogic)) then { GVAR(waveHeightLogic) = "Logic" createVehicleLocal [0,0,0]; }; -GVAR(waveHeightLogic) setPosASL (_this select 0); +GVAR(waveHeightLogic) setPosASL _position; -(((getPosASLW GVAR(waveHeightLogic)) select 2) - ((getPosASL GVAR(waveHeightLogic)) select 2)) \ No newline at end of file +(getPosASLW GVAR(waveHeightLogic) select 2) - (getPosASL GVAR(waveHeightLogic) select 2) diff --git a/addons/common/functions/fnc_worldToScreenBounds.sqf b/addons/common/functions/fnc_worldToScreenBounds.sqf index b3b5ba3f1e..2de07c7bbd 100644 --- a/addons/common/functions/fnc_worldToScreenBounds.sqf +++ b/addons/common/functions/fnc_worldToScreenBounds.sqf @@ -1,53 +1,76 @@ -// (c) zGuba 2011 -// Function helper for framing objects on screen. -// Input: [_object,_margins3D,_offset3D] (object, 3 * float array, 3 * float array) -// Output: [_minX,_minY,_minY,_maxY] (4 * float) - +/* + * Author: zGuba 2011 + * + * Function helper for framing objects on screen. + * + * Arguments: + * 0: object + * 1: margins 3D + * 0: X + * 1: Y + * 2: Z + * 2: offset 3D + * 0: X + * 1: Y + * 2: Z + * + * Return Value: + * 0: Minimal X + * 1: Minimal Y + * 2: Maximal X + * 3: Maximal Y + * + * Public: No + */ #include "script_component.hpp" -private ["_minX","_minY","_maxX","_maxY", "_bounds", "_boundsCorners", "_boundsMax", "_boundsMaxX", "_boundsMaxY", "_boundsMaxZ", "_boundsMin", "_boundsMinX", "_boundsMinY", "_boundsMinZ"]; +params ["_object", "_margins", "_offsets"]; -PARAMS_3(_object,_margins,_offsets); +private ["_minX", "_minY", "_maxX", "_maxY", "_bounds", "_boundsCorners"]; _minX = 10; _minY = 10; _maxX = -10; _maxY = -10; -if (true) then { - _bounds = boundingBox _object; +_bounds = boundingBox _object; +_margins params ["_marginsX", "_marginsY", "_marginsZ"]; +_offsets params ["_offsetsX", "_offsetsY", "_offsetsZ"]; - _boundsMin = _bounds select 0; - _boundsMinX = (_boundsMin select 0) - (_margins select 0) + (_offsets select 0); - _boundsMinY = (_boundsMin select 1) - (_margins select 1) + (_offsets select 1); - _boundsMinZ = (_boundsMin select 2) - (_margins select 2) + (_offsets select 2); - _boundsMax = _bounds select 1; - _boundsMaxX = (_boundsMax select 0) + (_margins select 0) + (_offsets select 0); - _boundsMaxY = (_boundsMax select 1) + (_margins select 1) + (_offsets select 1); - _boundsMaxZ = (_boundsMax select 2) + (_margins select 2) + (_offsets select 2); +_bounds params ["_boundsMin", "_boundsMax"]; +_boundsMin params ["_boundsMinX", "_boundsMinY", "_boundsMinZ"]; +_boundsMax params ["_boundsMaxX", "_boundsMaxY", "_boundsMaxZ"]; - _boundsCorners = [ - [_boundsMinX,_boundsMinY,_boundsMinZ], - [_boundsMinX,_boundsMinY,_boundsMaxZ], - [_boundsMinX,_boundsMaxY,_boundsMinZ], - [_boundsMinX,_boundsMaxY,_boundsMaxZ], - [_boundsMaxX,_boundsMinY,_boundsMinZ], - [_boundsMaxX,_boundsMinY,_boundsMaxZ], - [_boundsMaxX,_boundsMaxY,_boundsMinZ], - [_boundsMaxX,_boundsMaxY,_boundsMaxZ] - ]; +_boundsMinX = _boundsMinX - _marginsX + _offsetsX; +_boundsMinY = _boundsMinY - _marginsY + _offsetsY; +_boundsMinZ = _boundsMinZ - _marginsZ + _offsetsZ; +_boundsMaxX = _boundsMaxX + _marginsX + _offsetsX; +_boundsMaxY = _boundsMaxY + _marginsY + _offsetsY; +_boundsMaxZ = _boundsMaxZ + _marginsZ + _offsetsZ; - { - _ppos = worldToScreen (_object modelToWorld _x); - if (count _ppos >= 2) then { - EXPLODE_2_PVT(_ppos,_pposX,_pposY); - if (_pposX < _minX) then {_minX = _pposX}; - if (_pposX > _maxX) then {_maxX = _pposX}; - if (_pposY < _minY) then {_minY = _pposY}; - if (_pposY > _maxY) then {_maxY = _pposY}; - }; //else - what to do if it is offscreen? - } forEach _boundsCorners; -}; +_boundsCorners = [ + [_boundsMinX,_boundsMinY,_boundsMinZ], + [_boundsMinX,_boundsMinY,_boundsMaxZ], + [_boundsMinX,_boundsMaxY,_boundsMinZ], + [_boundsMinX,_boundsMaxY,_boundsMaxZ], + [_boundsMaxX,_boundsMinY,_boundsMinZ], + [_boundsMaxX,_boundsMinY,_boundsMaxZ], + [_boundsMaxX,_boundsMaxY,_boundsMinZ], + [_boundsMaxX,_boundsMaxY,_boundsMaxZ] +]; + +{ + private "_ppos"; + _ppos = worldToScreen (_object modelToWorld _x); + if (count _ppos >= 2) then { + _ppos params ["_pposX", "_pposY"]; + if (_pposX < _minX) then {_minX = _pposX}; + if (_pposX > _maxX) then {_maxX = _pposX}; + if (_pposY < _minY) then {_minY = _pposY}; + if (_pposY > _maxY) then {_maxY = _pposY}; + }; //else - what to do if it is offscreen? + false +} count _boundsCorners; [_minX,_minY,_maxX,_maxY] diff --git a/addons/common/functions/script_component.hpp b/addons/common/functions/script_component.hpp index 95b7e86461..c213544655 100644 --- a/addons/common/functions/script_component.hpp +++ b/addons/common/functions/script_component.hpp @@ -10,4 +10,4 @@ if((count _this) > c) then {\ _callFrom = _this select c;\ _lineNo = _this select c+1;\ - }; \ No newline at end of file + };