-
Notifications
You must be signed in to change notification settings - Fork 737
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
Improve checking of unit items #6350
Conversation
Based on slack discussion with @dedmen , unsure whether checking |
replacing Here are the results to replacing
Empty Inventory (from Slack 16th may 11:47AM)
This doesn't include the caching of the new ACE func which probably increases the impact a little more. Alsoooo... What about https://github.com/acemod/ACE3/blob/master/addons/explosives/functions/fnc_onIncapacitated.sqf#L28 ? :D |
params ["_unit"]; | ||
|
||
private _fnc_getItems = { | ||
params ["_unit"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is just the CBA thing without assignedItems right? CBATeam/CBA_A3#922 add's a parameter to disable assignedItems. But this specific implementation in here will be faster than the CBA one with it's conditionals.
So duplicate code and faster vs no duplicate code and slower ¯\(ツ)/¯
Btw you don't need params ["_unit"]
the local variable implicitly carries over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comes down to whether 5 if
s and 1 params
are worth duplicating code. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you are right about _unit
, i guess I added it for cachedCall
but it should be available there.
_result = _result arrayIntersect _result; | ||
|
||
_result | ||
(_unit call EFUNC(common,uniqueItems)) select {getNumber (configFile >> "CfgWeapons" >> _x >> QGVAR(Detonator)) == 1}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can again move the configFile >> "CfgWeapons"
outside the loop.
How often does this function run? That's a interaction menu condition right? so probably worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep forgetting to do that.. It's called for interaction menu actions, inventory EHs, and canDetonate (so lots).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/acemod/ACE3/pull/6350/files#r189167878 (my last comment) I want that :u
|
Replacing the cachedCall part (0.0118 ms): [_unit, _fnc_getItems, _unit, QGVAR(uniqueItemsCache), ITEMS_CACHE_TIME, "cba_events_loadoutEvent"] call FUNC(cachedCall); with something like this (0.0065 ms): private _items = _unit getVariable QGVAR(uniqueItemsCache);
if (isNil "_items") then {
_items = call _fnc_getItems;
_unit setVariable [QGVAR(uniqueItemsCache), _items];
};
+_items and a loadout event added in postInit to clear the cache seems worth it, considering we are going for overkill. This was tested with a low item count (4 unique items), the situation in which the And for similar reasons, I think |
Keep in mind that loadout event only works for local player. the how much faster is _fnc_getItems.. |
With no caching at all (4 items): I think the |
7de3c20
to
a0cab46
Compare
I think this PR is complete (replaced most/all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no further comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol I can approve multiple times?
* Add uniqueItems function * Optimize dogtag children actions function * Optimize getDetonators item search * Store CfgWeapons lookup in getDetonators * Update items to use new function * Update items to use new function 2 * More optimization of uniqueItems function * Update items to use new function 3
* Add uniqueItems function * Optimize dogtag children actions function * Optimize getDetonators item search * Store CfgWeapons lookup in getDetonators * Update items to use new function * Update items to use new function 2 * More optimization of uniqueItems function * Update items to use new function 3
When merged this pull request will:
uniqueItems
common function - same concept asCBA_fnc_uniqueUnitItems
however, caches items if unit isACE_player
(improves performance when checking units with lots of items)ace_dogtags_fnc_addDogtagActions
by usinguniqueItems
ace_explosives_fnc_getDetonators
by usinguniqueItems
Performance differences for
ace_dogtags_fnc_addDogtagActions
:Performance differences for
ace_explosives_fnc_getDetonators
: