Remove unnecessary trait lookups when cloaking/decloaking.

This commit is contained in:
Paul Chote
2017-10-05 18:03:05 +01:00
committed by abcdefg30
parent cf4c16b6bb
commit 4aee91cd47

View File

@@ -68,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits
[Sync] int remainingTime;
bool isDocking;
ConditionManager conditionManager;
Cloak[] otherCloaks;
CPos? lastPos;
bool wasCloaked = false;
@@ -83,6 +84,9 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
otherCloaks = self.TraitsImplementing<Cloak>()
.Where(c => c != this)
.ToArray();
if (Cloaked)
{
@@ -157,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
cloakedToken = conditionManager.GrantCondition(self, Info.CloakedCondition);
// Sounds shouldn't play if the actor starts cloaked
if (!(firstTick && Info.InitialDelay == 0) && !self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
if (!(firstTick && Info.InitialDelay == 0) && !otherCloaks.Any(a => a.Cloaked))
Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition);
}
else if (!isCloaked && wasCloaked)
@@ -165,7 +169,7 @@ namespace OpenRA.Mods.Common.Traits
if (cloakedToken != ConditionManager.InvalidConditionToken)
cloakedToken = conditionManager.RevokeCondition(self, cloakedToken);
if (!(firstTick && Info.InitialDelay == 0) && !self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
if (!(firstTick && Info.InitialDelay == 0) && !otherCloaks.Any(a => a.Cloaked))
Game.Sound.Play(SoundType.World, Info.UncloakSound, self.CenterPosition);
}