From 4aee91cd4788279242a43a7195e23f1582cd5a21 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 5 Oct 2017 18:03:05 +0100 Subject: [PATCH] Remove unnecessary trait lookups when cloaking/decloaking. --- OpenRA.Mods.Common/Traits/Cloak.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Cloak.cs b/OpenRA.Mods.Common/Traits/Cloak.cs index f268de2512..d14cff2a69 100644 --- a/OpenRA.Mods.Common/Traits/Cloak.cs +++ b/OpenRA.Mods.Common/Traits/Cloak.cs @@ -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(); + otherCloaks = self.TraitsImplementing() + .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().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().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); }