Remove legacy bounds code.

This commit is contained in:
Paul Chote
2017-12-09 00:01:00 +00:00
committed by reaperrr
parent bf57eceeec
commit c87409ed1a
83 changed files with 418 additions and 563 deletions

View File

@@ -48,9 +48,6 @@ namespace OpenRA
public int Generation;
public Rectangle RenderBounds { get; private set; }
public Rectangle SelectableBounds { get; private set; }
public Rectangle SelectionOverlayBounds { get; private set; }
public IEffectiveOwner EffectiveOwner { get; private set; }
public IOccupySpace OccupiesSpace { get; private set; }
public ITargetable[] Targetables { get; private set; }
@@ -113,14 +110,6 @@ namespace OpenRA
// PERF: Cache all these traits as soon as the actor is created. This is a fairly cheap one-off cost per
// actor that allows us to provide some fast implementations of commonly used methods that are relied on by
// performance-sensitive parts of the core game engine, such as pathfinding, visibility and rendering.
// RenderBounds are used for ScreenMap binning
// SelectableBounds define the selectable area of the actor
// SelectionOverlayBounds are used to draw the selection box and determine offsets for other selection overlays
RenderBounds = DetermineRenderBounds();
SelectableBounds = DetermineSelectableBounds();
SelectionOverlayBounds = DetermineSelectionOverlayBounds();
EffectiveOwner = TraitOrDefault<IEffectiveOwner>();
facing = TraitOrDefault<IFacing>();
health = TraitOrDefault<IHealth>();
@@ -135,44 +124,6 @@ namespace OpenRA
SyncHashes = TraitsImplementing<ISync>().Select(sync => new SyncHash(sync)).ToArray();
}
Rectangle DetermineRenderBounds()
{
var size = TraitsImplementing<IAutoRenderSize>().Select(x => x.RenderSize(this)).FirstOrDefault(Exts.IsTraitEnabled);
var offset = -size / 2;
return new Rectangle(offset.X, offset.Y, size.X, size.Y);
}
Rectangle DetermineSelectableBounds()
{
var si = Info.TraitInfoOrDefault<SelectableInfo>();
if (si == null || si.Bounds == null)
return RenderBounds;
var size = new int2(si.Bounds[0], si.Bounds[1]);
var offset = -size / 2;
if (si.Bounds.Length > 2)
offset += new int2(si.Bounds[2], si.Bounds[3]);
return new Rectangle(offset.X, offset.Y, size.X, size.Y);
}
Rectangle DetermineSelectionOverlayBounds()
{
var sd = Info.TraitInfoOrDefault<ISelectionDecorationsInfo>();
if (sd == null || sd.SelectionBoxBounds == null)
return SelectableBounds;
var size = new int2(sd.SelectionBoxBounds[0], sd.SelectionBoxBounds[1]);
var offset = -size / 2;
if (sd.SelectionBoxBounds.Length > 2)
offset += new int2(sd.SelectionBoxBounds[2], sd.SelectionBoxBounds[3]);
return new Rectangle(offset.X, offset.Y, size.X, size.Y);
}
public void Tick()
{
var wasIdle = IsIdle;

View File

@@ -263,6 +263,7 @@
<Compile Include="UtilityCommands\ClearInvalidModRegistrationsCommand.cs" />
<Compile Include="HotkeyManager.cs" />
<Compile Include="HotkeyDefinition.cs" />
<Compile Include="Traits\Interactable.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileSystem\Folder.cs" />

View File

@@ -0,0 +1,80 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Traits
{
[Desc("Used to enable mouse interaction on actors that are not Selectable.")]
public class InteractableInfo : ITraitInfo, IMouseBoundsInfo, IDecorationBoundsInfo
{
[Desc("Defines a custom rectangle for mouse interaction with the actor.",
"If null, the engine will guess an appropriate size based on the With*Body trait.",
"The first two numbers define the width and height of the rectangle.",
"The (optional) second two numbers define an x and y offset from the actor center.")]
public readonly int[] Bounds = null;
[Desc("Defines a custom rectangle for Decorations (e.g. the selection box).",
"If null, Bounds will be used instead")]
public readonly int[] DecorationBounds = null;
public virtual object Create(ActorInitializer init) { return new Interactable(this); }
}
public class Interactable : INotifyCreated, IMouseBounds, IDecorationBounds
{
readonly InteractableInfo info;
IAutoMouseBounds[] autoBounds;
public Interactable(InteractableInfo info)
{
this.info = info;
}
void INotifyCreated.Created(Actor self)
{
autoBounds = self.TraitsImplementing<IAutoMouseBounds>().ToArray();
}
Rectangle AutoBounds(Actor self, WorldRenderer wr)
{
return autoBounds.Select(s => s.AutoMouseoverBounds(self, wr)).FirstOrDefault(r => !r.IsEmpty);
}
Rectangle Bounds(Actor self, WorldRenderer wr, int[] bounds)
{
if (bounds == null)
return AutoBounds(self, wr);
var size = new int2(bounds[0], bounds[1]);
var offset = -size / 2;
if (bounds.Length > 2)
offset += new int2(bounds[2], bounds[3]);
var xy = wr.ScreenPxPosition(self.CenterPosition) + offset;
return new Rectangle(xy.X, xy.Y, size.X, size.Y);
}
Rectangle IMouseBounds.MouseoverBounds(Actor self, WorldRenderer wr)
{
return Bounds(self, wr, info.Bounds);
}
Rectangle IDecorationBounds.DecorationBounds(Actor self, WorldRenderer wr)
{
return Bounds(self, wr, info.DecorationBounds ?? info.Bounds);
}
}
}

View File

@@ -31,7 +31,6 @@ namespace OpenRA.Traits
{
public readonly PPos[] Footprint;
public readonly WPos CenterPosition;
public readonly Rectangle SelectableBounds;
public readonly HashSet<string> TargetTypes;
readonly Actor actor;
readonly Shroud shroud;
@@ -83,7 +82,6 @@ namespace OpenRA.Traits
footprint.Select(p => shroud.Contains(p).ToString()).JoinWith("|")));
CenterPosition = self.CenterPosition;
SelectableBounds = self.SelectableBounds;
TargetTypes = self.GetEnabledTargetTypes().ToHashSet();
tooltips = self.TraitsImplementing<ITooltip>().ToArray();

