Skip to content

Commit

Permalink
Attach - Optimize creating children actions (#6345)
Browse files Browse the repository at this point in the history
* Optimize attach get children actions

* Store CfgMagazines and CfgWeapons config lookups
  • Loading branch information
mharis001 authored and PabstMirror committed May 31, 2018
1 parent b1c969c commit ac3642d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 56 deletions.
4 changes: 2 additions & 2 deletions addons/attach/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions addons/attach/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

PREP(attach);
PREP(canAttach);
PREP(canDetach);
PREP(detach);
PREP(getChildrenAttachActions);
PREP(getChildrenActions);
PREP(handleGetIn);
PREP(handleGetOut);
PREP(handleKilled);
Expand Down
48 changes: 48 additions & 0 deletions addons/attach/functions/fnc_getChildrenActions.sqf
Original file line number Diff line number Diff line change
@@ -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
52 changes: 0 additions & 52 deletions addons/attach/functions/fnc_getChildrenAttachActions.sqf

This file was deleted.

0 comments on commit ac3642d

Please sign in to comment.