From c3beee82615496b2c29b6b7c179396f5d68c607e Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 30 Aug 2015 21:13:29 +0200 Subject: [PATCH] make use of getHitpointsDamage command to drastically speed up some functions about hitpoints --- addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_getHitPoints.sqf | 46 ++-------------- .../fnc_getHitPointsWithSelections.sqf | 52 ++----------------- .../fnc_getSelectionsWithoutHitPoints.sqf | 28 ++++++++++ 4 files changed, 37 insertions(+), 90 deletions(-) create mode 100644 addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 6fdf99113cf..23b4e5c6967 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -215,6 +215,7 @@ PREP(getConfigGunner); PREP(getConfigCommander); PREP(getHitPoints); PREP(getHitPointsWithSelections); +PREP(getSelectionsWithoutHitPoints); PREP(getReflectorsWithSelections); PREP(getLightProperties); PREP(getLightPropertiesWeapon); diff --git a/addons/common/functions/fnc_getHitPoints.sqf b/addons/common/functions/fnc_getHitPoints.sqf index 06b2b8d40b4..491f243b442 100644 --- a/addons/common/functions/fnc_getHitPoints.sqf +++ b/addons/common/functions/fnc_getHitPoints.sqf @@ -1,7 +1,7 @@ /* * Author: commy2 * - * Returns all hitpoints of any vehicle. Non unique hitpoints in turrets are ignored. + * Returns all hitpoints of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names. * * Arguments: * 0: A vehicle, not the classname (Object) @@ -11,46 +11,6 @@ */ #include "script_component.hpp" -private ["_config", "_hitpoints", "_i"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); - -_config = configFile >> "CfgVehicles" >> typeOf _vehicle; - -_hitpoints = []; - -// get all classes that can contain hitpoints -private "_hitpointClasses"; -_hitpointClasses = [_config >> "HitPoints"]; -{ - private "_class"; - _class = ([_config, _x] call FUNC(getTurretConfigPath)) >> "HitPoints"; - - if (isClass _class) then { - _hitpointClasses pushBack _class; - }; - -} forEach allTurrets _vehicle; - -// iterate through all classes with hitpoints and their parents -{ - private "_class"; - _class = _x; - - while {isClass _class} do { - - for "_i" from 0 to (count _class - 1) do { - private "_entry"; - _entry = configName (_class select _i); - - if (!(_entry in _hitpoints) && {!isNil {_vehicle getHitPointDamage _entry}}) then { - _hitpoints pushBack _entry; - }; - }; - - _class = inheritsFrom _class; - }; - -} forEach _hitpointClasses; - -_hitpoints +(getAllHitPointsDamage _vehicle select 0) - [""] diff --git a/addons/common/functions/fnc_getHitPointsWithSelections.sqf b/addons/common/functions/fnc_getHitPointsWithSelections.sqf index b66700881ec..bc3799665e5 100644 --- a/addons/common/functions/fnc_getHitPointsWithSelections.sqf +++ b/addons/common/functions/fnc_getHitPointsWithSelections.sqf @@ -11,51 +11,9 @@ */ #include "script_component.hpp" -private ["_config", "_hitpoints", "_selections", "_i"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); - -_config = configFile >> "CfgVehicles" >> typeOf _vehicle; - -_hitpoints = []; -_selections = []; - -// get all classes that can contain hitpoints -private "_hitpointClasses"; -_hitpointClasses = [_config >> "HitPoints"]; -{ - private "_class"; - _class = ([_config, _x] call FUNC(getTurretConfigPath)) >> "HitPoints"; - - if (isClass _class) then { - _hitpointClasses pushBack _class; - }; - -} forEach allTurrets _vehicle; - -// iterate through all classes with hitpoints and their parents -{ - private "_class"; - _class = _x; - - while {isClass _class} do { - - for "_i" from 0 to (count _class - 1) do { - if (isClass (_class select _i)) then { - private ["_entry", "_selection"]; - _entry = configName (_class select _i); - _selection = getText (_class select _i >> "name"); - - if (!(_selection in _selections) && {!isNil {_vehicle getHit _selection}}) then { - _hitpoints pushBack _entry; - _selections pushBack _selection; - }; - }; - }; - - _class = inheritsFrom _class; - }; - -} forEach _hitpointClasses; - -[_hitpoints, _selections] +private "_hitPointsWithSelections"; +_hitPointsWithSelections = getAllHitPointsDamage _vehicle; +_hitPointsWithSelections resize 2; +_hitPointsWithSelections diff --git a/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf b/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf new file mode 100644 index 00000000000..277155108ab --- /dev/null +++ b/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf @@ -0,0 +1,28 @@ +/* + * Author: commy2 + * + * Returns all damageable selections without hitpoints of any vehicle. + * + * Arguments: + * 0: A vehicle, not the classname (Object) + * + * Return Value: + * The selections without hitpoints, i.e. reflectors. (Array) + */ +#include "script_component.hpp" + +params ["_vehicle"]; + +private ["_hitPointsFull", "_allSelectionsWithoutHitpoints"]; + +_hitPointsFull = getAllHitPointsDamage _vehicle; + +_allSelectionsWithoutHitpoints = []; + +{ + if (_x == "") then { + _allSelectionsWithoutHitpoints pushBack (_hitPointsFull select 1 select _forEachIndex); + }; +} forEach (_hitPointsFull select 0); + +_allSelectionsWithoutHitpoints