Fix and rewrite contrails. Closes #3457.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
Animation anim;
|
||||
|
||||
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
|
||||
ContrailHistory Trail;
|
||||
ContrailRenderable Trail;
|
||||
|
||||
public Bullet(BulletInfo info, ProjectileArgs args)
|
||||
{
|
||||
@@ -73,9 +73,8 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
if (Info.ContrailLength > 0)
|
||||
{
|
||||
Trail = new ContrailHistory(Info.ContrailLength,
|
||||
Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
|
||||
Info.ContrailDelay);
|
||||
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.firedBy) : Info.ContrailColor;
|
||||
Trail = new ContrailRenderable(args.firedBy.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +126,10 @@ namespace OpenRA.Mods.RA.Effects
|
||||
ticksToNextSmoke = Info.TrailInterval;
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
if (Info.ContrailLength > 0)
|
||||
{
|
||||
var alt = (Info.High || Info.Angle > 0) ? GetAltitude() : 0;
|
||||
Trail.Tick(new PPos((int)pos.X, (int)pos.Y).ToWPos((int)alt));
|
||||
Trail.Update(new PPos((int)pos.X, (int)pos.Y).ToWPos((int)alt));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +152,9 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
if (Info.ContrailLength > 0)
|
||||
yield return Trail;
|
||||
|
||||
if (anim != null)
|
||||
{
|
||||
var at = (float)t / TotalTime();
|
||||
@@ -177,9 +179,6 @@ namespace OpenRA.Mods.RA.Effects
|
||||
wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), (int)pos.Y);
|
||||
}
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(wr, Args.firedBy);
|
||||
}
|
||||
|
||||
void Explode( World world )
|
||||
|
||||
@@ -28,17 +28,18 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new Contrail(init.self, this); }
|
||||
}
|
||||
|
||||
class Contrail : ITick, IPostRender
|
||||
class Contrail : ITick, IRender
|
||||
{
|
||||
ContrailInfo info;
|
||||
ContrailHistory history;
|
||||
ContrailRenderable trail;
|
||||
IBodyOrientation body;
|
||||
|
||||
public Contrail(Actor self, ContrailInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
history = new ContrailHistory(info.TrailLength,
|
||||
info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color);
|
||||
|
||||
var color = info.UsePlayerColor ? ContrailRenderable.ChooseColor(self) : info.Color;
|
||||
trail = new ContrailRenderable(self.World, color, info.TrailLength, 0, 0);
|
||||
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
}
|
||||
@@ -46,62 +47,12 @@ namespace OpenRA.Mods.RA
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var local = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
|
||||
history.Tick(self.CenterPosition + body.LocalToWorld(local));
|
||||
trail.Update(self.CenterPosition + body.LocalToWorld(local));
|
||||
}
|
||||
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); }
|
||||
}
|
||||
|
||||
class ContrailHistory
|
||||
{
|
||||
List<WPos> positions = new List<WPos>();
|
||||
readonly int TrailLength;
|
||||
readonly Color Color;
|
||||
readonly int StartSkip;
|
||||
|
||||
public static Color ChooseColor(Actor self)
|
||||
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
var ownerColor = Color.FromArgb(255, self.Owner.Color.RGB);
|
||||
return Exts.ColorLerp(0.5f, ownerColor, Color.White);
|
||||
}
|
||||
|
||||
public ContrailHistory(int trailLength, Color color)
|
||||
: this(trailLength, color, 0) { }
|
||||
|
||||
public ContrailHistory(int trailLength, Color color, int startSkip)
|
||||
{
|
||||
this.TrailLength = trailLength;
|
||||
this.Color = color;
|
||||
this.StartSkip = startSkip;
|
||||
}
|
||||
|
||||
public void Tick(WPos currentPos)
|
||||
{
|
||||
positions.Add(currentPos);
|
||||
if (positions.Count >= TrailLength)
|
||||
positions.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void Render(WorldRenderer wr, Actor self)
|
||||
{
|
||||
Color trailStart = Color;
|
||||
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B);
|
||||
|
||||
for (int i = positions.Count - 1 - StartSkip; i >= 4; --i)
|
||||
{
|
||||
// World positions
|
||||
var conPos = WPos.Average(positions[i], positions[i-1], positions[i-2], positions[i-3]);
|
||||
var nextPos = WPos.Average(positions[i-1], positions[i-2], positions[i-3], positions[i-4]);
|
||||
|
||||
if (!self.World.FogObscures(new CPos(conPos)) &&
|
||||
!self.World.FogObscures(new CPos(nextPos)))
|
||||
{
|
||||
Game.Renderer.WorldLineRenderer.DrawLine(wr.ScreenPosition(conPos), wr.ScreenPosition(nextPos), trailStart, trailEnd);
|
||||
|
||||
trailStart = trailEnd;
|
||||
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, trailStart.G, trailStart.B);
|
||||
}
|
||||
}
|
||||
yield return trail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
int Facing;
|
||||
int t;
|
||||
int Altitude;
|
||||
ContrailHistory Trail;
|
||||
ContrailRenderable Trail;
|
||||
|
||||
public Missile(MissileInfo info, ProjectileArgs args)
|
||||
{
|
||||
@@ -81,9 +81,8 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
if (Info.ContrailLength > 0)
|
||||
{
|
||||
Trail = new ContrailHistory(Info.ContrailLength,
|
||||
Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
|
||||
Info.ContrailDelay);
|
||||
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.firedBy) : Info.ContrailColor;
|
||||
Trail = new ContrailRenderable(args.firedBy.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +161,8 @@ namespace OpenRA.Mods.RA.Effects
|
||||
Explode(world);
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Tick(PxPosition.ToWPos(Altitude));
|
||||
if (Info.ContrailLength > 0)
|
||||
Trail.Update(PxPosition.ToWPos(Altitude));
|
||||
}
|
||||
|
||||
void Explode(World world)
|
||||
@@ -176,12 +175,12 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
if (Info.ContrailLength > 0)
|
||||
yield return Trail;
|
||||
|
||||
if (!Args.firedBy.World.FogObscures(PxPosition.ToCPos()))
|
||||
yield return new SpriteRenderable(anim.Image, PxPosition.ToFloat2() - new float2(0, Altitude),
|
||||
wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y);
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(wr, Args.firedBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user