Misc constructor caching

Cache trait look-ups in constructor for various other traits and
activities.
This commit is contained in:
reaperrr
2015-03-14 04:00:39 +01:00
parent 1e9d1a6cb7
commit b52d055eec
11 changed files with 70 additions and 48 deletions

View File

@@ -17,17 +17,24 @@ namespace OpenRA.Mods.Common.Activities
{
class ExternalCaptureActor : Activity
{
Target target;
readonly ExternalCapturable capturable;
readonly ExternalCapturesInfo capturesInfo;
readonly Mobile mobile;
readonly Target target;
public ExternalCaptureActor(Target target) { this.target = target; }
public ExternalCaptureActor(Actor self, Target target)
{
this.target = target;
capturable = target.Actor.Trait<ExternalCapturable>();
capturesInfo = self.Info.Traits.Get<ExternalCapturesInfo>();
mobile = self.Trait<Mobile>();
}
public override Activity Tick(Actor self)
{
if (target.Type != TargetType.Actor)
return NextActivity;
var capturable = target.Actor.Trait<ExternalCapturable>();
if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
{
if (capturable.CaptureInProgress)
@@ -36,7 +43,6 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
var mobile = self.Trait<Mobile>();
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
if ((nearest - mobile.ToCell).LengthSquared > 2)
@@ -56,8 +62,6 @@ namespace OpenRA.Mods.Common.Activities
if (capturable.CaptureProgressTime == capturable.Info.CaptureCompleteTime * 25)
{
var capturesInfo = self.Info.Traits.Get<ExternalCapturesInfo>();
self.World.AddFrameEndTask(w =>
{
if (target.Actor.IsDead)