Remove color caches
This commit is contained in:
committed by
Matthias Mailänder
parent
239891070d
commit
6b463f9d9e
@@ -21,9 +21,12 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
public int Length => trail.Length;
|
||||
|
||||
readonly Actor owner;
|
||||
readonly World world;
|
||||
readonly Color startcolor;
|
||||
readonly Color endcolor;
|
||||
readonly Color startColor;
|
||||
readonly bool usePlayerStartColor;
|
||||
readonly Color endColor;
|
||||
readonly bool usePlayerEndColor;
|
||||
|
||||
// Store trail positions in a circular buffer
|
||||
readonly WPos[] trail;
|
||||
@@ -33,20 +36,23 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
int length;
|
||||
readonly int skip;
|
||||
|
||||
public ContrailRenderable(World world, Color startcolor, Color endcolor, WDist startWidth, WDist endWidth, int length, int skip, int zOffset)
|
||||
: this(world, new WPos[length], startWidth, endWidth, 0, 0, skip, startcolor, endcolor, zOffset) { }
|
||||
public ContrailRenderable(World world, Actor owner, Color startcolor, bool usePlayerStartColor, Color endcolor, bool usePlayerEndColor, WDist startWidth, WDist endWidth, int length, int skip, int zOffset)
|
||||
: this(world, owner, new WPos[length], startWidth, endWidth, 0, 0, skip, startcolor, usePlayerStartColor, endcolor, usePlayerEndColor, zOffset) { }
|
||||
|
||||
ContrailRenderable(World world, WPos[] trail, WDist startWidth, WDist endWidth, int next, int length, int skip, Color startcolor, Color endcolor, int zOffset)
|
||||
ContrailRenderable(World world, Actor owner, WPos[] trail, WDist startWidth, WDist endWidth, int next, int length, int skip, Color startColor, bool usePlayerStartColor, Color endColor, bool usePlayerEndColor, int zOffset)
|
||||
{
|
||||
this.world = world;
|
||||
this.owner = owner;
|
||||
this.trail = trail;
|
||||
this.startWidth = startWidth;
|
||||
this.endWidth = endWidth;
|
||||
this.next = next;
|
||||
this.length = length;
|
||||
this.skip = skip;
|
||||
this.startcolor = startcolor;
|
||||
this.endcolor = endcolor;
|
||||
this.startColor = startColor;
|
||||
this.usePlayerStartColor = usePlayerStartColor;
|
||||
this.usePlayerEndColor = usePlayerEndColor;
|
||||
this.endColor = endColor;
|
||||
ZOffset = zOffset;
|
||||
}
|
||||
|
||||
@@ -54,12 +60,12 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public int ZOffset { get; }
|
||||
public bool IsDecoration => true;
|
||||
|
||||
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), startWidth, endWidth, next, length, skip, startcolor, endcolor, newOffset); }
|
||||
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, owner, (WPos[])trail.Clone(), startWidth, endWidth, next, length, skip, startColor, usePlayerStartColor, endColor, usePlayerEndColor, newOffset); }
|
||||
public IRenderable OffsetBy(in WVec vec)
|
||||
{
|
||||
// Lambdas can't use 'in' variables, so capture a copy for later
|
||||
var offset = vec;
|
||||
return new ContrailRenderable(world, trail.Select(pos => pos + offset).ToArray(), startWidth, endWidth, next, length, skip, startcolor, endcolor, ZOffset);
|
||||
return new ContrailRenderable(world, owner, trail.Select(pos => pos + offset).ToArray(), startWidth, endWidth, next, length, skip, startColor, usePlayerStartColor, endColor, usePlayerEndColor, ZOffset);
|
||||
}
|
||||
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
@@ -68,7 +74,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
// Note: The length of contrail is now actually the number of the points to draw the contrail
|
||||
// and we require at least two points to draw a tail
|
||||
// and we require at least two points to draw a tail.
|
||||
var renderLength = length - skip;
|
||||
if (renderLength <= 1)
|
||||
return;
|
||||
@@ -76,14 +82,22 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var screenWidth = wr.ScreenVector(new WVec(1, 0, 0))[0];
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
|
||||
var startColor = this.startColor;
|
||||
if (usePlayerStartColor)
|
||||
startColor = Color.FromArgb(this.startColor.A, owner.OwnerColor());
|
||||
|
||||
var endColor = this.endColor;
|
||||
if (usePlayerEndColor)
|
||||
endColor = Color.FromArgb(this.endColor.A, owner.OwnerColor());
|
||||
|
||||
// Start of the first line segment is the tail of the list - don't smooth it.
|
||||
var curPos = trail[Index(next - skip - 1)];
|
||||
var curColor = startcolor;
|
||||
var curColor = startColor;
|
||||
|
||||
for (var i = 1; i < renderLength; i++)
|
||||
{
|
||||
var j = next - skip - 1 - i;
|
||||
var nextColor = Exts.ColorLerp(i / (renderLength - 1f), startcolor, endcolor);
|
||||
var nextColor = Exts.ColorLerp(i / (renderLength - 1f), startColor, endColor);
|
||||
|
||||
var nextX = 0L;
|
||||
var nextY = 0L;
|
||||
|
||||
Reference in New Issue
Block a user