Make IsDisabled a method on Actor.
This allows us to cache the disabled traits, which simplifies life for some callers since we relieve them of having to cache it, as well as improving perf for all IsDisabled calls.
This commit is contained in:
@@ -54,11 +54,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
|
||||
|
||||
if (info.PauseOnLowPower)
|
||||
{
|
||||
var disabled = self.TraitsImplementing<IDisable>();
|
||||
DefaultAnimation.Paused = () => disabled.Any(d => d.Disabled)
|
||||
&& DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, info.Sequence);
|
||||
}
|
||||
DefaultAnimation.Paused = () =>
|
||||
self.IsDisabled() && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, info.Sequence);
|
||||
}
|
||||
|
||||
public void PlayCustomAnimThen(Actor self, string name, Action a)
|
||||
|
||||
@@ -30,13 +30,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class WithActiveAnimation : ITick, INotifyBuildComplete, INotifySold
|
||||
{
|
||||
readonly IEnumerable<IDisable> disabled;
|
||||
readonly WithActiveAnimationInfo info;
|
||||
readonly RenderBuilding renderBuilding;
|
||||
|
||||
public WithActiveAnimation(Actor self, WithActiveAnimationInfo info)
|
||||
{
|
||||
disabled = self.TraitsImplementing<IDisable>();
|
||||
renderBuilding = self.Trait<RenderBuilding>();
|
||||
this.info = info;
|
||||
}
|
||||
@@ -49,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
if (!(info.PauseOnLowPower && disabled.Any(d => d.Disabled)))
|
||||
if (!(info.PauseOnLowPower && self.IsDisabled()))
|
||||
renderBuilding.PlayCustomAnim(self, info.Sequence);
|
||||
ticks = info.Interval;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
var disabled = self.TraitsImplementing<IDisable>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
@@ -70,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
new AnimationWithOffset(overlay,
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
() => IsTraitDisabled || !buildComplete,
|
||||
() => info.PauseOnLowPower && disabled.Any(d => d.Disabled),
|
||||
() => info.PauseOnLowPower && self.IsDisabled(),
|
||||
p => WithTurret.ZOffsetFromCenter(self, p, 1)),
|
||||
info.Palette, info.IsPlayerPalette);
|
||||
}
|
||||
|
||||
@@ -27,19 +27,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class WithRepairAnimation : INotifyRepair
|
||||
{
|
||||
IEnumerable<IDisable> disabled;
|
||||
WithRepairAnimationInfo info;
|
||||
|
||||
public WithRepairAnimation(Actor self, WithRepairAnimationInfo info)
|
||||
{
|
||||
disabled = self.TraitsImplementing<IDisable>();
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void Repairing(Actor self, Actor host)
|
||||
{
|
||||
var building = host.TraitOrDefault<RenderBuilding>();
|
||||
if (building != null && !(info.PauseOnLowPower && disabled.Any(d => d.Disabled)))
|
||||
if (building != null && !(info.PauseOnLowPower && self.IsDisabled()))
|
||||
building.PlayCustomAnim(host, info.Sequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
var disabled = self.TraitsImplementing<IDisable>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
@@ -53,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
new AnimationWithOffset(overlay,
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
() => !buildComplete,
|
||||
() => info.PauseOnLowPower && disabled.Any(d => d.Disabled),
|
||||
() => info.PauseOnLowPower && self.IsDisabled(),
|
||||
p => WithTurret.ZOffsetFromCenter(self, p, 1)),
|
||||
info.Palette, info.IsPlayerPalette);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
static bool InstanceDisabled(SupportPower sp)
|
||||
{
|
||||
return sp.Self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
||||
return sp.Self.IsDisabled();
|
||||
}
|
||||
|
||||
bool notifiedCharging;
|
||||
|
||||
Reference in New Issue
Block a user