Skip to content

Commit

Permalink
optimize magwell preloading (#1144)
Browse files Browse the repository at this point in the history
* optimize magwell preloading

* recognize inherited items

* fix some test weirdness
  • Loading branch information
commy2 authored May 11, 2019
1 parent cbefd8c commit a9273cb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 48 deletions.
76 changes: 52 additions & 24 deletions addons/ui/fnc_preload3DEN.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ private _cfgMagazines = configFile >> "CfgMagazines";
private _magazines = [];
private _magazinesLists = [];

// cache magwells
private _magwells = call CBA_fnc_createNamespace;

{
private _magazines = [];

{
if (isArray _x) then {
_magazines append getArray _x;
};
} forEach configProperties [_x];

_magwells setVariable [configName _x, _magazines];
} forEach ("true" configClasses (configFile >> "CfgMagazineWells"));

private _cache = [];

{
private _item = toLower configName _x;
(_item call BIS_fnc_itemType) params ["_itemCategory", "_itemType"];
Expand All @@ -93,7 +110,7 @@ private _magazinesLists = [];
_displayName,
getText (_cfgWeapons >> getText (_x >> "item") >> "displayName")
];
} forEach ("true" configClasses (_weaponConfig >> "linkeditems")); //configProperties [_weaponConfig >> "linkeditems", "isClass _x"];
} forEach configProperties [_weaponConfig >> "linkeditems", "isClass _x"];

_listItem pushBack [
_displayName,
Expand All @@ -114,31 +131,41 @@ private _magazinesLists = [];
};

private _compatibleMagazines = getArray (_muzzleConfig >> "magazines");
{

private _magWell = getArray (_muzzleConfig >> "magazineWell");
if (isNil {_magwells getVariable str _magWell}) then {
private _magazines = [];

{
_compatibleMagazines append getArray _x;
} forEach configProperties [configFile >> "CfgMagazineWells" >> _x, "isArray _x"];
} foreach getArray (_muzzleConfig >> "magazineWell");

{
private _item = toLower _x;

if (_magazinesLists pushBackUnique [_item, _listItem] != -1) then {
private _magazineConfig = _cfgMagazines >> _item;

if (getNumber (_magazineConfig >> "scope") == 2) then {
_listItem pushBack [
getText (_magazineConfig >> "displayName"),
_item,
getText (_magazineConfig >> "picture"),
2,
_item in _magazines
];

_magazines pushBack _item;
_magazines append (_magwells getVariable [_x, []]);
} forEach _magWell;

_magwells setVariable [str _magWell, _magazines];
};

_compatibleMagazines append (_magwells getVariable str _magWell);

if (_cache pushBackUnique [_compatibleMagazines, _listItem] != -1) then {
{
private _item = toLower _x;

if (_magazinesLists pushBackUnique [_item, _listItem] != -1) then {
private _magazineConfig = _cfgMagazines >> _item;

if (getNumber (_magazineConfig >> "scope") == 2) then {
_listItem pushBack [
getText (_magazineConfig >> "displayName"),
_item,
getText (_magazineConfig >> "picture"),
2,
_item in _magazines
];

_magazines pushBack _item;
};
};
};
} forEach _compatibleMagazines;
} forEach _compatibleMagazines;
};
} forEach getArray (_weaponConfig >> "muzzles");
};
};
Expand Down Expand Up @@ -187,5 +214,6 @@ private _listHeadgear = _list select 10;
} forEach ("true" configClasses (configFile >> "CfgGlasses"));

_itemTypes call CBA_fnc_deleteNamespace;
_magwells call CBA_fnc_deleteNamespace;

true
72 changes: 50 additions & 22 deletions addons/ui/fnc_preloadCurator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ private _cfgMagazines = configFile >> "CfgMagazines";
private _magazines = [];
private _magazinesLists = [];

// cache magwells
private _magwells = call CBA_fnc_createNamespace;

{
private _magazines = [];

{
if (isArray _x) then {
_magazines append getArray _x;
};
} forEach configProperties [_x];

_magwells setVariable [configName _x, _magazines];
} forEach ("true" configClasses (configFile >> "CfgMagazineWells"));

