Use RgbaColorRenderer for rendering contrails.

This commit is contained in:
Paul Chote
2015-12-10 17:40:44 +00:00
parent c618c2d8ab
commit 310222eb0e
4 changed files with 20 additions and 15 deletions

View File

@@ -66,6 +66,7 @@ namespace OpenRA.Mods.Common.Effects
public readonly Color ContrailColor = Color.White;
public readonly bool ContrailUsePlayerColor = false;
public readonly int ContrailDelay = 1;
public readonly WDist ContrailWidth = new WDist(64);
public IEffect Create(ProjectileArgs args) { return new Bullet(this, args); }
}
@@ -127,7 +128,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0)
{
var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
contrail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
contrail = new ContrailRenderable(world, color, info.ContrailWidth, info.ContrailLength, info.ContrailDelay, 0);
}
trailPalette = info.TrailPalette;

View File

@@ -26,6 +26,9 @@ namespace OpenRA.Mods.Common.Effects
[Desc("Length of the trail (in ticks).")]
public readonly int TrailLength = 25;
[Desc("Width of the trail.")]
public readonly WDist TrailWidth = new WDist(64);
[Desc("RGB color of the contrail.")]
public readonly Color Color = Color.White;
@@ -48,7 +51,7 @@ namespace OpenRA.Mods.Common.Effects
this.info = info;
var color = info.UsePlayerColor ? ContrailRenderable.ChooseColor(self) : info.Color;
trail = new ContrailRenderable(self.World, color, info.TrailLength, 0, 0);
trail = new ContrailRenderable(self.World, color, info.TrailWidth, info.TrailLength, 0, 0);
body = self.Trait<BodyOrientation>();
}

View File

@@ -105,6 +105,8 @@ namespace OpenRA.Mods.Common.Effects
public readonly int ContrailLength = 0;
public readonly WDist ContrailWidth = new WDist(64);
public readonly Color ContrailColor = Color.White;
public readonly bool ContrailUsePlayerColor = false;
@@ -209,7 +211,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0)
{
var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
contrail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
contrail = new ContrailRenderable(world, color, info.ContrailWidth, info.ContrailLength, info.ContrailDelay, 0);
}
trailPalette = info.TrailPalette;

View File

@@ -24,17 +24,19 @@ namespace OpenRA.Mods.Common.Graphics
// Store trail positions in a circular buffer
readonly WPos[] trail;
readonly WDist width;
int next;
int length;
int skip;
public ContrailRenderable(World world, Color color, int length, int skip, int zOffset)
: this(world, new WPos[length], 0, 0, skip, color, zOffset) { }
public ContrailRenderable(World world, Color color, WDist width, int length, int skip, int zOffset)
: this(world, new WPos[length], width, 0, 0, skip, color, zOffset) { }
ContrailRenderable(World world, WPos[] trail, int next, int length, int skip, Color color, int zOffset)
ContrailRenderable(World world, WPos[] trail, WDist width, int next, int length, int skip, Color color, int zOffset)
{
this.world = world;
this.trail = trail;
this.width = width;
this.next = next;
this.length = length;
this.skip = skip;
@@ -47,9 +49,9 @@ namespace OpenRA.Mods.Common.Graphics
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return new ContrailRenderable(world, (WPos[])trail.Clone(), next, length, skip, color, zOffset); }
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), next, length, skip, color, newOffset); }
public IRenderable OffsetBy(WVec vec) { return new ContrailRenderable(world, trail.Select(pos => pos + vec).ToArray(), next, length, skip, color, zOffset); }
public IRenderable WithPalette(PaletteReference newPalette) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, color, zOffset); }
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, color, newOffset); }
public IRenderable OffsetBy(WVec vec) { return new ContrailRenderable(world, trail.Select(pos => pos + vec).ToArray(), width, next, length, skip, color, zOffset); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
@@ -59,9 +61,8 @@ namespace OpenRA.Mods.Common.Graphics
if (length - skip < 4)
return;
var wlr = Game.Renderer.WorldLineRenderer;
var oldWidth = wlr.LineWidth;
wlr.LineWidth = wr.Viewport.Zoom;
var screenWidth = wr.ScreenVector(new WVec(width, WDist.Zero, WDist.Zero))[0];
var wcr = Game.Renderer.WorldRgbaColorRenderer;
// Start of the first line segment is the tail of the list - don't smooth it.
var curPos = trail[Index(next - skip - 1)];
@@ -73,13 +74,11 @@ namespace OpenRA.Mods.Common.Graphics
var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent);
if (!world.FogObscures(curPos) && !world.FogObscures(nextPos))
wlr.DrawLine(wr.ScreenPosition(curPos), wr.ScreenPosition(nextPos), curColor, nextColor);
wcr.DrawLine(wr.ScreenPosition(curPos), wr.ScreenPosition(nextPos), screenWidth, curColor, nextColor);
curPos = nextPos;
curColor = nextColor;
}
wlr.LineWidth = oldWidth;
}
public void RenderDebugGeometry(WorldRenderer wr) { }