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;
|
public int Length => trail.Length;
|
||||||
|
|
||||||
|
readonly Actor owner;
|
||||||
readonly World world;
|
readonly World world;
|
||||||
readonly Color startcolor;
|
readonly Color startColor;
|
||||||
readonly Color endcolor;
|
readonly bool usePlayerStartColor;
|
||||||
|
readonly Color endColor;
|
||||||
|
readonly bool usePlayerEndColor;
|
||||||
|
|
||||||
// Store trail positions in a circular buffer
|
// Store trail positions in a circular buffer
|
||||||
readonly WPos[] trail;
|
readonly WPos[] trail;
|
||||||
@@ -33,20 +36,23 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
int length;
|
int length;
|
||||||
readonly int skip;
|
readonly int skip;
|
||||||
|
|
||||||
public ContrailRenderable(World world, Color startcolor, Color endcolor, WDist startWidth, WDist endWidth, int length, int skip, int 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, new WPos[length], startWidth, endWidth, 0, 0, skip, startcolor, endcolor, 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.world = world;
|
||||||
|
this.owner = owner;
|
||||||
this.trail = trail;
|
this.trail = trail;
|
||||||
this.startWidth = startWidth;
|
this.startWidth = startWidth;
|
||||||
this.endWidth = endWidth;
|
this.endWidth = endWidth;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.skip = skip;
|
this.skip = skip;
|
||||||
this.startcolor = startcolor;
|
this.startColor = startColor;
|
||||||
this.endcolor = endcolor;
|
this.usePlayerStartColor = usePlayerStartColor;
|
||||||
|
this.usePlayerEndColor = usePlayerEndColor;
|
||||||
|
this.endColor = endColor;
|
||||||
ZOffset = zOffset;
|
ZOffset = zOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,12 +60,12 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
public int ZOffset { get; }
|
public int ZOffset { get; }
|
||||||
public bool IsDecoration => true;
|
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)
|
public IRenderable OffsetBy(in WVec vec)
|
||||||
{
|
{
|
||||||
// Lambdas can't use 'in' variables, so capture a copy for later
|
// Lambdas can't use 'in' variables, so capture a copy for later
|
||||||
var offset = vec;
|
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; }
|
public IRenderable AsDecoration() { return this; }
|
||||||
@@ -68,7 +74,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
// Note: The length of contrail is now actually the number of the points to draw the contrail
|
// 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;
|
var renderLength = length - skip;
|
||||||
if (renderLength <= 1)
|
if (renderLength <= 1)
|
||||||
return;
|
return;
|
||||||
@@ -76,14 +82,22 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
var screenWidth = wr.ScreenVector(new WVec(1, 0, 0))[0];
|
var screenWidth = wr.ScreenVector(new WVec(1, 0, 0))[0];
|
||||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
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.
|
// Start of the first line segment is the tail of the list - don't smooth it.
|
||||||
var curPos = trail[Index(next - skip - 1)];
|
var curPos = trail[Index(next - skip - 1)];
|
||||||
var curColor = startcolor;
|
var curColor = startColor;
|
||||||
|
|
||||||
for (var i = 1; i < renderLength; i++)
|
for (var i = 1; i < renderLength; i++)
|
||||||
{
|
{
|
||||||
var j = next - skip - 1 - 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 nextX = 0L;
|
||||||
var nextY = 0L;
|
var nextY = 0L;
|
||||||
|
|||||||
@@ -201,9 +201,14 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
if (info.ContrailLength > 0)
|
if (info.ContrailLength > 0)
|
||||||
{
|
{
|
||||||
var startcolor = info.ContrailStartColorUsePlayerColor ? Color.FromArgb(info.ContrailStartColorAlpha, Player.ActorColor(args.SourceActor)) : Color.FromArgb(info.ContrailStartColorAlpha, info.ContrailStartColor);
|
var startcolor = Color.FromArgb(info.ContrailStartColorAlpha, info.ContrailStartColor);
|
||||||
var endcolor = info.ContrailEndColorUsePlayerColor ? Color.FromArgb(info.ContrailEndColorAlpha, Player.ActorColor(args.SourceActor)) : Color.FromArgb(info.ContrailEndColorAlpha, info.ContrailEndColor ?? startcolor);
|
var endcolor = Color.FromArgb(info.ContrailEndColorAlpha, info.ContrailEndColor ?? startcolor);
|
||||||
contrail = new ContrailRenderable(world, startcolor, endcolor, info.ContrailStartWidth, info.ContrailEndWidth ?? info.ContrailStartWidth, info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
|
contrail = new ContrailRenderable(world, args.SourceActor,
|
||||||
|
startcolor, info.ContrailStartColorUsePlayerColor,
|
||||||
|
endcolor, info.ContrailEndColor == null ? info.ContrailStartColorUsePlayerColor : info.ContrailEndColorUsePlayerColor,
|
||||||
|
info.ContrailStartWidth,
|
||||||
|
info.ContrailEndWidth ?? info.ContrailStartWidth,
|
||||||
|
info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
trailPalette = info.TrailPalette;
|
trailPalette = info.TrailPalette;
|
||||||
|
|||||||
@@ -285,9 +285,14 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
if (info.ContrailLength > 0)
|
if (info.ContrailLength > 0)
|
||||||
{
|
{
|
||||||
var startcolor = info.ContrailStartColorUsePlayerColor ? Color.FromArgb(info.ContrailStartColorAlpha, Player.ActorColor(args.SourceActor)) : Color.FromArgb(info.ContrailStartColorAlpha, info.ContrailStartColor);
|
var startcolor = Color.FromArgb(info.ContrailStartColorAlpha, info.ContrailStartColor);
|
||||||
var endcolor = info.ContrailEndColorUsePlayerColor ? Color.FromArgb(info.ContrailEndColorAlpha, Player.ActorColor(args.SourceActor)) : Color.FromArgb(info.ContrailEndColorAlpha, info.ContrailEndColor ?? startcolor);
|
var endcolor = Color.FromArgb(info.ContrailEndColorAlpha, info.ContrailEndColor ?? startcolor);
|
||||||
contrail = new ContrailRenderable(world, startcolor, endcolor, info.ContrailStartWidth, info.ContrailEndWidth ?? info.ContrailStartWidth, info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
|
contrail = new ContrailRenderable(world, args.SourceActor,
|
||||||
|
startcolor, info.ContrailStartColorUsePlayerColor,
|
||||||
|
endcolor, info.ContrailEndColor == null ? info.ContrailStartColorUsePlayerColor : info.ContrailEndColorUsePlayerColor,
|
||||||
|
info.ContrailStartWidth,
|
||||||
|
info.ContrailEndWidth ?? info.ContrailStartWidth,
|
||||||
|
info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
trailPalette = info.TrailPalette;
|
trailPalette = info.TrailPalette;
|
||||||
|
|||||||
@@ -75,9 +75,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
startcolor = info.StartColorUsePlayerColor ? Color.FromArgb(info.StartColorAlpha, Player.ActorColor(self)) : Color.FromArgb(info.StartColorAlpha, info.StartColor);
|
startcolor = Color.FromArgb(info.StartColorAlpha, info.StartColor);
|
||||||
endcolor = info.EndColorUsePlayerColor ? Color.FromArgb(info.EndColorAlpha, Player.ActorColor(self)) : Color.FromArgb(info.EndColorAlpha, info.EndColor ?? startcolor);
|
endcolor = Color.FromArgb(info.EndColorAlpha, info.EndColor ?? startcolor);
|
||||||
trail = new ContrailRenderable(self.World, startcolor, endcolor, info.StartWidth, info.EndWidth ?? info.StartWidth, info.TrailLength, info.TrailDelay, info.ZOffset);
|
trail = new ContrailRenderable(self.World, self,
|
||||||
|
startcolor, info.StartColorUsePlayerColor,
|
||||||
|
endcolor, info.EndColor == null ? info.StartColorUsePlayerColor : info.EndColorUsePlayerColor,
|
||||||
|
info.StartWidth,
|
||||||
|
info.EndWidth ?? info.StartWidth,
|
||||||
|
info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||||
|
|
||||||
body = self.Trait<BodyOrientation>();
|
body = self.Trait<BodyOrientation>();
|
||||||
}
|
}
|
||||||
@@ -106,7 +111,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
trail = new ContrailRenderable(self.World, startcolor, endcolor, info.StartWidth, info.EndWidth ?? info.StartWidth, info.TrailLength, info.TrailDelay, info.ZOffset);
|
trail = new ContrailRenderable(self.World, self,
|
||||||
|
startcolor, info.StartColorUsePlayerColor,
|
||||||
|
endcolor, info.EndColor == null ? info.StartColorUsePlayerColor : info.EndColorUsePlayerColor,
|
||||||
|
info.StartWidth,
|
||||||
|
info.EndWidth ?? info.StartWidth,
|
||||||
|
info.TrailLength, info.TrailDelay, info.ZOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
using OpenRA.Primitives;
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits.Render
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
@@ -26,14 +25,13 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public override object Create(ActorInitializer init) { return new RenderDebugState(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new RenderDebugState(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class RenderDebugState : INotifyAddedToWorld, INotifyOwnerChanged, INotifyCreated, IRenderAnnotationsWhenSelected
|
sealed class RenderDebugState : INotifyAddedToWorld, INotifyCreated, IRenderAnnotationsWhenSelected
|
||||||
{
|
{
|
||||||
readonly DebugVisualizations debugVis;
|
readonly DebugVisualizations debugVis;
|
||||||
readonly SpriteFont font;
|
readonly SpriteFont font;
|
||||||
readonly WVec offset;
|
readonly WVec offset;
|
||||||
SquadManagerBotModule[] squadManagerModules;
|
SquadManagerBotModule[] squadManagerModules;
|
||||||
|
|
||||||
Color color;
|
|
||||||
string tagString;
|
string tagString;
|
||||||
|
|
||||||
public RenderDebugState(Actor self, RenderDebugStateInfo info)
|
public RenderDebugState(Actor self, RenderDebugStateInfo info)
|
||||||
@@ -42,7 +40,6 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var yOffset = buildingInfo?.Dimensions.Y ?? 1;
|
var yOffset = buildingInfo?.Dimensions.Y ?? 1;
|
||||||
offset = new WVec(0, 512 * yOffset, 0);
|
offset = new WVec(0, 512 * yOffset, 0);
|
||||||
|
|
||||||
color = self.OwnerColor();
|
|
||||||
font = Game.Renderer.Fonts[info.Font];
|
font = Game.Renderer.Fonts[info.Font];
|
||||||
|
|
||||||
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
debugVis = self.World.WorldActor.TraitOrDefault<DebugVisualizations>();
|
||||||
@@ -58,13 +55,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
tagString = self.ToString();
|
tagString = self.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) => color = self.OwnerColor();
|
|
||||||
|
|
||||||
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)
|
IEnumerable<IRenderable> IRenderAnnotationsWhenSelected.RenderAnnotations(Actor self, WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (debugVis == null || !debugVis.ActorTags)
|
if (debugVis == null || !debugVis.ActorTags)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
|
var color = self.OwnerColor();
|
||||||
yield return new TextAnnotationRenderable(font, self.CenterPosition - offset, 0, color, tagString);
|
yield return new TextAnnotationRenderable(font, self.CenterPosition - offset, 0, color, tagString);
|
||||||
|
|
||||||
// Get the actor's activity.
|
// Get the actor's activity.
|
||||||
|
|||||||
@@ -45,14 +45,14 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public class WithNameTagDecoration : WithDecorationBase<WithNameTagDecorationInfo>, INotifyOwnerChanged
|
public class WithNameTagDecoration : WithDecorationBase<WithNameTagDecorationInfo>, INotifyOwnerChanged
|
||||||
{
|
{
|
||||||
readonly SpriteFont font;
|
readonly SpriteFont font;
|
||||||
|
readonly WithNameTagDecorationInfo info;
|
||||||
string name;
|
string name;
|
||||||
Color color;
|
|
||||||
|
|
||||||
public WithNameTagDecoration(Actor self, WithNameTagDecorationInfo info)
|
public WithNameTagDecoration(Actor self, WithNameTagDecorationInfo info)
|
||||||
: base(self, info)
|
: base(self, info)
|
||||||
{
|
{
|
||||||
font = Game.Renderer.Fonts[info.Font];
|
font = Game.Renderer.Fonts[info.Font];
|
||||||
color = info.UsePlayerColor ? self.OwnerColor() : info.Color;
|
this.info = info;
|
||||||
|
|
||||||
name = self.Owner.PlayerName;
|
name = self.Owner.PlayerName;
|
||||||
if (name.Length > info.MaxLength)
|
if (name.Length > info.MaxLength)
|
||||||
@@ -67,15 +67,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var size = font.Measure(name);
|
var size = font.Measure(name);
|
||||||
return new IRenderable[]
|
return new IRenderable[]
|
||||||
{
|
{
|
||||||
new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, color, name)
|
new UITextRenderable(font, self.CenterPosition, screenPos - size / 2, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, name)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
{
|
{
|
||||||
if (Info.UsePlayerColor)
|
|
||||||
color = self.OwnerColor();
|
|
||||||
|
|
||||||
name = self.Owner.PlayerName;
|
name = self.Owner.PlayerName;
|
||||||
if (name.Length > Info.MaxLength)
|
if (name.Length > Info.MaxLength)
|
||||||
name = name[..Info.MaxLength];
|
name = name[..Info.MaxLength];
|
||||||
|
|||||||
@@ -45,20 +45,16 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public override object Create(ActorInitializer init) { return new WithTextControlGroupDecoration(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new WithTextControlGroupDecoration(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithTextControlGroupDecoration : IDecoration, INotifyOwnerChanged
|
public class WithTextControlGroupDecoration : IDecoration
|
||||||
{
|
{
|
||||||
readonly WithTextControlGroupDecorationInfo info;
|
readonly WithTextControlGroupDecorationInfo info;
|
||||||
readonly SpriteFont font;
|
readonly SpriteFont font;
|
||||||
readonly CachedTransform<int, string> label;
|
readonly CachedTransform<int, string> label;
|
||||||
|
|
||||||
Color color;
|
|
||||||
|
|
||||||
public WithTextControlGroupDecoration(Actor self, WithTextControlGroupDecorationInfo info)
|
public WithTextControlGroupDecoration(Actor self, WithTextControlGroupDecorationInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
font = Game.Renderer.Fonts[info.Font];
|
font = Game.Renderer.Fonts[info.Font];
|
||||||
color = info.UsePlayerColor ? self.OwnerColor() : info.Color;
|
|
||||||
|
|
||||||
label = new CachedTransform<int, string>(g => self.World.ControlGroups.Groups[g]);
|
label = new CachedTransform<int, string>(g => self.World.ControlGroups.Groups[g]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,14 +70,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var screenPos = container.GetDecorationOrigin(self, wr, info.Position, info.Margin);
|
var screenPos = container.GetDecorationOrigin(self, wr, info.Position, info.Margin);
|
||||||
return new IRenderable[]
|
return new IRenderable[]
|
||||||
{
|
{
|
||||||
new UITextRenderable(font, self.CenterPosition, screenPos, 0, color, text)
|
new UITextRenderable(font, self.CenterPosition, screenPos, 0, info.UsePlayerColor ? self.OwnerColor() : info.Color, text)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
|
||||||
{
|
|
||||||
if (info.UsePlayerColor)
|
|
||||||
color = self.OwnerColor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user