Remove ApplyToAllTargetablePositions hack from RectangleShape

In its current form it is bad for performance due to the ITargetablePositions look-up, and fixing that only to remove the hack entirely a few weeks later would be kind of pointless, so let's get this over with.
This commit is contained in:
reaperrr
2017-06-29 01:34:52 +02:00
parent f75115a645
commit 3f8efb1163
2 changed files with 26 additions and 30 deletions

View File

@@ -38,10 +38,6 @@ namespace OpenRA.Mods.Common.HitShapes
"Mobile actors do NOT need this!")] "Mobile actors do NOT need this!")]
public readonly WAngle LocalYaw = WAngle.Zero; public readonly WAngle LocalYaw = WAngle.Zero;
// This is just a temporary work-around until we have a customizable PolygonShape
[Desc("Applies shape to every TargetablePosition instead of just CenterPosition.")]
public readonly bool ApplyToAllTargetablePositions = false;
int2 quadrantSize; int2 quadrantSize;
int2 center; int2 center;
@@ -103,13 +99,6 @@ namespace OpenRA.Mods.Common.HitShapes
var actorPos = actor.CenterPosition; var actorPos = actor.CenterPosition;
var orientation = actor.Orientation + WRot.FromYaw(LocalYaw); var orientation = actor.Orientation + WRot.FromYaw(LocalYaw);
var targetablePositions = actor.TraitsImplementing<ITargetablePositions>();
if (ApplyToAllTargetablePositions && targetablePositions.Any())
{
var positions = targetablePositions.SelectMany(tp => tp.TargetablePositions(actor));
actorPos = positions.PositionClosestTo(pos);
}
if (pos.Z > actorPos.Z + VerticalTopOffset) if (pos.Z > actorPos.Z + VerticalTopOffset)
return DistanceFromEdge((pos - (actorPos + new WVec(0, 0, VerticalTopOffset))).Rotate(-orientation)); return DistanceFromEdge((pos - (actorPos + new WVec(0, 0, VerticalTopOffset))).Rotate(-orientation));
@@ -124,25 +113,10 @@ namespace OpenRA.Mods.Common.HitShapes
var actorPos = actor.CenterPosition; var actorPos = actor.CenterPosition;
var orientation = actor.Orientation + WRot.FromYaw(LocalYaw); var orientation = actor.Orientation + WRot.FromYaw(LocalYaw);
var targetablePositions = actor.TraitsImplementing<ITargetablePositions>(); var vertsTop = combatOverlayVertsTop.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
if (ApplyToAllTargetablePositions && targetablePositions.Any()) var vertsBottom = combatOverlayVertsBottom.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
{ wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow);
var positions = targetablePositions.SelectMany(tp => tp.TargetablePositions(actor)); wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow);
foreach (var pos in positions)
{
var vertsTop = combatOverlayVertsTop.Select(v => wr.Screen3DPosition(pos + v.Rotate(orientation)));
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.Screen3DPosition(pos + v.Rotate(orientation)));
wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow);
wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow);
}
}
else
{
var vertsTop = combatOverlayVertsTop.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow);
wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow);
}
RangeCircleRenderable.DrawRangeCircle(wr, actorPos, OuterRadius, 1, Color.LimeGreen, 0, Color.LimeGreen); RangeCircleRenderable.DrawRangeCircle(wr, actorPos, OuterRadius, 1, Color.LimeGreen, 0, Color.LimeGreen);
} }

View File

@@ -749,6 +749,28 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
// Removed ApplyToAllTargetablePositions hack from Rectangle shape
if (engineVersion < 20170629)
{
if (node.Key.StartsWith("HitShape", StringComparison.Ordinal))
{
var shape = node.Value.Nodes.FirstOrDefault(n => n.Key == "Type" && n.Value.Value == "Rectangle");
if (shape != null)
{
var hack = shape.Value.Nodes.FirstOrDefault(n => n.Key == "ApplyToAllTargetablePositions");
if (hack != null)
{
Console.WriteLine("Rectangle.ApplyToAllTargetablePositions has been removed due to incompatibilities");
Console.WriteLine("with the HitShape refactor and projectile/warhead victim scans, as well as performance concerns.");
Console.WriteLine("If you absolutely want to use it, please ship a duplicate of the old Rectangle code with your mod code.");
Console.WriteLine("Otherwise, we recommend using inheritable shape templates for rectangular buildings");
Console.WriteLine("and custom setups for the rest (see our official mods for examples).");
shape.Value.Nodes.Remove(hack);
}
}
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
} }