From 493ce1b09211ea7aacfbbb783f9ff3eea9420872 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 22:16:51 +0200 Subject: [PATCH] more common code cleanup --- .../common/functions/fnc_disableUserInput.sqf | 28 ++++----- .../functions/fnc_displayTextPicture.sqf | 29 +++++----- .../functions/fnc_displayTextStructured.sqf | 25 ++++---- addons/common/functions/fnc_doAnimation.sqf | 45 +++++---------- addons/common/functions/fnc_dropBackpack.sqf | 22 +++---- addons/common/functions/fnc_dumpArray.sqf | 26 +++++++-- .../functions/fnc_dumpPerformanceCounters.sqf | 57 ++++++++++++------- 7 files changed, 123 insertions(+), 109 deletions(-) diff --git a/addons/common/functions/fnc_disableUserInput.sqf b/addons/common/functions/fnc_disableUserInput.sqf index d9485b11e7..ffa6d8e28f 100644 --- a/addons/common/functions/fnc_disableUserInput.sqf +++ b/addons/common/functions/fnc_disableUserInput.sqf @@ -5,23 +5,20 @@ * Arguments: * 0: True to disable key inputs, false to re-enable them * - * Return value: - * Nothing + * Return Value: + * None * - * Public: Yes + * Public: No */ - #include "script_component.hpp" -private ["_dlg"]; - -PARAMS_1(_state); +params ["_state"]; if (_state) then { disableSerialization; if (!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])) exitWith {}; - if ("ACE_DisableUserInput" in ([BIS_stackedEventHandlers_onEachFrame, {_this select 0}] call FUNC(map))) exitWith {}; + if (!isNil QGVAR(disableInputPFH)) exitWith {}; // end TFAR and ACRE2 radio transmissions call FUNC(endRadioTransmission); @@ -34,19 +31,22 @@ if (_state) then { closeDialog 0; createDialog QGVAR(DisableMouse_Dialog); + private "_dlg"; _dlg = uiNamespace getVariable QGVAR(dlgDisableMouse); _dlg displayAddEventHandler ["KeyDown", { - private ["_key", "_dlg", "_ctrl", "_config", "_acc", "_index"]; - _key = _this select 1; + params ["", "_key"]; if (_key == 1 && {alive player}) then { createDialog (["RscDisplayInterrupt", "RscDisplayMPInterrupt"] select isMultiplayer); disableSerialization; + + private ["_dlg", "_ctrl"]; + _dlg = finddisplay 49; _dlg displayAddEventHandler ["KeyDown", { - _key = _this select 1; + params ["", "_key"]; !(_key == 1) }]; @@ -62,19 +62,21 @@ if (_state) then { _ctrl = _dlg displayctrl ([104, 1010] select isMultiplayer); _ctrl ctrlSetEventHandler ["buttonClick", QUOTE(closeDialog 0; player setDamage 1; [false] call DFUNC(disableUserInput);)]; - _ctrl ctrlEnable (call {_config = missionConfigFile >> "respawnButton"; !isNumber _config || {getNumber _config == 1}}); + _ctrl ctrlEnable (call {private "_config"; _config = missionConfigFile >> "respawnButton"; !isNumber _config || {getNumber _config == 1}}); _ctrl ctrlSetText "RESPAWN"; _ctrl ctrlSetTooltip "Respawn."; }; if (_key in actionKeys "TeamSwitch" && {teamSwitchEnabled}) then { (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0; + + private "_acc"; _acc = accTime; teamSwitch; setAccTime _acc; }; - if (_key in actionKeys "CuratorInterface" && {getAssignedCuratorLogic player in allCurators}) then { + if (_key in actionKeys "CuratorInterface" && {getAssignedCuratorLogic player in allCurators}) then { (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0; openCuratorInterface; }; diff --git a/addons/common/functions/fnc_displayTextPicture.sqf b/addons/common/functions/fnc_displayTextPicture.sqf index 93d4d38df7..3bdf908d16 100644 --- a/addons/common/functions/fnc_displayTextPicture.sqf +++ b/addons/common/functions/fnc_displayTextPicture.sqf @@ -1,25 +1,21 @@ /* * Author: commy2, Glowbal - * * Display a structured text with image. * - * Argument: + * Arguments: * 0: Text * 1: Image - * 2: Image color - * 3: Target Unit. Will only display if target is the player controlled object + * 2: Image color (default: [0, 0, 0, 0]) + * 3: Target Unit. Will only display if target is the player controlled object (default: ACE_player) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ - #include "script_component.hpp" -private ["_imageColor", "_target"]; -PARAMS_2(_text,_image); -_imageColor = if (count _this > 2) then {_this select 2} else {[1,1,1]}; -_imageColor resize 3; -_target = if (count _this > 3) then {_this select 3} else {ACE_player}; +params ["_text", "_image", ["_imageColor", [1,1,1]], ["_target", ACE_player]]; if (_target != ACE_player) exitWith {}; @@ -28,16 +24,21 @@ if (typeName _text != "TEXT") then { if (count _text > 0) then { { if (typeName _x == "STRING" && {isLocalized _x}) then { - _text set [_foreachIndex, localize _x]; + _text set [_forEachIndex, localize _x]; }; - }foreach _text; + } forEach _text; + _text = format _text; }; }; + if (typeName _text == "STRING" && {isLocalized _text}) then { _text = localize _text; }; + _text = parseText format ["%1", _text]; }; + _text = composeText [parseText format ["", _image, _imageColor call BIS_fnc_colorRGBtoHTML], lineBreak, _text]; + [_text, 2] call FUNC(displayTextStructured); diff --git a/addons/common/functions/fnc_displayTextStructured.sqf b/addons/common/functions/fnc_displayTextStructured.sqf index cfe2feb3cb..255a014b6f 100644 --- a/addons/common/functions/fnc_displayTextStructured.sqf +++ b/addons/common/functions/fnc_displayTextStructured.sqf @@ -1,23 +1,20 @@ /* * Author: commy2, Glowbal - * * Display a structured text. * - * Argument: + * Arguments: * 0: Text - * 1: Size of the textbox - * 2: Target Unit. Will only display if target is the player controlled object + * 1: Size of the textbox (default: 1.5) + * 2: Target Unit. Will only display if target is the player controlled object (default: ACE_player) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ - #include "script_component.hpp" -private ["_text", "_size", "_isShown", "_ctrlHint", "_yPos", "_xPos", "_wPos", "_hPos", "_position", "_target"]; -_text = _this select 0; -_size = if (count _this > 1) then {_this select 1} else {1.5;}; -_target = if (count _this > 2) then {_this select 2} else {ACE_player}; +params ["_text", ["_size", 1.5], ["_target", ACE_player]]; if (_target != ACE_player) exitWith {}; @@ -38,6 +35,8 @@ if (typeName _text != "TEXT") then { _text = composeText [lineBreak, parseText format ["%1", _text]]; }; +private ["_isShown", "_ctrlHint", "_xPos", "_yPos", "_wPos", "_hPos", "_position"]; + _isShown = ctrlShown (uiNamespace getVariable ["ACE_ctrlHint", controlNull]); ("ACE_RscHint" call BIS_fnc_rscLayer) cutRsc ["ACE_RscHint", "PLAIN", 0, true]; @@ -60,8 +59,8 @@ _yPos = safeZoneY + 0.175 * safezoneH; _wPos = (10 *(((safezoneW / safezoneH) min 1.2) / 40)); _hPos = (2 *((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)); -//Zeus Interface Open and Display would be under the "CREATE" list -if (!isnull curatorCamera) then { +// Zeus Interface Open and Display would be under the "CREATE" list +if (!isNull curatorCamera) then { _xPos = _xPos min ((safezoneX + safezoneW - 12.5 * (((safezoneW / safezoneH) min 1.2) / 40)) - _wPos); }; diff --git a/addons/common/functions/fnc_doAnimation.sqf b/addons/common/functions/fnc_doAnimation.sqf index 5b7a1ed1bf..42d59f0b72 100644 --- a/addons/common/functions/fnc_doAnimation.sqf +++ b/addons/common/functions/fnc_doAnimation.sqf @@ -3,35 +3,22 @@ * * Execute an animation. This is used to not break things like the unconsciousness animation. * - * Argument: - * 0: Unit (Object) - * 1: Animation (String) - * 2: Priority of the animation. (Number, optional default: 0) - * 0: PlayMove - * 1: PlayMoveNow - * 2: SwitchMove (no transitional animation, doesn't overwrite priority 1) + * Arguments: + * 0: Unit + * 1: Animation + * 2: Priority of the animation. (default: 0) + * 0 = PlayMove + * 1 = PlayMoveNow + * 2 = SwitchMove (no transitional animation, doesn't overwrite priority 1) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ #include "script_component.hpp" -private ["_force"]; - -PARAMS_3(_unit,_animation,_priority); -_force = False; - -// no animation given -if (isNil "_animation") exitWith { - ACE_LOGERROR_1("No animation specified in %1.",_fnc_scriptNameParent); -}; - -if (isNil "_priority") then { - _priority = 0; -}; -if (count _this > 3) then { - _force = _this select 3; -}; +params ["_unit", "_animation", ["_priority", 0], ["_force", false]]; // don't overwrite more important animations if (_unit getVariable ["ACE_isUnconscious", false] && {(_animation != "Unconscious")} && {!_force}) exitWith {}; @@ -47,7 +34,7 @@ if (_animation == "") then { //if (_animation == animationState _unit) exitWith {}; switch (_priority) do { - case 0 : { + case 0: { if (_unit == vehicle _unit) then { [_unit, format ["{_this playMove '%1'}", _animation], _unit] call FUNC(execRemoteFnc); } else { @@ -55,7 +42,7 @@ switch (_priority) do { [_unit, format ["{_this playMove '%1'}", _animation]] call FUNC(execRemoteFnc); }; }; - case 1 : { + case 1: { if (_unit == vehicle _unit) then { [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); } else { @@ -63,7 +50,7 @@ switch (_priority) do { [_unit, format ["{_this playMoveNow '%1'}", _animation]] call FUNC(execRemoteFnc); }; }; - case 2 : { + case 2: { // try playMoveNow first if (_unit == vehicle _unit) then { [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); @@ -80,5 +67,3 @@ switch (_priority) do { }; default {}; }; - -["Anim", [_priority, _animation]] call FUNC(log); diff --git a/addons/common/functions/fnc_dropBackpack.sqf b/addons/common/functions/fnc_dropBackpack.sqf index 05ee3ab750..fc2b0bba64 100644 --- a/addons/common/functions/fnc_dropBackpack.sqf +++ b/addons/common/functions/fnc_dropBackpack.sqf @@ -1,30 +1,24 @@ /* * Author: commy2 - * * Drops a backback. Also returns the ground wepaon holder object of the dropped backpack. * - * Argument: - * 0: Unit that has a backpack (Object) + * Arguments: + * 0: Unit that has a backpack * * Return value: - * Ground wepaon holder with backpack (Object) + * Ground wepaon holder with backpack * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; -private ["_backpackObject","_holder"]; +private ["_backpackObject", "_holder"]; _backpackObject = backpackContainer _unit; + _unit addBackpack "Bag_Base"; removeBackpack _unit; -_holder = objNull; -{ - if (_backpackObject in everyBackpack _x) exitWith { - _holder = _x; - }; -} forEach (position _unit nearObjects ["WeaponHolder", 5]); - -_holder +objectParent _backpackObject // return diff --git a/addons/common/functions/fnc_dumpArray.sqf b/addons/common/functions/fnc_dumpArray.sqf index 8572aaf134..e07da9f695 100644 --- a/addons/common/functions/fnc_dumpArray.sqf +++ b/addons/common/functions/fnc_dumpArray.sqf @@ -1,10 +1,21 @@ -//fnc_dumpArray.sqf +/* + * Author: ? + * ? + * + * Arguments: + * 0: Array to be dumped + * 1: Depth + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_pad", "_i", "_x"]; - -PARAMS_2(_var,_depth); +params ["_var", "_depth"]; +private "_pad"; _pad = ""; for "_i" from 0 to _depth do { @@ -14,11 +25,14 @@ for "_i" from 0 to _depth do { _depth = _depth + 1; if (IS_ARRAY(_var)) then { - if ((count _var) > 0) then { + if (count _var > 0) then { diag_log text format["%1[", _pad]; + { [_x, _depth] call FUNC(dumpArray); - } forEach _var; + false + } count _var; + diag_log text format["%1],", _pad]; } else { diag_log text format["%1[],", _pad]; diff --git a/addons/common/functions/fnc_dumpPerformanceCounters.sqf b/addons/common/functions/fnc_dumpPerformanceCounters.sqf index 0c3d6c8e78..7845aaf95d 100644 --- a/addons/common/functions/fnc_dumpPerformanceCounters.sqf +++ b/addons/common/functions/fnc_dumpPerformanceCounters.sqf @@ -1,49 +1,68 @@ -//fnc_dumpPerformanceCounters.sqf -#define DEBUG_MODE_FULL +/* + * Author: ? + * Dumps performance counter statistics into Logs. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" - diag_log text format["REGISTERED ACE PFH HANDLERS"]; diag_log text format["-------------------------------------------"]; + if (!isNil "ACE_PFH_COUNTER") then { { - private ["_isActive"]; _x params ["_pfh", "_parameters"]; - _isActive = if (!isNil {cba_common_PFHhandles select (_pfh select 0)}) then {"ACTIVE"} else {"REMOVED"}; - diag_log text format["Registered PFH: id=%1 [%2, delay %3], %4:%5", (_pfh select 0), (_isActive), (_parameters select 1), (_pfh select 1), (_pfh select 2) ]; - } forEach ACE_PFH_COUNTER; + + private "_isActive"; + _isActive = ["ACTIVE", "REMOVED"] select isNil {CBA_common_PFHhandles select (_pfh select 0)} + + diag_log text format ["Registered PFH: id=%1 [%2, delay %3], %4:%5", _pfh select 0, _isActive, _parameters select 1, _pfh select 1, _pfh select 2]; + false + } count ACE_PFH_COUNTER; }; -diag_log text format["ACE COUNTER RESULTS"]; -diag_log text format["-------------------------------------------"]; +diag_log text format ["ACE COUNTER RESULTS"]; +diag_log text format ["-------------------------------------------"]; + { - private ["_counterEntry", "_iter", "_total", "_count", "_delta", "_averageResult"]; + private ["_counterEntry", "_iter", "_total", "_count", "_averageResult", "_delta"]; + _counterEntry = _x; _iter = 0; _total = 0; _count = 0; _averageResult = 0; - if( (count _counterEntry) > 3) then { + + if (count _counterEntry > 3) then { // calc { - if(_iter > 2) then { + if (_iter > 2) then { _count = _count + 1; _delta = (_x select 1) - (_x select 0); _total = _total + _delta; }; + _iter = _iter + 1; - } forEach _counterEntry; - + false + } count _counterEntry; + // results _averageResult = (_total / _count) * 1000; - + // dump results - diag_log text format["%1: Average: %2s / %3 = %4ms", (_counterEntry select 0), _total, _count, _averageResult]; + diag_log text format ["%1: Average: %2s / %3 = %4ms", _counterEntry select 0, _total, _count, _averageResult]; } else { - diag_log text format["%1: No results", (_counterEntry select 0) ]; + diag_log text format ["%1: No results", _counterEntry select 0]; }; -} forEach ACE_COUNTERS; + false +} count ACE_COUNTERS; /* // Dump PFH Trackers @@ -71,4 +90,4 @@ diag_log text format["-------------------------------------------"]; // //} forEach ACRE_EXCESSIVE_FRAME_TRACKER; -*/ \ No newline at end of file +*/