Add FirstNonEmptyBounds method for IDecorationBounds interface.
This provides a more efficient way of determining the bounds by avoiding LINQ. A helper that works directly on arrays prevents allocation of an enumerator when the collection is know to be an array.
This commit is contained in:
@@ -163,10 +163,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
{
|
||||
var bounds = unit.TraitsImplementing<IDecorationBounds>()
|
||||
.Select(b => b.DecorationBounds(unit, wr))
|
||||
.FirstOrDefault(b => !b.IsEmpty);
|
||||
|
||||
var bounds = unit.TraitsImplementing<IDecorationBounds>().FirstNonEmptyBounds(unit, wr);
|
||||
yield return new SelectionBoxRenderable(unit, bounds, Color.Red);
|
||||
}
|
||||
}
|
||||
@@ -281,10 +278,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
{
|
||||
var bounds = unit.TraitsImplementing<IDecorationBounds>()
|
||||
.Select(b => b.DecorationBounds(unit, wr))
|
||||
.FirstOrDefault(b => !b.IsEmpty);
|
||||
|
||||
var bounds = unit.TraitsImplementing<IDecorationBounds>().FirstNonEmptyBounds(unit, wr);
|
||||
yield return new SelectionBoxRenderable(unit, bounds, Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user