Attach - Optimize creating children actions (#6345)

* Optimize attach get children actions

* Store CfgMagazines and CfgWeapons config lookups
This commit is contained in:
mharis001 2018-05-31 11:49:38 -04:00 committed by PabstMirror
parent b1c969c89d
commit ac3642d074
4 changed files with 51 additions and 56 deletions

View File

@ -5,7 +5,7 @@
class GVAR(AttachVehicle) { \
displayName = CSTRING(AttachDetach); \
condition = QUOTE(_this call FUNC(canAttach)); \
insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions)); \
insertChildren = QUOTE(_this call FUNC(getChildrenActions)); \
exceptions[] = {"isNotSwimming"}; \
showDisabled = 0; \
icon = QPATHTOF(UI\attach_ca.paa); \
@ -52,7 +52,7 @@ class CfgVehicles {
class GVAR(Attach) {
displayName = CSTRING(AttachDetach);
condition = QUOTE(_this call FUNC(canAttach));
insertChildren = QUOTE(_this call FUNC(getChildrenAttachActions));
insertChildren = QUOTE(_this call FUNC(getChildrenActions));
exceptions[] = {"isNotDragging", "isNotSwimming"};
showDisabled = 0;
icon = QPATHTOF(UI\attach_ca.paa);

View File

@ -1,9 +1,8 @@
PREP(attach);
PREP(canAttach);
PREP(canDetach);
PREP(detach);
PREP(getChildrenAttachActions);
PREP(getChildrenActions);
PREP(handleGetIn);
PREP(handleGetOut);
PREP(handleKilled);

View File

@ -0,0 +1,48 @@
/*
* Author: Garth de Wet (LH), PabstMirror, mharis001
* Returns children actions for attachable items.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* Actions <ARRAY>
*
* Example:
* [_target, _player] call ace_attach_fnc_getChildrenActions
*
* Public: No
*/
#include "script_component.hpp"
params ["_target", "_player"];
TRACE_2("params",_target,_player);
private _cfgMagazines = configFile >> "CfgMagazines";
private _cfgWeapons = configFile >> "CfgWeapons";
private _actions = [];
private _magazines = magazines _player;
{
private _config = _cfgMagazines >> _x;
if (getText (_config >> "ACE_Attachable") != "") then {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
private _action = [_x, _displayName, _picture, {[{_this call FUNC(attach)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
} forEach (_magazines arrayIntersect _magazines);
{
private _config = _cfgWeapons >> _x;
if (getText (_config >> "ACE_Attachable") != "") then {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
private _action = [_x, _displayName, _picture, {[{_this call FUNC(attach)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
} forEach ([_player, false] call CBA_fnc_uniqueUnitItems);
_actions

View File

@ -1,52 +0,0 @@
/*
* Author: Garth de Wet (LH), PabstMirror
* Show the ammo counts for a static weapon.
* Called from "insertChildren" on interact_menu
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* ChildActiosn<ARRAY>
*
* Example:
* [player, player] call ace_attach_fnc_getChildrenAttachActions
*
* Public: No
*/
#include "script_component.hpp"
params ["_target","_player"];
TRACE_2("params",_target,_player);
private _listed = [];
private _actions = [];
{
if !(_x in _listed) then {
_listed pushBack _x;
private _item = ConfigFile >> "CfgMagazines" >> _x;
if (getText (_item >> "ACE_Attachable") != "") then {
private _displayName = getText(_item >> "displayName");
private _picture = getText(_item >> "picture");
private _action = [_x, _displayName, _picture, {[{_this call FUNC(attach)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, [_x]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
};
} forEach (magazines _player);
{
if !(_x in _listed) then {
_listed pushBack _x;
private _item = ConfigFile >> "CfgWeapons" >> _x;
if (getText (_item >> "ACE_Attachable") != "") then {
private _displayName = getText(_item >> "displayName");
private _picture = getText(_item >> "picture");
private _action = [_x, _displayName, _picture, {[{_this call FUNC(attach)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, [_x]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
};
} forEach (items _player);
_actions