remove trait lookup spam everywhere for IOccupySpace.
This commit is contained in:
@@ -25,25 +25,25 @@ 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()))
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace OpenRA
|
||||
map = world.Map;
|
||||
influence = new InfluenceNode[world.Map.MapSize.X, world.Map.MapSize.Y];
|
||||
|
||||
world.ActorAdded += a => Add( a, a.TraitOrDefault<IOccupySpace>() );
|
||||
world.ActorRemoved += a => Remove( a, a.TraitOrDefault<IOccupySpace>() );
|
||||
world.ActorAdded += a => Add( a, a.OccupiesSpace );
|
||||
world.ActorRemoved += a => Remove( a, a.OccupiesSpace );
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> GetUnitsAt( int2 a )
|
||||
@@ -71,8 +71,8 @@ namespace OpenRA
|
||||
if (!AnyUnitsAt(a))
|
||||
return true;
|
||||
|
||||
return new[]{SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||
SubCell.BottomLeft, SubCell.BottomRight}.Any(b => !AnyUnitsAt(a,b));
|
||||
return new[]{ SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||
SubCell.BottomLeft, SubCell.BottomRight }.Any(b => !AnyUnitsAt(a,b));
|
||||
}
|
||||
|
||||
public bool AnyUnitsAt(int2 a)
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public static IEnumerable<int2> GetVisOrigins(Actor a)
|
||||
{
|
||||
var ios = a.TraitOrDefault<IOccupySpace>();
|
||||
var ios = a.OccupiesSpace;
|
||||
if (ios != null)
|
||||
{
|
||||
var cells = ios.OccupiedCells();
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
// todo: clean this up
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () =>
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (!target.Trait<IOccupySpace>().OccupiedCells().Any(x => x.First == self.Location))
|
||||
if (!target.OccupiesSpace.OccupiedCells().Any(x => x.First == self.Location))
|
||||
return NextActivity;
|
||||
|
||||
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var nearest = target.Trait<IOccupySpace>().NearestCellTo( mobile.toCell );
|
||||
var nearest = target.OccupiesSpace.NearestCellTo( mobile.toCell );
|
||||
if( ( nearest - mobile.toCell ).LengthSquared > 2 )
|
||||
return Util.SequenceActivities( new MoveAdjacentTo( target ), this );
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
foreach (var t in target.TraitsImplementing<IAcceptSpy>())
|
||||
|
||||
@@ -35,12 +35,12 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if( IsCanceled || !target.IsValid) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
Pair<int2, SubCell>[] cells = new Pair<int2, SubCell>[] {};
|
||||
var cells = new Pair<int2, SubCell>[] {};
|
||||
if (target.IsActor)
|
||||
cells = target.Actor.Trait<IOccupySpace>().OccupiedCells().ToArray();
|
||||
cells = target.Actor.OccupiesSpace.OccupiedCells().ToArray();
|
||||
|
||||
if (cells.Length == 0)
|
||||
cells = new OpenRA.FileFormats.Pair<int2, SubCell>[] {
|
||||
cells = new [] {
|
||||
Pair.New(Util.CellContaining(target.CenterLocation), SubCell.FullCell) };
|
||||
|
||||
var ps1 = new PathSearch( self.World, mobile.Info, self.Owner )
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
if( !target.OccupiesSpace.OccupiedCells().Any( x => x.First == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
var health = target.Trait<Health>();
|
||||
|
||||
@@ -15,29 +15,25 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class AppearsOnRadarInfo : TraitInfo<AppearsOnRadar>
|
||||
public class AppearsOnRadarInfo : ITraitInfo
|
||||
{
|
||||
public readonly bool UseLocation = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new AppearsOnRadar(this); }
|
||||
}
|
||||
|
||||
public class AppearsOnRadar : IRadarSignature
|
||||
{
|
||||
AppearsOnRadarInfo info;
|
||||
IOccupySpace Space;
|
||||
|
||||
public AppearsOnRadar(AppearsOnRadarInfo info) { this.info = info; }
|
||||
|
||||
public IEnumerable<int2> RadarSignatureCells(Actor self)
|
||||
{
|
||||
if (info == null)
|
||||
info = self.Info.Traits.Get<AppearsOnRadarInfo>();
|
||||
|
||||
if (info.UseLocation)
|
||||
return new int2[] { self.Location };
|
||||
else
|
||||
{
|
||||
if (Space == null)
|
||||
Space = self.Trait<IOccupySpace>();
|
||||
return Space.OccupiedCells().Select(c => c.First);
|
||||
}
|
||||
return self.OccupiesSpace.OccupiedCells().Select(c => c.First);
|
||||
}
|
||||
|
||||
public Color RadarSignatureColor(Actor self)
|
||||
|
||||
Reference in New Issue
Block a user