View File

@@ -16,65 +16,29 @@ using OpenRA.Graphics;
namespace OpenRA.Traits
{
[Desc("This actor is selectable. Defines bounds of selectable area, selection class and selection priority.")]
public class SelectableInfo : ITraitInfo, IDecorationBoundsInfo
public class SelectableInfo : InteractableInfo
{
public readonly int Priority = 10;
[Desc("Bounds for the selectable area.")]
public readonly int[] Bounds = null;
[Desc("Area outside the visible selection box that is enabled for selection")]
public readonly int Margin = 0;
[Desc("All units having the same selection class specified will be selected with select-by-type commands (e.g. double-click). "
+ "Defaults to the actor name when not defined or inherited.")]
public readonly string Class = null;
[VoiceReference] public readonly string Voice = "Select";
public object Create(ActorInitializer init) { return new Selectable(init.Self, this); }
public override object Create(ActorInitializer init) { return new Selectable(init.Self, this); }
}
public class Selectable : IMouseBounds, IDecorationBounds
public class Selectable : Interactable
{
public readonly string Class = null;
public SelectableInfo Info;
public readonly SelectableInfo Info;
public Selectable(Actor self, SelectableInfo info)
: base(info)
{
Class = string.IsNullOrEmpty(info.Class) ? self.Info.Name : info.Class;
Info = info;
}
Rectangle IMouseBounds.MouseoverBounds(Actor self, WorldRenderer wr)
{
if (Info.Bounds == null)
return Rectangle.Empty;
var size = new int2(Info.Bounds[0], Info.Bounds[1]);
var offset = -size / 2 - new int2(Info.Margin, Info.Margin);
if (Info.Bounds.Length > 2)
offset += new int2(Info.Bounds[2], Info.Bounds[3]);
var xy = wr.ScreenPxPosition(self.CenterPosition) + offset;
return new Rectangle(xy.X, xy.Y, size.X + 2 * Info.Margin, size.Y + 2 * Info.Margin);
}
Rectangle IDecorationBounds.DecorationBounds(Actor self, WorldRenderer wr)
{
if (Info.Bounds == null)
return Rectangle.Empty;
var size = new int2(Info.Bounds[0], Info.Bounds[1]);
var offset = -size / 2;
if (Info.Bounds.Length > 2)
offset += new int2(Info.Bounds[2], Info.Bounds[3]);
var xy = wr.ScreenPxPosition(self.CenterPosition) + offset;
return new Rectangle(xy.X, xy.Y, size.X, size.Y);
}
}
}

View File

@@ -102,20 +102,15 @@ namespace OpenRA.Traits
IEnumerable<Rectangle> ScreenBounds(Actor self, WorldRenderer wr);
}
public interface IAutoSelectionSizeInfo : ITraitInfoInterface { }
public interface IAutoSelectionSize { int2 SelectionSize(Actor self); }
// TODO: Replace Rectangle with an int2[] polygon
public interface IMouseBounds { Rectangle MouseoverBounds(Actor self, WorldRenderer wr); }
public interface IMouseBoundsInfo : ITraitInfoInterface { }
public interface IAutoMouseBounds { Rectangle AutoMouseoverBounds(Actor self, WorldRenderer wr); }
// HACK: This provides a shim for legacy code until it can be rewritten
public interface IDecorationBounds { Rectangle DecorationBounds(Actor self, WorldRenderer wr); }
public interface IDecorationBoundsInfo : ITraitInfoInterface { }
public interface IAutoRenderSizeInfo : ITraitInfoInterface { }
public interface IAutoRenderSize { int2 RenderSize(Actor self); }
public interface IIssueOrder
{
IEnumerable<IOrderTargeter> Orders { get; }
@@ -159,11 +154,6 @@ namespace OpenRA.Traits
public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); }
public interface INotifyEffectiveOwnerChanged { void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner); }
public interface ISelectionDecorationsInfo : ITraitInfoInterface
{
int[] SelectionBoxBounds { get; }
}
public interface IVoiced
{
string VoiceSet { get; }