From d052fd79e308cdfba397591b8c086e3580341ee0 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 22 Dec 2009 11:57:32 +1300 Subject: [PATCH] the rest of yesterday's render changes. --- OpenRa.Game/GameRules/UnitInfo.cs | 1 - OpenRa.Game/Traits/RenderBuilding.cs | 6 ---- OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs | 37 +++++---------------- OpenRa.Game/Traits/RenderUnitRotor.cs | 36 +++++++++----------- OpenRa.Game/Traits/RenderUnitSpinner.cs | 21 ++++-------- OpenRa.Game/Traits/Util.cs | 3 +- units.ini | 1 - 7 files changed, 32 insertions(+), 73 deletions(-) diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 0bb6b3a78d..a13e9c46d7 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -44,7 +44,6 @@ namespace OpenRa.Game.GameRules public readonly int[] PrimaryOffset = { 0, 0 }; public readonly int[] SecondaryOffset = null; public readonly int Recoil = 0; - public readonly string SecondaryAnim = null; public readonly bool MuzzleFlash = false; public readonly int SelectionPriority = 10; public readonly int InitialFacing = 128; diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index b2b7a4c3d2..c36173c031 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -51,12 +51,6 @@ namespace OpenRa.Game.Traits } } - public override IEnumerable> Render(Actor self) - { - var pal = self.Owner == null ? 0 : self.Owner.Palette; - yield return Tuple.New(anim.Image, 24f * (float2)self.Location, pal); - } - public virtual void Damaged(Actor self, AttackInfo e) { if (!e.DamageStateChanged) diff --git a/OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs b/OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs index 5d5937d2bd..18bfbc8385 100644 --- a/OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs +++ b/OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs @@ -7,40 +7,21 @@ namespace OpenRa.Game.Traits { class RenderUnitMuzzleFlash : RenderUnit { - Animation muzzleFlash; - public RenderUnitMuzzleFlash(Actor self) : base(self) { if (!self.Info.MuzzleFlash) throw new InvalidOperationException("wtf??"); - muzzleFlash = new Animation(self.Info.Name); - muzzleFlash.PlayFetchIndex("muzzle", - () => - { - var attack = self.traits.WithInterface().First(); - var unit = self.traits.Get(); - return (Util.QuantizeFacing( - unit.Facing, 8)) * 6 + (int)(attack.primaryRecoil * 5.9f); - }); - } - - public override void Tick(Actor self) - { - base.Tick(self); - muzzleFlash.Tick(); - } - - public override IEnumerable> Render(Actor self) - { + var unit = self.traits.Get(); var attack = self.traits.WithInterface().First(); - if (attack.primaryRecoil > 0) - return base.Render(self).Concat(new[] {Util.Centered(self, - muzzleFlash.Image, self.CenterLocation + new float2( - self.Info.PrimaryOffset.ElementAtOrDefault(2), - self.Info.PrimaryOffset.ElementAtOrDefault(3)))}); - else - return base.Render(self); + + var muzzleFlash = new Animation(self.Info.Name); + muzzleFlash.PlayFetchIndex("muzzle", + () => (Util.QuantizeFacing(unit.Facing, 8)) * 6 + (int)(attack.primaryRecoil * 5.9f)); + anims.Add( "muzzle", new AnimationWithOffset( + muzzleFlash, + () => new float2( self.Info.PrimaryOffset.ElementAtOrDefault( 2 ), self.Info.PrimaryOffset.ElementAtOrDefault( 3 ) ), + () => attack.primaryRecoil <= 0 ) ); } } } diff --git a/OpenRa.Game/Traits/RenderUnitRotor.cs b/OpenRa.Game/Traits/RenderUnitRotor.cs index dec9beef10..ca8438e9c5 100755 --- a/OpenRa.Game/Traits/RenderUnitRotor.cs +++ b/OpenRa.Game/Traits/RenderUnitRotor.cs @@ -9,35 +9,29 @@ namespace OpenRa.Game.Traits public RenderUnitRotor( Actor self ) : base(self) - { - rotorAnim = new Animation(self.Info.Name); - rotorAnim.PlayRepeating("rotor"); - - if (self.Info.SecondaryAnim != null) - { - secondRotorAnim = new Animation(self.Info.Name); - secondRotorAnim.PlayRepeating(self.Info.SecondaryAnim); - } - } - - public override IEnumerable> Render(Actor self) { var unit = self.traits.Get(); - yield return Util.Centered(self, anim.Image, self.CenterLocation); - yield return Util.Centered(self, rotorAnim.Image, self.CenterLocation - + Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ) ); - if (self.Info.SecondaryOffset != null) - yield return Util.Centered(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation - + Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, 0 ) ); + rotorAnim = new Animation(self.Info.Name); + rotorAnim.PlayRepeating("rotor"); + anims.Add( "rotor_1", new AnimationWithOffset( + rotorAnim, + () => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ), + null ) ); + + if( self.Info.SecondaryOffset == null ) return; + + secondRotorAnim = new Animation( self.Info.Name ); + secondRotorAnim.PlayRepeating( "rotor2" ); + anims.Add( "rotor_2", new AnimationWithOffset( + secondRotorAnim, + () => Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, 0 ), + null ) ); } public override void Tick(Actor self) { base.Tick(self); - rotorAnim.Tick(); - if (secondRotorAnim != null) - secondRotorAnim.Tick(); var unit = self.traits.Get(); diff --git a/OpenRa.Game/Traits/RenderUnitSpinner.cs b/OpenRa.Game/Traits/RenderUnitSpinner.cs index 2522404929..aefb72329f 100755 --- a/OpenRa.Game/Traits/RenderUnitSpinner.cs +++ b/OpenRa.Game/Traits/RenderUnitSpinner.cs @@ -9,24 +9,15 @@ namespace OpenRa.Game.Traits public RenderUnitSpinner( Actor self ) : base(self) - { - spinnerAnim = new Animation( self.Info.Name ); - spinnerAnim.PlayRepeating( "spinner" ); - } - - public override IEnumerable> Render(Actor self) { var unit = self.traits.Get(); - yield return Util.Centered(self, anim.Image, self.CenterLocation); - yield return Util.Centered( self, spinnerAnim.Image, self.CenterLocation - + Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, 0)); - } - - public override void Tick(Actor self) - { - base.Tick(self); - spinnerAnim.Tick(); + spinnerAnim = new Animation( self.Info.Name ); + spinnerAnim.PlayRepeating( "spinner" ); + anims.Add( "spinner", new AnimationWithOffset( + spinnerAnim, + () => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ), + null ) ); } } } diff --git a/OpenRa.Game/Traits/Util.cs b/OpenRa.Game/Traits/Util.cs index 8ec7032803..2932b94b43 100755 --- a/OpenRa.Game/Traits/Util.cs +++ b/OpenRa.Game/Traits/Util.cs @@ -116,8 +116,9 @@ namespace OpenRa.Game.Traits public static Tuple Centered(Actor self, Sprite s, float2 location) { + var pal = self.Owner == null ? 0 : self.Owner.Palette; var loc = location - 0.5f * s.size; - return Tuple.New(s, loc.Round(), self.Owner.Palette); + return Tuple.New(s, loc.Round(), pal); } public static Tuple CenteredShadow(Actor self, Sprite s, float2 location) diff --git a/units.ini b/units.ini index e46717c32d..ea2daf0ee1 100755 --- a/units.ini +++ b/units.ini @@ -170,7 +170,6 @@ PrimaryOffset=0,14,0,-4 SecondaryOffset=0,-14,0,-2 BuiltAt=hpad Traits=Unit, Helicopter, RenderUnitRotor, WithShadow -SecondaryAnim=rotor2 InitialFacing=20 LongDesc=Fast Infantry Transport Helicopter.\n Unarmed [HELI]