Cache some trait lookups that occur frequently.
This commit is contained in:
@@ -315,13 +315,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var ret = InnerTick(self, Move.mobile);
|
||||
mobile.IsMoving = ret is MovePart;
|
||||
Move.mobile.IsMoving = ret is MovePart;
|
||||
|
||||
if (moveFraction > MoveFractionTotal)
|
||||
moveFraction = MoveFractionTotal;
|
||||
UpdateCenterLocation(self, mobile);
|
||||
UpdateCenterLocation(self, Move.mobile);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -312,6 +312,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
internal int TicksBeforePathing = 0;
|
||||
|
||||
readonly Actor self;
|
||||
readonly ISpeedModifier[] speedModifiers;
|
||||
public readonly MobileInfo Info;
|
||||
public bool IsMoving { get; set; }
|
||||
|
||||
@@ -351,6 +352,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self = init.Self;
|
||||
Info = info;
|
||||
|
||||
speedModifiers = self.TraitsImplementing<ISpeedModifier>().ToArray();
|
||||
|
||||
ToSubCell = FromSubCell = info.SharesCell ? init.World.Map.DefaultSubCell : SubCell.FullCell;
|
||||
if (init.Contains<SubCellInit>())
|
||||
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
||||
@@ -597,7 +600,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return 0;
|
||||
|
||||
speed *= Info.Speed;
|
||||
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
|
||||
foreach (var t in speedModifiers)
|
||||
speed *= t.GetSpeedModifier() / 100m;
|
||||
|
||||
return (int)(speed / 100);
|
||||
|
||||
@@ -27,9 +27,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
class WithMuzzleFlash : UpgradableTrait<WithMuzzleFlashInfo>, INotifyAttack, IRender, ITick
|
||||
{
|
||||
Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
|
||||
Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
|
||||
Func<int> getFacing;
|
||||
readonly Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
|
||||
readonly Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
|
||||
readonly Func<int> getFacing;
|
||||
readonly Armament[] armaments;
|
||||
|
||||
public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
|
||||
: base(info)
|
||||
@@ -37,7 +38,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var render = self.Trait<RenderSprites>();
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
|
||||
foreach (var arm in self.TraitsImplementing<Armament>())
|
||||
armaments = self.TraitsImplementing<Armament>().ToArray();
|
||||
|
||||
foreach (var arm in armaments)
|
||||
{
|
||||
var armClosure = arm; // closure hazard in AnimationWithOffset
|
||||
|
||||
@@ -87,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
foreach (var arm in self.TraitsImplementing<Armament>())
|
||||
foreach (var arm in armaments)
|
||||
{
|
||||
var palette = wr.Palette(arm.Info.MuzzlePalette);
|
||||
foreach (var kv in anims)
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class TurretedInfo : ITraitInfo, UsesInit<TurretFacingInit>
|
||||
public class TurretedInfo : ITraitInfo, UsesInit<TurretFacingInit>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
public readonly string Turret = "primary";
|
||||
[Desc("Rate of Turning")]
|
||||
@@ -34,6 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly TurretedInfo info;
|
||||
AttackTurreted attack;
|
||||
IFacing facing;
|
||||
IBodyOrientation body;
|
||||
|
||||
[Sync] public int QuantizedFacings = 0;
|
||||
[Sync] public int TurretFacing = 0;
|
||||
@@ -67,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
attack = self.TraitOrDefault<AttackTurreted>();
|
||||
facing = self.TraitOrDefault<IFacing>();
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
}
|
||||
|
||||
public virtual void Tick(Actor self)
|
||||
@@ -94,7 +96,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Turret offset in world-space
|
||||
public WVec Position(Actor self)
|
||||
{
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
|
||||
return body.LocalToWorld(Offset.Rotate(bodyOrientation));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user