Skip to content

Commit

Permalink
make use of getHitpointsDamage command to drastically speed up some f…
Browse files Browse the repository at this point in the history
…unctions about hitpoints
  • Loading branch information
commy2 committed Aug 30, 2015
1 parent 2f54cfa commit c3beee8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 90 deletions.
1 change: 1 addition & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ PREP(getConfigGunner);
PREP(getConfigCommander);
PREP(getHitPoints);
PREP(getHitPointsWithSelections);
PREP(getSelectionsWithoutHitPoints);
PREP(getReflectorsWithSelections);
PREP(getLightProperties);
PREP(getLightPropertiesWeapon);
Expand Down
46 changes: 3 additions & 43 deletions addons/common/functions/fnc_getHitPoints.sqf
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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) - [""]
52 changes: 5 additions & 47 deletions addons/common/functions/fnc_getHitPointsWithSelections.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c3beee8

Please sign in to comment.