From 7ecf84dc61890561ea1e46421fda4fe1b979ccd0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 21 Oct 2013 18:12:34 +1300 Subject: [PATCH] Extract contrail fading for dead projectiles into an IEffect. --- OpenRA.Mods.RA/Effects/Bullet.cs | 15 +++------- OpenRA.Mods.RA/Effects/ContrailFader.cs | 38 +++++++++++++++++++++++++ OpenRA.Mods.RA/Effects/Missile.cs | 18 +++--------- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + 4 files changed, 47 insertions(+), 25 deletions(-) create mode 100755 OpenRA.Mods.RA/Effects/ContrailFader.cs diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index 16913756da..63947498c6 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 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, @@ -110,13 +110,6 @@ namespace OpenRA.Mods.RA.Effects public void Tick(World world) { - // Fade the trail out gradually - if (ticks > length && info.ContrailLength > 0) - { - trail.Update(pos); - return; - } - if (anim != null) anim.Tick(); @@ -166,9 +159,9 @@ namespace OpenRA.Mods.RA.Effects void Explode(World world) { if (info.ContrailLength > 0) - world.AddFrameEndTask(w => w.Add(new DelayedAction(info.ContrailLength, () => w.Remove(this)))); - else - world.AddFrameEndTask(w => w.Remove(this)); + world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, trail))); + + world.AddFrameEndTask(w => w.Remove(this)); Combat.DoImpacts(pos, args.SourceActor, args.Weapon, args.FirepowerModifier); } diff --git a/OpenRA.Mods.RA/Effects/ContrailFader.cs b/OpenRA.Mods.RA/Effects/ContrailFader.cs new file mode 100755 index 0000000000..9957a02bd1 --- /dev/null +++ b/OpenRA.Mods.RA/Effects/ContrailFader.cs @@ -0,0 +1,38 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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.Collections.Generic; +using OpenRA.Effects; +using OpenRA.Graphics; + +namespace OpenRA.Mods.RA.Effects +{ + class ContrailFader : IEffect + { + WPos pos; + ContrailRenderable trail; + + public ContrailFader(WPos pos, ContrailRenderable trail) + { + this.pos = pos; + this.trail = trail; + } + + public void Tick(World world) + { + trail.Update(pos); + } + + public IEnumerable Render(WorldRenderer wr) + { + yield return trail; + } + } +} diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 536e95fd86..c48b509698 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 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, @@ -63,7 +63,6 @@ namespace OpenRA.Mods.RA.Effects [Sync] WPos targetPosition; [Sync] WVec offset; [Sync] int ticks; - [Sync] bool exploded; [Sync] public Actor SourceActor { get { return args.SourceActor; } } [Sync] public Target GuidedTarget { get { return args.GuidedTarget; } } @@ -112,13 +111,6 @@ namespace OpenRA.Mods.RA.Effects public void Tick(World world) { - // Fade the trail out gradually - if (exploded && info.ContrailLength > 0) - { - trail.Update(pos); - return; - } - ticks++; anim.Tick(); @@ -174,12 +166,10 @@ namespace OpenRA.Mods.RA.Effects void Explode(World world) { - exploded = true; - if (info.ContrailLength > 0) - world.AddFrameEndTask(w => w.Add(new DelayedAction(info.ContrailLength, () => w.Remove(this)))); - else - world.AddFrameEndTask(w => w.Remove(this)); + world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, trail))); + + world.AddFrameEndTask(w => w.Remove(this)); // Don't blow up in our launcher's face! if (ticks <= info.Arm) diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index beb37e3946..5e6203c3b0 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -471,6 +471,7 @@ +