private _cache = [];

{
private _patchConfig = _cfgPatches >> _x;
_addon = toLower _x;
Expand All @@ -101,7 +118,7 @@ private _magazinesLists = [];
_displayName,
getText (_cfgWeapons >> getText (_x >> "item") >> "displayName")
];
} forEach ("true" configClasses (_weaponConfig >> "linkeditems")); //configProperties [_weaponConfig >> "linkeditems", "isClass _x"];
} forEach configProperties [_weaponConfig >> "linkeditems", "isClass _x"];

private _displayNameShort = _displayName;
private _displayNameShortArray = toArray _displayNameShort;
Expand Down Expand Up @@ -131,34 +148,44 @@ private _magazinesLists = [];
};

private _compatibleMagazines = getArray (_muzzleConfig >> "magazines");
{

private _magWell = getArray (_muzzleConfig >> "magazineWell");
if (isNil {_magwells getVariable str _magWell}) then {
private _magazines = [];

{
_compatibleMagazines append getArray _x;
} forEach configProperties [configFile >> "CfgMagazineWells" >> _x, "isArray _x"];
} foreach getArray (_muzzleConfig >> "magazineWell");
_magazines append (_magwells getVariable [_x, []]);
} forEach _magWell;

{
private _item = toLower _x;
_magwells setVariable [str _magWell, _magazines];
};

if (_magazinesLists pushBackUnique [_item, _listItem] != -1) then {
private _magazineConfig = _cfgMagazines >> _item;
_compatibleMagazines append (_magwells getVariable str _magWell);

if (getNumber (_magazineConfig >> "scope") == 2) then {
private _displayName = getText (_magazineConfig >> "displayName");
if (_cache pushBackUnique [_compatibleMagazines, _listItem] != -1) then {
{
private _item = toLower _x;

_listItem pushBack [
_displayName,
_displayName,
_item,
getText (_magazineConfig >> "picture"),
2,
_item in _magazines
];
if (_magazinesLists pushBackUnique [_item, _listItem] != -1) then {
private _magazineConfig = _cfgMagazines >> _item;

_magazines pushBack _item;
if (getNumber (_magazineConfig >> "scope") == 2) then {
private _displayName = getText (_magazineConfig >> "displayName");

_listItem pushBack [
_displayName,
_displayName,
_item,
getText (_magazineConfig >> "picture"),
2,
_item in _magazines
];

_magazines pushBack _item;
};
};
};
} forEach _compatibleMagazines;
} forEach _compatibleMagazines;
};
} forEach getArray (_weaponConfig >> "muzzles");
};
};
Expand Down Expand Up @@ -199,5 +226,6 @@ private _magazinesLists = [];
} forEach call (uiNamespace getVariable QEGVAR(common,addons));

_itemTypes call CBA_fnc_deleteNamespace;
_magwells call CBA_fnc_deleteNamespace;

true
6 changes: 4 additions & 2 deletions addons/ui/test_preload.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if (!canSuspend) exitWith {
isNil {
with uiNamespace do {
// 3DEN
TEST_DEFINED(QFUNC(preload3DEN),"");

AmmoBox_list = nil;
["onLoad", [controlNull]] call compile preprocessFile "\a3\3den\UI\Attributes\AmmoBox.sqf";
};
Expand All @@ -19,6 +17,9 @@ waitUntil {!isNil {uiNamespace getVariable "AmmoBox_list"}};

isNil {
with uiNamespace do {
// 3DEN
TEST_DEFINED(QFUNC(preload3DEN),"");

private _vanilla = AmmoBox_list;

AmmoBox_list = nil;
Expand All @@ -37,6 +38,7 @@ isNil {
private _curator = getAssignedCuratorLogic _unit;

if (isNull _curator) then {
activateAddons call EGVAR(common,addons);
_curator = createGroup sideLogic createUnit ["ModuleCurator_F", [0,0,0], [], 0, "NONE"];
_unit assignCurator _curator;
};
Expand Down

0 comments on commit a9273cb

Please sign in to comment.