mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-18 22:33:56 -07:00
optimize the finding of new target (no changes on the output) when lots of units involved, fixes #3605
This was SVN commit r17264.
This commit is contained in:
parent
6b8dc7684a
commit
34fd23e920
1 changed files with 28 additions and 5 deletions
|
|
@ -5830,8 +5830,10 @@ UnitAI.prototype.SetFacePointAfterMove = function(val)
|
|||
|
||||
UnitAI.prototype.AttackEntitiesByPreference = function(ents)
|
||||
{
|
||||
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
||||
if (!ents.length)
|
||||
return false;
|
||||
|
||||
var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|
||||
if (!cmpAttack)
|
||||
return false;
|
||||
|
||||
|
|
@ -5843,10 +5845,31 @@ UnitAI.prototype.AttackEntitiesByPreference = function(ents)
|
|||
return cmpUnitAI && (!cmpUnitAI.IsAnimal() || cmpUnitAI.IsDangerousAnimal());
|
||||
};
|
||||
|
||||
return this.RespondToTargetedEntities(
|
||||
ents.filter(function (v) { return cmpAttack.CanAttack(v) && attackfilter(v); })
|
||||
.sort(function (a, b) { return cmpAttack.CompareEntitiesByPreference(a, b); })
|
||||
);
|
||||
let entsByPreferences = {};
|
||||
let preferences = [];
|
||||
for (let ent of ents)
|
||||
{
|
||||
if (!attackfilter(ent))
|
||||
continue;
|
||||
let pref = cmpAttack.GetPreference(ent);
|
||||
if (pref === null || pref === undefined)
|
||||
pref = 999;
|
||||
if (!entsByPreferences[pref])
|
||||
{
|
||||
preferences.push(pref);
|
||||
entsByPreferences[pref] = [ent];
|
||||
}
|
||||
else
|
||||
entsByPreferences[pref].push(ent);
|
||||
}
|
||||
if (!preferences.length)
|
||||
return false;
|
||||
preferences.sort((a, b) => a - b);
|
||||
for (let pref of preferences)
|
||||
if (this.RespondToTargetedEntities(entsByPreferences[pref]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue