Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise: getGear for large item counts #39

Merged
merged 2 commits into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addons/game/XEH_pre_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ FUNC(getGear) = {
if (isNull _unit) exitWith {[]};
// diag_log text format["Assigned Items: %1", (assignedItems _unit)];
private _gear = (weapons _unit) + (items _unit) + (assignedItems _unit);
_gear = _gear select {(_x select [0, 4]) == "ACRE" || _x == "ItemRadio" || _x == "ItemRadioAcreFlagged"}; // We are only interested in ACRE gear.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A substring check is faster than a config check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, even without lazy eval here. I didn't lazy eval to improve worst case performance (lazy eval adds some overhead). Though the monitorRadios function (client check for uninitalized radios and a few other things) would do 3 config lookups for each equipment return. But filtering in getGear seems to speed it up. Each in the server masterIDTracker there is a speed up and that's only 1 config look up.

// The below is really slow and tends to worsen performance.
//_gear = _gear select {(_x call EFUNC(api,getBaseRadio)) in (call EFUNC(api,getAllRadios) select 0) || {_x == "ItemRadio"} || {_x == "ItemRadioAcreFlagged"}};
_gear;
};

Expand Down
15 changes: 7 additions & 8 deletions addons/sys_radio/fnc_monitorRadios.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ DFUNC(monitorRadios_PFH) = {
if(time < 1) exitWith { };

if(ACREALIVE(acre_player)) then {
_currentUniqueItems = [];
_weapons = [acre_player] call EFUNC(lib,getGear);

private _currentUniqueItems = [];
private _weapons = [acre_player] call EFUNC(lib,getGear);

if(!("ItemRadio" in _weapons) && !("ItemRadioAcreFlagged" in _weapons) && !ACRE_HOLD_OFF_ITEMRADIO_CHECK) then {
// [acre_player, "ItemRadioAcreFlagged"] call EFUNC(lib,addGear);
acre_player linkItem "ItemRadioAcreFlagged";
_newWeapons = [acre_player] call EFUNC(lib,getGear);
acre_player linkItem "ItemRadioAcreFlagged"; // Only ItemRadio/ItemRadioAcreFlagged can be in the linked item slot for Radios.
// Check if the linkItem removes anything... Only ItemRadio
/*_newWeapons = [acre_player] call EFUNC(lib,getGear);
{
_radio = _x;
_hasUnique = getNumber(configFile >> "CfgWeapons" >> _radio >> "acre_hasUnique");
Expand All @@ -52,7 +51,7 @@ DFUNC(monitorRadios_PFH) = {
};
};
} forEach _weapons;
_weapons = _newWeapons;
_weapons = _newWeapons;*/
} else {
if("ItemRadioAcreFlagged" in _weapons && !("ItemRadioAcreFlagged" in (assignedItems acre_player)) && !ACRE_HOLD_OFF_ITEMRADIO_CHECK) then {
acre_player assignItem "ItemRadioAcreFlagged";
Expand Down Expand Up @@ -110,7 +109,7 @@ DFUNC(monitorRadios_PFH) = {
[acre_player, _radio, _baseRadio] call EFUNC(lib,replaceGear);
_radio = _baseRadio;
};
PUSH(_currentUniqueItems, _radio);
_currentUniqueItems pushBack _radio;
};
} forEach _weapons;

Expand Down
2 changes: 2 additions & 0 deletions addons/sys_server/fnc_masterIdTracker.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (!GVAR(doFullSearch)) then {
} else {
#ifdef PLATFORM_A3
_items = itemCargo _object;
_items = _items select {(_x select [0, 4]) == "ACRE" || _x == "ItemRadio" || _x == "ItemRadioAcreFlagged"};
#endif
#ifdef PLATFORM_A2
_items = (getWeaponCargo _object) select 0;
Expand Down Expand Up @@ -103,6 +104,7 @@ if(GVAR(doFullSearch) && !GVAR(fullSearchRunning) ) then {
} else {
#ifdef PLATFORM_A3
_items = itemCargo _object;
_items = _items select {(_x select [0, 4]) == "ACRE" || _x == "ItemRadio" || _x == "ItemRadioAcreFlagged"};
#endif
#ifdef PLATFORM_A2
_items = (getWeaponCargo _object) select 0;
Expand Down