1
0
forked from 0ad/0ad

Improve AttackEntitiesByPreference by short-circuiting on best possible preference.

Similar trick to D3446 / c87229aa48 - we can short-circuit if we find
units that match our best possible preference.
This is, in particular, almost a 40% wall time improvement on Combat
Demo Huge, but it should apply in a number of more normal cases.

Differential Revision: https://code.wildfiregames.com/D5020
This was SVN commit r27701.
This commit is contained in:
wraitii 2023-06-14 07:52:30 +00:00
parent 64efa0acf9
commit 298f207e5b

View File

@ -6438,7 +6438,15 @@ UnitAI.prototype.AttackEntitiesByPreference = function(ents)
if (!attackfilter(ent))
continue;
let pref = cmpAttack.GetPreference(ent);
if (pref === null || pref === undefined)
// If we match our best preference, we can try responding right away.
// This makes some common cases fast, like most soldiers having 'Human' as best preference,
// or ships having 'Ship'. And if there are no such targets, this doesn't do much more work.
if (pref === 0)
{
if (this.RespondToTargetedEntities([ent]))
return true;
}
else if (pref === null || pref === undefined)
entsWithoutPref.push(ent);
else if (!entsByPreferences[pref])
{