Cache some trait lookups that occur frequently.

This commit is contained in:
RoosterDragon
2015-04-20 21:21:09 +01:00
parent 6125d7c117
commit 500a33b590
4 changed files with 17 additions and 11 deletions

View File

@@ -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);