From 259e2f71f6f3c8248a5e0b5e95cc5b847457d1d3 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 10 May 2019 21:25:01 +0200 Subject: [PATCH 1/3] optimize magwell preloading --- addons/ui/fnc_preload3DEN.sqf | 74 ++++++++++++++++++++++---------- addons/ui/fnc_preloadCurator.sqf | 70 +++++++++++++++++++++--------- addons/ui/test_preload.sqf | 5 ++- 3 files changed, 103 insertions(+), 46 deletions(-) diff --git a/addons/ui/fnc_preload3DEN.sqf b/addons/ui/fnc_preload3DEN.sqf index d53e47199..0b4e7e84b 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"]; @@ -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..500130f0f 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; @@ -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..bdc6635b6 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; From 06d65c53d421ccacca787ca74bd9d950080868d3 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 May 2019 00:36:03 +0200 Subject: [PATCH 2/3] recognize inherited items --- addons/ui/fnc_preload3DEN.sqf | 2 +- addons/ui/fnc_preloadCurator.sqf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/ui/fnc_preload3DEN.sqf b/addons/ui/fnc_preload3DEN.sqf index 0b4e7e84b..4938fc2b1 100644 --- a/addons/ui/fnc_preload3DEN.sqf +++ b/addons/ui/fnc_preload3DEN.sqf @@ -110,7 +110,7 @@ private _cache = []; _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, diff --git a/addons/ui/fnc_preloadCurator.sqf b/addons/ui/fnc_preloadCurator.sqf index 500130f0f..908e1ebb6 100644 --- a/addons/ui/fnc_preloadCurator.sqf +++ b/addons/ui/fnc_preloadCurator.sqf @@ -118,7 +118,7 @@ private _cache = []; _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; From 1ab7071c2cd4c4ae38bfd5f153c69c656b768fbf Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 May 2019 10:43:32 +0200 Subject: [PATCH 3/3] fix some test weirdness --- addons/ui/test_preload.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/ui/test_preload.sqf b/addons/ui/test_preload.sqf index bdc6635b6..641a28a92 100644 --- a/addons/ui/test_preload.sqf +++ b/addons/ui/test_preload.sqf @@ -38,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; };