Open remcoros opened 1 year ago
If I may suggest a modification -- in addition to the GetHitChanceForObjectRef
slowness, SortEnemies
currently constantly fetches state objects from the History in every sorting call to push destructibles to the end, so the function that maps the StateObjectReference to structs could also pre-check whether the state object is a XComGameState_Destructible
and also store that in the struct (or just assign a -1000 hit chance to them) for sorting purposes. That would simplify the comparison delegate.
As a reminder for myself: The same optimization can be applied to "GatherAbilityTargets" of XComGameState_Ability and XComGameState_Ability_CH. The sorting delegate there also does calls to GetGameState and GetShotBreakDown
Should be noted that the default implementation of GatherAbilityTargets
is native and only in some edge cases for very specific abilities, the implementation in XComGameState_Ability_CH
is used. See the comments in that file for details.
UpdateVisibleEnemies of UITacticalHUD_Enemies sorts the array of visible enemies by hit chance using a comparer delegate.
This sorting delegate determines the hit change, by calling GetHitChanceForObjectRef on object A and B, which is relatively slow, and calls it multiple times for the same objects, until the array is fully sorted.
The hit chance for the same object reference cannot change during one sorting pass, so pre-calculating the hit chances for visible enemies first. Then using that in the sorting delegate would decrease the number of calls drastically.
Before:![image](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/assets/130373/ec8e81f0-40d6-4038-b17b-dc6e3e99c766)
After:![image](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/assets/130373/3da49553-ea2f-4fc5-b21e-122f38b64843)
Note that I used the override of UITacticalHUD_Enemies from 'WOTC_DisplayHitChange' to do my test, which was easier for now than to build a custom CHL.
The profiling was done on the exact same save, same conditions, same move. Reduced the number of calls in that one frame, from 378 to 48.
Not sure if the above implementation is ideal, that's the best I could do with my limited UnrealScript knowledge. Maybe it's also possible with a class variable, then using CachedHitChanges.Find('Object', ObjectA) (which is a hashtable lookup?) inside SortEnemies.
discord: https://discord.com/channels/165245941664710656/165245941664710656/1137333029837209630