remove trait lookup spam everywhere for IOccupySpace.

This commit is contained in:
Chris Forbes
2011-08-02 19:43:02 +12:00
parent aff3111eac
commit 663a323f29
11 changed files with 35 additions and 37 deletions

View File

@@ -24,26 +24,26 @@ namespace OpenRA
public readonly World World;
public readonly uint ActorID;
IOccupySpace OccupiesSpace;
Lazy<IOccupySpace> occupySpace;
IHasLocation HasLocation;
Lazy<IMove> Move;
public Cached<Rectangle> Bounds;
public Cached<Rectangle> ExtendedBounds;
public int2 Location
{ get {
if (OccupiesSpace == null)
OccupiesSpace = Trait<IOccupySpace>();
return OccupiesSpace.TopLeft;
}}
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
public int2 Location { get { return occupySpace.Value.TopLeft; } }
public int2 CenterLocation
{ get {
if (HasLocation == null)
HasLocation = Trait<IHasLocation>();
return HasLocation.PxPosition;
}}
{
get
{
if (HasLocation == null)
HasLocation = Trait<IHasLocation>();
return HasLocation.PxPosition;
}
}
[Sync]
public Player Owner;
@@ -60,6 +60,8 @@ namespace OpenRA
if( initDict.Contains<OwnerInit>() )
Owner = init.Get<OwnerInit,Player>();
occupySpace = Lazy.New( () => TraitOrDefault<IOccupySpace>() );
if (name != null)
{
if (!Rules.Info.ContainsKey(name.ToLowerInvariant()))