Speed up checks for IOccupySpace trait.

Eagerly load the trait (if it exists) in Actor, and use this reference to avoid having to perform self.Info.HasTraitInfo<IOccupySpaceInfo>() checks.
This commit is contained in:
RoosterDragon
2015-10-14 20:36:32 +01:00
parent 410f121a1e
commit 262ab408b5
5 changed files with 13 additions and 18 deletions

View File

@@ -35,12 +35,9 @@ namespace OpenRA.Mods.Common.Traits
public readonly ProductionInfo Info;
public string Faction { get; private set; }
readonly bool occupiesSpace;
public Production(ActorInitializer init, ProductionInfo info)
{
Info = info;
occupiesSpace = init.Self.Info.HasTraitInfo<IOccupySpaceInfo>();
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
@@ -60,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
new OwnerInit(self.Owner),
};
if (occupiesSpace)
if (self.OccupiesSpace != null)
{
exit = self.Location + exitinfo.ExitCell;
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
@@ -122,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
var exit = self.Info.TraitInfos<ExitInfo>().Shuffle(self.World.SharedRandom)
.FirstOrDefault(e => CanUseExit(self, producee, e));
if (exit != null || !occupiesSpace)
if (exit != null || self.OccupiesSpace == null)
{
DoProduction(self, producee, exit, factionVariant);
return true;