Simplifying(?) some of the render stuff.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace OpenRa.Game.Graphics
|
|||||||
public Animation( string name )
|
public Animation( string name )
|
||||||
{
|
{
|
||||||
this.name = name.ToLowerInvariant();
|
this.name = name.ToLowerInvariant();
|
||||||
|
tickFunc = () => { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sprite Image
|
public Sprite Image
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
var oldTotal = moveFractionTotal;
|
var oldTotal = moveFractionTotal;
|
||||||
|
|
||||||
moveFraction += (int)Util.GetEffectiveSpeed(self);
|
moveFraction += (int)Util.GetEffectiveSpeed(self);
|
||||||
|
if( moveFraction >= moveFractionTotal )
|
||||||
|
moveFraction = moveFractionTotal;
|
||||||
UpdateCenterLocation( self, mobile );
|
UpdateCenterLocation( self, mobile );
|
||||||
if( moveFraction >= moveFractionTotal )
|
if( moveFraction >= moveFractionTotal )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,27 +13,19 @@ namespace OpenRa.Game.Traits
|
|||||||
public RenderBuilding(Actor self)
|
public RenderBuilding(Actor self)
|
||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
Make(() =>
|
if( Game.skipMakeAnims )
|
||||||
{
|
Complete( self );
|
||||||
anim.PlayRepeating("idle");
|
else
|
||||||
}, self);
|
anim.PlayThen( "make", () => Complete( self ) );
|
||||||
|
|
||||||
DoBib(self, false);
|
DoBib(self, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Make( Action after, Actor self )
|
void Complete( Actor self )
|
||||||
{
|
{
|
||||||
Action newAfter = () =>
|
anim.PlayRepeating( "idle" );
|
||||||
{
|
foreach( var x in self.traits.WithInterface<INotifyBuildComplete>() )
|
||||||
after();
|
x.BuildingComplete( self );
|
||||||
foreach (var x in self.traits.WithInterface<INotifyBuildComplete>())
|
|
||||||
x.BuildingComplete(self);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Game.skipMakeAnims)
|
|
||||||
newAfter();
|
|
||||||
else
|
|
||||||
anim.PlayThen("make", newAfter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoBib(Actor self, bool isRemove)
|
void DoBib(Actor self, bool isRemove)
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class RenderBuildingOre : RenderBuilding
|
class RenderBuildingOre : RenderBuilding, INotifyBuildComplete
|
||||||
{
|
{
|
||||||
public RenderBuildingOre(Actor self)
|
public RenderBuildingOre(Actor self)
|
||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
Make( () => anim.PlayFetchIndex("idle",
|
}
|
||||||
() => (int)(4.9 * self.Owner.GetSiloFullness())), self); /* hack */
|
|
||||||
|
public void BuildingComplete( Actor self )
|
||||||
|
{
|
||||||
|
anim.PlayFetchIndex( "idle", () => (int)( 4.9 * self.Owner.GetSiloFullness() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class RenderBuildingTurreted : RenderBuilding
|
class RenderBuildingTurreted : RenderBuilding, INotifyBuildComplete
|
||||||
{
|
{
|
||||||
public RenderBuildingTurreted(Actor self)
|
public RenderBuildingTurreted(Actor self)
|
||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
Make( () => PlayTurretAnim( self, "idle" ), self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayTurretAnim(Actor self, string a)
|
public void BuildingComplete( Actor self )
|
||||||
{
|
{
|
||||||
anim.PlayFacing(a, () => self.traits.Get<Turreted>().turretFacing);
|
PlayTurretAnim( self, "idle" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayTurretAnim( Actor self, string a )
|
||||||
|
{
|
||||||
|
anim.PlayFacing( a, () => self.traits.Get<Turreted>().turretFacing );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Damaged(Actor self, AttackInfo e)
|
public override void Damaged(Actor self, AttackInfo e)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using OpenRa.Game.Graphics;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class RenderWarFactory : RenderBuilding
|
class RenderWarFactory : RenderBuilding, INotifyBuildComplete
|
||||||
{
|
{
|
||||||
public Animation roof;
|
public Animation roof;
|
||||||
bool doneBuilding;
|
bool doneBuilding;
|
||||||
@@ -15,14 +15,14 @@ namespace OpenRa.Game.Traits
|
|||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
|
||||||
roof = new Animation(self.Info.Image ?? self.Info.Name);
|
roof = new Animation(self.Info.Image ?? self.Info.Name);
|
||||||
Make( () =>
|
}
|
||||||
{
|
|
||||||
doneBuilding = true;
|
public void BuildingComplete( Actor self )
|
||||||
anim.Play("idle");
|
{
|
||||||
roof.Play(prefix + "idle-top");
|
doneBuilding = true;
|
||||||
}, self);
|
anim.Play( "idle" );
|
||||||
|
roof.Play( prefix + "idle-top" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Tuple<Sprite, float2, int>> RenderRoof(Actor self)
|
public IEnumerable<Tuple<Sprite, float2, int>> RenderRoof(Actor self)
|
||||||
|
|||||||
@@ -1,22 +1,63 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using IjwFramework.Collections;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
abstract class RenderSimple : IRender, ITick
|
abstract class RenderSimple : IRender, ITick
|
||||||
{
|
{
|
||||||
public Animation anim;
|
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||||
|
public Animation anim { get { return anims[ "" ].Animation; } }
|
||||||
|
|
||||||
public RenderSimple(Actor self)
|
public RenderSimple(Actor self)
|
||||||
{
|
{
|
||||||
anim = new Animation(self.Info.Image ?? self.Info.Name);
|
anims.Add( "", new Animation( self.Info.Image ?? self.Info.Name ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self);
|
public virtual IEnumerable<Tuple<Sprite, float2, int>> Render( Actor self )
|
||||||
|
{
|
||||||
|
foreach( var a in anims.Values )
|
||||||
|
if( a.DisableFunc == null || !a.DisableFunc() )
|
||||||
|
yield return a.Image( self );
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Tick(Actor self)
|
public virtual void Tick(Actor self)
|
||||||
{
|
{
|
||||||
anim.Tick();
|
foreach( var a in anims.Values )
|
||||||
|
a.Animation.Tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AnimationWithOffset
|
||||||
|
{
|
||||||
|
public Animation Animation;
|
||||||
|
public Func<float2> OffsetFunc;
|
||||||
|
public Func<bool> DisableFunc;
|
||||||
|
|
||||||
|
public AnimationWithOffset( Animation a )
|
||||||
|
: this( a, null, null )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnimationWithOffset( Animation a, Func<float2> o, Func<bool> d )
|
||||||
|
{
|
||||||
|
this.Animation = a;
|
||||||
|
this.OffsetFunc = o;
|
||||||
|
this.DisableFunc = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tuple<Sprite, float2, int> Image( Actor self )
|
||||||
|
{
|
||||||
|
if( OffsetFunc != null )
|
||||||
|
return Util.Centered( self, Animation.Image, self.CenterLocation + OffsetFunc() );
|
||||||
|
else
|
||||||
|
return Util.Centered( self, Animation.Image, self.CenterLocation );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator AnimationWithOffset( Animation a )
|
||||||
|
{
|
||||||
|
return new AnimationWithOffset( a );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ namespace OpenRa.Game.Traits
|
|||||||
: base(self)
|
: base(self)
|
||||||
{
|
{
|
||||||
PlayFacingAnim(self);
|
PlayFacingAnim(self);
|
||||||
smoke = new Animation("smoke_m");
|
|
||||||
|
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayFacingAnim(Actor self)
|
void PlayFacingAnim(Actor self)
|
||||||
@@ -25,15 +26,7 @@ namespace OpenRa.Game.Traits
|
|||||||
anim.PlayThen(newAnim, () => { PlayFacingAnim(self); if (after != null) after(); });
|
anim.PlayThen(newAnim, () => { PlayFacingAnim(self); if (after != null) after(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
|
||||||
{
|
|
||||||
yield return Util.Centered(self, anim.Image, self.CenterLocation);
|
|
||||||
if (isSmoking)
|
|
||||||
yield return Util.Centered(self, smoke.Image, self.CenterLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSmoking;
|
bool isSmoking;
|
||||||
Animation smoke;
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
@@ -41,17 +34,11 @@ namespace OpenRa.Game.Traits
|
|||||||
if (isSmoking) return;
|
if (isSmoking) return;
|
||||||
|
|
||||||
isSmoking = true;
|
isSmoking = true;
|
||||||
smoke.PlayThen("idle",
|
var smoke = anims[ "smoke" ].Animation;
|
||||||
() => smoke.PlayThen("loop",
|
smoke.PlayThen( "idle",
|
||||||
() => smoke.PlayBackwardsThen("end",
|
() => smoke.PlayThen( "loop",
|
||||||
() => isSmoking = false)));
|
() => smoke.PlayBackwardsThen( "end",
|
||||||
}
|
() => isSmoking = false ) ) );
|
||||||
|
|
||||||
public override void Tick(Actor self)
|
|
||||||
{
|
|
||||||
base.Tick(self);
|
|
||||||
if (isSmoking)
|
|
||||||
smoke.Tick();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,51 +6,41 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
class RenderUnitTurreted : RenderUnit
|
class RenderUnitTurreted : RenderUnit
|
||||||
{
|
{
|
||||||
public Animation turretAnim;
|
|
||||||
public Animation muzzleFlash;
|
public Animation muzzleFlash;
|
||||||
|
|
||||||
public RenderUnitTurreted(Actor self)
|
public RenderUnitTurreted(Actor self)
|
||||||
: base(self)
|
: base(self)
|
||||||
{
|
|
||||||
self.traits.Get<Turreted>();
|
|
||||||
turretAnim = new Animation(self.Info.Name);
|
|
||||||
|
|
||||||
if (self.Info.MuzzleFlash)
|
|
||||||
{
|
|
||||||
var attack = self.traits.WithInterface<AttackBase>().First();
|
|
||||||
muzzleFlash = new Animation(self.Info.Name);
|
|
||||||
muzzleFlash.PlayFetchIndex("muzzle",
|
|
||||||
() => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6
|
|
||||||
+ (int)(attack.primaryRecoil * 5.9f));
|
|
||||||
/* hack: recoil can be 1.0f, but don't overflow into next anim */
|
|
||||||
}
|
|
||||||
|
|
||||||
turretAnim.PlayFacing("turret", () => self.traits.Get<Turreted>().turretFacing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
|
||||||
{
|
{
|
||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
|
var turreted = self.traits.Get<Turreted>();
|
||||||
var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault();
|
var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault();
|
||||||
|
|
||||||
yield return Util.Centered(self, anim.Image, self.CenterLocation);
|
var turretAnim = new Animation(self.Info.Name);
|
||||||
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
|
turretAnim.PlayFacing( "turret", () => turreted.turretFacing );
|
||||||
+ Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil));
|
|
||||||
if (self.Info.SecondaryOffset != null)
|
|
||||||
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
|
|
||||||
+ Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil));
|
|
||||||
|
|
||||||
if (muzzleFlash != null && attack.primaryRecoil > 0)
|
if( self.Info.PrimaryOffset != null )
|
||||||
yield return Util.Centered(self, muzzleFlash.Image, self.CenterLocation
|
anims.Add( "turret_1", new AnimationWithOffset(
|
||||||
+ Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil));
|
turretAnim,
|
||||||
}
|
() => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, attack.primaryRecoil ),
|
||||||
|
null ) );
|
||||||
|
|
||||||
public override void Tick(Actor self)
|
if( self.Info.SecondaryOffset != null )
|
||||||
{
|
anims.Add( "turret_2", new AnimationWithOffset(
|
||||||
base.Tick(self);
|
turretAnim,
|
||||||
turretAnim.Tick();
|
() => Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil ),
|
||||||
if (muzzleFlash != null)
|
null ) );
|
||||||
muzzleFlash.Tick();
|
|
||||||
|
if( self.Info.MuzzleFlash )
|
||||||
|
{
|
||||||
|
muzzleFlash = new Animation( self.Info.Name );
|
||||||
|
muzzleFlash.PlayFetchIndex( "muzzle",
|
||||||
|
() => ( Util.QuantizeFacing( self.traits.Get<Turreted>().turretFacing, 8 ) ) * 6
|
||||||
|
+ (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */
|
||||||
|
anims.Add( "muzzle_flash", new AnimationWithOffset(
|
||||||
|
muzzleFlash,
|
||||||
|
() => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, attack.primaryRecoil ),
|
||||||
|
() => attack.primaryRecoil <= 0 ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace OpenRa.Game.Traits
|
|||||||
if (rut == null) return float2.Zero;
|
if (rut == null) return float2.Zero;
|
||||||
|
|
||||||
var facing = self.traits.Get<Turreted>().turretFacing;
|
var facing = self.traits.Get<Turreted>().turretFacing;
|
||||||
var quantizedFacing = QuantizeFacing(facing, rut.turretAnim.CurrentSequence.Length) * (256 / rut.turretAnim.CurrentSequence.Length);
|
var quantizedFacing = QuantizeFacing(facing, rut.anim.CurrentSequence.Length) * (256 / rut.anim.CurrentSequence.Length);
|
||||||
|
|
||||||
return RotateVectorByFacing(new float2(0, recoil * self.Info.Recoil), quantizedFacing, .7f);
|
return RotateVectorByFacing(new float2(0, recoil * self.Info.Recoil), quantizedFacing, .7f);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user