Merge pull request #10148 from pchote/widelines
Rewrite line renderer: Part 1 (improved lasers plus other cleanups)
This commit is contained in:
@@ -35,6 +35,9 @@ namespace OpenRA.Mods.Common.Effects
|
||||
[Desc("The width of the beam.")]
|
||||
public readonly WDist Width = new WDist(512);
|
||||
|
||||
[Desc("The shape of the beam. Accepts values Cylindrical or Flat.")]
|
||||
public readonly BeamRenderableShape Shape = BeamRenderableShape.Cylindrical;
|
||||
|
||||
[Desc("How far beyond the target the projectile keeps on travelling.")]
|
||||
public readonly WDist BeyondTargetRange = new WDist(0);
|
||||
|
||||
@@ -190,9 +193,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
{
|
||||
if (!IsBeamComplete && info.RenderBeam && !(wr.World.FogObscures(tailPos) && wr.World.FogObscures(headPos)))
|
||||
{
|
||||
float width, y, z;
|
||||
wr.ScreenVectorComponents(new WVec(info.Width, WDist.Zero, WDist.Zero), out width, out y, out z);
|
||||
var beamRender = new BeamRenderable(headPos, 0, tailPos - headPos, width, color);
|
||||
var beamRender = new BeamRenderable(headPos, 0, tailPos - headPos, info.Shape, info.Width, color);
|
||||
return new[] { (IRenderable)beamRender };
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace OpenRA.Mods.Common.Effects
|
||||
[Desc("Not a sprite, but an engine effect.")]
|
||||
class LaserZapInfo : IProjectileInfo
|
||||
{
|
||||
public readonly int BeamWidth = 2;
|
||||
[Desc("The width of the zap.")]
|
||||
public readonly WDist Width = new WDist(86);
|
||||
|
||||
[Desc("The shape of the beam. Accepts values Cylindrical or Flat.")]
|
||||
public readonly BeamRenderableShape Shape = BeamRenderableShape.Cylindrical;
|
||||
|
||||
public readonly int BeamDuration = 10;
|
||||
|
||||
@@ -98,7 +102,7 @@ namespace OpenRA.Mods.Common.Effects
|
||||
if (ticks < info.BeamDuration)
|
||||
{
|
||||
var rc = Color.FromArgb((info.BeamDuration - ticks) * 255 / info.BeamDuration, color);
|
||||
yield return new BeamRenderable(args.Source, 0, target - args.Source, info.BeamWidth, rc);
|
||||
yield return new BeamRenderable(args.Source, 0, target - args.Source, info.Shape, info.Width, rc);
|
||||
}
|
||||
|
||||
if (hitanim != null)
|
||||
|
||||
@@ -13,21 +13,24 @@ using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
public enum BeamRenderableShape { Cylindrical, Flat }
|
||||
public struct BeamRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
readonly WPos pos;
|
||||
readonly int zOffset;
|
||||
readonly WVec length;
|
||||
readonly BeamRenderableShape shape;
|
||||
readonly WDist width;
|
||||
readonly Color color;
|
||||
readonly float width;
|
||||
|
||||
public BeamRenderable(WPos pos, int zOffset, WVec length, float width, Color color)
|
||||
public BeamRenderable(WPos pos, int zOffset, WVec length, BeamRenderableShape shape, WDist width, Color color)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.zOffset = zOffset;
|
||||
this.length = length;
|
||||
this.color = color;
|
||||
this.shape = shape;
|
||||
this.width = width;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return pos; } }
|
||||
@@ -35,22 +38,35 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public int ZOffset { get { return zOffset; } }
|
||||
public bool IsDecoration { get { return true; } }
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return new BeamRenderable(pos, zOffset, length, width, color); }
|
||||
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, width, color); }
|
||||
public IRenderable OffsetBy(WVec vec) { return new BeamRenderable(pos + vec, zOffset, length, width, color); }
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
|
||||
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
|
||||
public IRenderable OffsetBy(WVec vec) { return new BeamRenderable(pos + vec, zOffset, length, shape, width, color); }
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
var src = wr.ScreenPosition(pos);
|
||||
var dest = wr.ScreenPosition(pos + length);
|
||||
var vecLength = length.Length;
|
||||
if (vecLength == 0)
|
||||
return;
|
||||
|
||||
var oldWidth = wlr.LineWidth;
|
||||
wlr.LineWidth = wr.Viewport.Zoom * width;
|
||||
wlr.DrawLine(src, dest, color);
|
||||
wlr.LineWidth = oldWidth;
|
||||
if (shape == BeamRenderableShape.Flat)
|
||||
{
|
||||
var delta = length * width.Length / (2 * vecLength);
|
||||
var corner = new WVec(-delta.Y, delta.X, delta.Z);
|
||||
var a = wr.ScreenPosition(pos - corner);
|
||||
var b = wr.ScreenPosition(pos + corner);
|
||||
var c = wr.ScreenPosition(pos + corner + length);
|
||||
var d = wr.ScreenPosition(pos - corner + length);
|
||||
Game.Renderer.WorldRgbaColorRenderer.FillRect(a, b, c, d, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
var start = wr.ScreenPosition(pos);
|
||||
var end = wr.ScreenPosition(pos + length);
|
||||
var screenWidth = wr.ScreenVector(new WVec(width, WDist.Zero, WDist.Zero))[0];
|
||||
Game.Renderer.WorldRgbaColorRenderer.DrawLine(start, end, screenWidth, color);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||
|
||||
88
OpenRA.Mods.Common/Graphics/DetectionCircleRenderable.cs
Normal file
88
OpenRA.Mods.Common/Graphics/DetectionCircleRenderable.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
public struct DetectionCircleRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
readonly WPos centerPosition;
|
||||
readonly WDist radius;
|
||||
readonly int zOffset;
|
||||
readonly int trailCount;
|
||||
readonly WAngle trailSeparation;
|
||||
readonly WAngle trailAngle;
|
||||
readonly Color color;
|
||||
readonly Color contrastColor;
|
||||
|
||||
public DetectionCircleRenderable(WPos centerPosition, WDist radius, int zOffset,
|
||||
int lineTrails, WAngle trailSeparation, WAngle trailAngle, Color color, Color contrastColor)
|
||||
{
|
||||
this.centerPosition = centerPosition;
|
||||
this.radius = radius;
|
||||
this.zOffset = zOffset;
|
||||
this.trailCount = lineTrails;
|
||||
this.trailSeparation = trailSeparation;
|
||||
this.trailAngle = trailAngle;
|
||||
this.color = color;
|
||||
this.contrastColor = contrastColor;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return centerPosition; } }
|
||||
public PaletteReference Palette { get { return null; } }
|
||||
public int ZOffset { get { return zOffset; } }
|
||||
public bool IsDecoration { get { return true; } }
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition, radius, zOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable WithZOffset(int newOffset)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition, radius, newOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable OffsetBy(WVec vec)
|
||||
{
|
||||
return new DetectionCircleRenderable(centerPosition + vec, radius, zOffset,
|
||||
trailCount, trailAngle, trailSeparation, color, contrastColor);
|
||||
}
|
||||
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
var center = wr.ScreenPosition(centerPosition);
|
||||
|
||||
for (var i = 0; i < trailCount; i++)
|
||||
{
|
||||
var angle = trailAngle - new WAngle(i * (trailSeparation.Angle <= 512 ? 1 : -1));
|
||||
var length = radius.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
|
||||
var end = wr.ScreenPosition(centerPosition + length);
|
||||
var alpha = color.A - i * color.A / trailCount;
|
||||
|
||||
wcr.DrawLine(center, end, 3, Color.FromArgb(alpha, contrastColor));
|
||||
wcr.DrawLine(center, end, 1, Color.FromArgb(alpha, color));
|
||||
}
|
||||
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, centerPosition, radius, 1, color, 3, contrastColor);
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,10 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
public struct RangeCircleRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
const int RangeCircleSegments = 32;
|
||||
static readonly int[][] RangeCircleStartRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i).AsMatrix());
|
||||
static readonly int[][] RangeCircleEndRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i + 6).AsMatrix());
|
||||
|
||||
readonly WPos centerPosition;
|
||||
readonly WDist radius;
|
||||
readonly int zOffset;
|
||||
@@ -43,13 +47,25 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
var oldWidth = wlr.LineWidth;
|
||||
wlr.LineWidth = 3;
|
||||
wr.DrawRangeCircle(centerPosition, radius, contrastColor);
|
||||
wlr.LineWidth = 1;
|
||||
wr.DrawRangeCircle(centerPosition, radius, color);
|
||||
wlr.LineWidth = oldWidth;
|
||||
DrawRangeCircle(wr, centerPosition, radius, 1, color, 3, contrastColor);
|
||||
}
|
||||
|
||||
public static void DrawRangeCircle(WorldRenderer wr, WPos centerPosition, WDist radius,
|
||||
float width, Color color, float contrastWidth, Color contrastColor)
|
||||
{
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
var offset = new WVec(radius.Length, 0, 0);
|
||||
for (var i = 0; i < RangeCircleRenderable.RangeCircleSegments; i++)
|
||||
{
|
||||
var a = wr.ScreenPosition(centerPosition + offset.Rotate(RangeCircleRenderable.RangeCircleStartRotations[i]));
|
||||
var b = wr.ScreenPosition(centerPosition + offset.Rotate(RangeCircleRenderable.RangeCircleEndRotations[i]));
|
||||
|
||||
if (contrastWidth > 0)
|
||||
wcr.DrawLine(a, b, contrastWidth / wr.Viewport.Zoom, contrastColor);
|
||||
|
||||
if (width > 0)
|
||||
wcr.DrawLine(a, b, width / wr.Viewport.Zoom, color);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr) { }
|
||||
|
||||
@@ -713,6 +713,7 @@
|
||||
<Compile Include="Widgets\Logic\MultiplayerLogic.cs" />
|
||||
<Compile Include="EditorBrushes\EditorCopyPasteBrush.cs" />
|
||||
<Compile Include="Traits\World\EditorSelectionLayer.cs" />
|
||||
<Compile Include="Graphics\DetectionCircleRenderable.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -48,7 +49,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
if (healthInfo != null)
|
||||
wr.DrawRangeCircle(self.CenterPosition, healthInfo.Radius, Color.Red);
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, self.CenterPosition, healthInfo.Radius,
|
||||
1, Color.Red, 0, Color.Red);
|
||||
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
|
||||
|
||||
@@ -19,14 +19,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class RenderDetectionCircleInfo : ITraitInfo, Requires<DetectCloakedInfo>
|
||||
{
|
||||
[Desc("Draw a rotating radar scanner update line, disabled by default.")]
|
||||
public readonly bool DrawUpdateLine = false;
|
||||
|
||||
[Desc("WAngle the Radar update line advances per tick.")]
|
||||
public readonly WAngle UpdateLineTick = new WAngle(-1);
|
||||
|
||||
[Desc("Number of trailing Radar update lines, will only draw one line if zero.")]
|
||||
public readonly int LineTrailLength = 3;
|
||||
[Desc("Number of trailing Radar update lines.")]
|
||||
public readonly int TrailCount = 0;
|
||||
|
||||
[Desc("Color of the circle and scanner update line.")]
|
||||
public readonly Color Color = Color.FromArgb(128, Color.LimeGreen);
|
||||
@@ -62,34 +59,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (range == WDist.Zero)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
yield return new DetectionCircleRenderable(
|
||||
self.CenterPosition,
|
||||
range,
|
||||
0,
|
||||
info.TrailCount,
|
||||
info.UpdateLineTick,
|
||||
lineAngle,
|
||||
info.Color,
|
||||
info.ContrastColor);
|
||||
|
||||
if (info.DrawUpdateLine)
|
||||
{
|
||||
for (var i = info.LineTrailLength; i >= 0; i--)
|
||||
{
|
||||
var angle = lineAngle - new WAngle(i * (info.UpdateLineTick.Angle <= 512 ? 1 : -1));
|
||||
var length = range.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
|
||||
var alpha = info.Color.A - (info.LineTrailLength > 0 ? i * info.Color.A / info.LineTrailLength : 0);
|
||||
yield return new BeamRenderable(
|
||||
self.CenterPosition,
|
||||
0,
|
||||
length,
|
||||
3,
|
||||
Color.FromArgb(alpha, info.ContrastColor));
|
||||
yield return new BeamRenderable(
|
||||
self.CenterPosition,
|
||||
0,
|
||||
length,
|
||||
1,
|
||||
Color.FromArgb(alpha, info.Color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!Visible)
|
||||
return;
|
||||
|
||||
var qr = Game.Renderer.WorldQuadRenderer;
|
||||
var qr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
var doDim = refreshTick - world.WorldTick <= 0;
|
||||
if (doDim) refreshTick = world.WorldTick + 20;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var pos = wr.World.Map.CenterOfCell(uv.ToCPos(map));
|
||||
var tl = wr.ScreenPxPosition(pos - new WVec(512, 512, 0));
|
||||
var br = wr.ScreenPxPosition(pos + new WVec(511, 511, 0));
|
||||
qr.FillRect(RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y), Color.FromArgb(w, c));
|
||||
qr.FillRect(tl, br, Color.FromArgb(w, c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -66,7 +67,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var alpha = 255.0f * i.Time / info.DisplayDuration;
|
||||
var rangeStep = alpha / i.Range.Length;
|
||||
|
||||
wr.DrawRangeCircle(i.CenterPosition, i.OuterRange, Color.FromArgb((int)alpha, i.Color));
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, i.CenterPosition, i.OuterRange,
|
||||
1, Color.FromArgb((int)alpha, i.Color), 0, i.Color);
|
||||
|
||||
foreach (var r in i.Range)
|
||||
{
|
||||
@@ -74,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var br = wr.ScreenPosition(i.CenterPosition + new WVec(r.Length, r.Length, 0));
|
||||
var rect = RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y);
|
||||
|
||||
Game.Renderer.WorldLineRenderer.FillEllipse(rect, Color.FromArgb((int)alpha, i.Color));
|
||||
Game.Renderer.WorldRgbaColorRenderer.FillEllipse(rect, Color.FromArgb((int)alpha, i.Color));
|
||||
|
||||
alpha -= rangeStep;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var tempPos = new float2(item.PosX + topLeft.X, item.PosY + topLeft.Y);
|
||||
|
||||
if (info.UseSquares)
|
||||
Game.Renderer.WorldQuadRenderer.FillRect(new RectangleF(tempPos.X, tempPos.Y, item.Size, item.Size), item.Color);
|
||||
Game.Renderer.WorldRgbaColorRenderer.FillRect(tempPos, tempPos + new float2(item.Size, item.Size), item.Color);
|
||||
else
|
||||
{
|
||||
var tempPosTail = new float2(topLeft.X + item.PosX - currentWindXOffset, item.PosY - (item.Gravity * 2 / 3) + topLeft.Y);
|
||||
|
||||
@@ -3178,6 +3178,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
}
|
||||
|
||||
if (engineVersion < 20151129)
|
||||
{
|
||||
if (node.Key == "BeamWidth" && parent.Value.Value == "LaserZap")
|
||||
{
|
||||
node.Key = "Width";
|
||||
ConvertPxToRange(ref node.Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeWeaponRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +96,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
}
|
||||
else
|
||||
Game.Renderer.LineRenderer.FillRect(new Rectangle(
|
||||
b.X, (int)float2.Lerp(b.Bottom, b.Top, providedFrac),
|
||||
b.Width, (int)(providedFrac * b.Height)), color);
|
||||
{
|
||||
var tl = new float2(b.X, (int)float2.Lerp(b.Bottom, b.Top, providedFrac));
|
||||
var br = tl + new float2(b.Width, (int)(providedFrac * b.Height));
|
||||
Game.Renderer.RgbaColorRenderer.FillRect(tl, br, color);
|
||||
}
|
||||
|
||||
var x = (b.Left + b.Right - indicator.Size.X) / 2;
|
||||
var y = float2.Lerp(b.Bottom, b.Top, usedFrac) - indicator.Size.Y / 2;
|
||||
@@ -126,7 +128,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
}
|
||||
else
|
||||
Game.Renderer.LineRenderer.FillRect(new Rectangle(b.X, b.Y, (int)(providedFrac * b.Width), b.Height), color);
|
||||
{
|
||||
var tl = new float2(b.X, b.Y);
|
||||
var br = tl + new float2((int)(providedFrac * b.Width), b.Height);
|
||||
Game.Renderer.RgbaColorRenderer.FillRect(tl, br, color);
|
||||
}
|
||||
|
||||
var x = float2.Lerp(b.Left, b.Right, usedFrac) - indicator.Size.X / 2;
|
||||
var y = (b.Bottom + b.Top - indicator.Size.Y) / 2;
|
||||
|
||||
Reference in New Issue
Block a user