Skip to content

Commit

Permalink
optimize magwell preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed May 10, 2019
1 parent cbefd8c commit 259e2f7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 46 deletions.
74 changes: 51 additions & 23 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 Down Expand Up @@ -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
70 changes: 49 additions & 21 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 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
5 changes: 3 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 Down

0 comments on commit 259e2f7

Please sign in to comment.