From a9273cb02f1a59edcf1785bffb93c10b2aed7087 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 May 2019 10:48:52 +0200 Subject: [PATCH] optimize magwell preloading (#1144) * optimize magwell preloading * recognize inherited items * fix some test weirdness --- addons/ui/fnc_preload3DEN.sqf | 76 ++++++++++++++++++++++---------- addons/ui/fnc_preloadCurator.sqf | 72 +++++++++++++++++++++--------- addons/ui/test_preload.sqf | 6 ++- 3 files changed, 106 insertions(+), 48 deletions(-) diff --git a/addons/ui/fnc_preload3DEN.sqf b/addons/ui/fnc_preload3DEN.sqf index d53e47199..4938fc2b1 100644 --- a/addons/ui/fnc_preload3DEN.sqf +++ b/addons/ui/fnc_preload3DEN.sqf @@ -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"]; @@ -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, @@ -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"); }; }; @@ -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 diff --git a/addons/ui/fnc_preloadCurator.sqf b/addons/ui/fnc_preloadCurator.sqf index 1c936dad8..908e1ebb6 100644 --- a/addons/ui/fnc_preloadCurator.sqf +++ b/addons/ui/fnc_preloadCurator.sqf @@ -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; @@ -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; @@ -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"); }; }; @@ -199,5 +226,6 @@ private _magazinesLists = []; } forEach call (uiNamespace getVariable QEGVAR(common,addons)); _itemTypes call CBA_fnc_deleteNamespace; +_magwells call CBA_fnc_deleteNamespace; true diff --git a/addons/ui/test_preload.sqf b/addons/ui/test_preload.sqf index fd692af73..641a28a92 100644 --- a/addons/ui/test_preload.sqf +++ b/addons/ui/test_preload.sqf @@ -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"; }; @@ -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; @@ -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; };