Change ActorIndex to work in terms of TraitInfo, instead of Trait.

This allows actor.Info.HasTraitInfo to be used when checking if an actor needs to be added to the index, which is a cheaper call than actor.TraitsImplementing.
This commit is contained in:
RoosterDragon
2024-09-14 18:32:54 +01:00
committed by Gustas
parent 327c1ba23b
commit ab50182c92
7 changed files with 33 additions and 31 deletions

View File

@@ -70,8 +70,8 @@ namespace OpenRA.Mods.Common.Traits
readonly Func<Actor, bool> unitCannotBeOrdered;
readonly Dictionary<Actor, HarvesterTraitWrapper> harvesters = new();
readonly Stack<HarvesterTraitWrapper> harvestersNeedingOrders = new();
readonly ActorIndex.OwnerAndNamesAndTrait<Building> refineries;
readonly ActorIndex.OwnerAndNamesAndTrait<Harvester> harvestersIndex;
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> refineries;
readonly ActorIndex.OwnerAndNamesAndTrait<HarvesterInfo> harvestersIndex;
readonly Dictionary<CPos, string> resourceTypesByCell = new();
IResourceLayer resourceLayer;
@@ -85,8 +85,8 @@ namespace OpenRA.Mods.Common.Traits
world = self.World;
player = self.Owner;
unitCannotBeOrdered = a => a.Owner != self.Owner || a.IsDead || !a.IsInWorld;
refineries = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.RefineryTypes, player);
harvestersIndex = new ActorIndex.OwnerAndNamesAndTrait<Harvester>(world, info.HarvesterTypes, player);
refineries = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.RefineryTypes, player);
harvestersIndex = new ActorIndex.OwnerAndNamesAndTrait<HarvesterInfo>(world, info.HarvesterTypes, player);
}
protected override void Created(Actor self)