Animation facing -> WAngle.

This commit is contained in:
Paul Chote
2020-05-08 18:57:28 +01:00
committed by atlimit8
parent 361e2d463c
commit fe58ed1283
26 changed files with 74 additions and 63 deletions

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Graphics
public bool IsDecoration { get; set; } public bool IsDecoration { get; set; }
readonly SequenceProvider sequenceProvider; readonly SequenceProvider sequenceProvider;
readonly Func<int> facingFunc; readonly Func<WAngle> facingFunc;
readonly Func<bool> paused; readonly Func<bool> paused;
int frame; int frame;
@@ -33,15 +33,15 @@ namespace OpenRA.Graphics
Action tickFunc = () => { }; Action tickFunc = () => { };
public Animation(World world, string name) public Animation(World world, string name)
: this(world, name, () => 0) { } : this(world, name, () => WAngle.Zero) { }
public Animation(World world, string name, Func<int> facingFunc) public Animation(World world, string name, Func<WAngle> facingFunc)
: this(world, name, facingFunc, null) { } : this(world, name, facingFunc, null) { }
public Animation(World world, string name, Func<bool> paused) public Animation(World world, string name, Func<bool> paused)
: this(world, name, () => 0, paused) { } : this(world, name, () => WAngle.Zero, paused) { }
public Animation(World world, string name, Func<int> facingFunc, Func<bool> paused) public Animation(World world, string name, Func<WAngle> facingFunc, Func<bool> paused)
{ {
sequenceProvider = world.Map.Rules.Sequences; sequenceProvider = world.Map.Rules.Sequences;
Name = name.ToLowerInvariant(); Name = name.ToLowerInvariant();
@@ -50,7 +50,7 @@ namespace OpenRA.Graphics
} }
public int CurrentFrame { get { return backwards ? CurrentSequence.Length - frame - 1 : frame; } } public int CurrentFrame { get { return backwards ? CurrentSequence.Length - frame - 1 : frame; } }
public Sprite Image { get { return CurrentSequence.GetSprite(CurrentFrame, WAngle.FromFacing(facingFunc())); } } public Sprite Image { get { return CurrentSequence.GetSprite(CurrentFrame, facingFunc()); } }
public IRenderable[] Render(WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale) public IRenderable[] Render(WPos pos, WVec offset, int zOffset, PaletteReference palette, float scale)
{ {
@@ -58,7 +58,7 @@ namespace OpenRA.Graphics
if (CurrentSequence.ShadowStart >= 0) if (CurrentSequence.ShadowStart >= 0)
{ {
var shadow = CurrentSequence.GetShadow(CurrentFrame, WAngle.FromFacing(facingFunc())); var shadow = CurrentSequence.GetShadow(CurrentFrame, facingFunc());
var shadowRenderable = new SpriteRenderable(shadow, pos, offset, CurrentSequence.ShadowZOffset + zOffset, palette, scale, true); var shadowRenderable = new SpriteRenderable(shadow, pos, offset, CurrentSequence.ShadowZOffset + zOffset, palette, scale, true);
return new IRenderable[] { shadowRenderable, imageRenderable }; return new IRenderable[] { shadowRenderable, imageRenderable };
} }
@@ -74,7 +74,7 @@ namespace OpenRA.Graphics
if (CurrentSequence.ShadowStart >= 0) if (CurrentSequence.ShadowStart >= 0)
{ {
var shadow = CurrentSequence.GetShadow(CurrentFrame, WAngle.FromFacing(facingFunc())); var shadow = CurrentSequence.GetShadow(CurrentFrame, facingFunc());
var shadowPos = pos - new int2((int)(scale * shadow.Size.X / 2), (int)(scale * shadow.Size.Y / 2)); var shadowPos = pos - new int2((int)(scale * shadow.Size.X / 2), (int)(scale * shadow.Size.Y / 2));
var shadowRenderable = new UISpriteRenderable(shadow, WPos.Zero + offset, shadowPos, CurrentSequence.ShadowZOffset + zOffset, palette, scale); var shadowRenderable = new UISpriteRenderable(shadow, WPos.Zero + offset, shadowPos, CurrentSequence.ShadowZOffset + zOffset, palette, scale);
return new IRenderable[] { shadowRenderable, imageRenderable }; return new IRenderable[] { shadowRenderable, imageRenderable };

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault(); var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault();
// Show the correct turret facing // Show the correct turret facing
var facing = init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit>().Value(init.World) : t.InitialFacing; var facing = WAngle.FromFacing(init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit>().Value(init.World) : t.InitialFacing);
var anim = new Animation(init.World, image, () => facing); var anim = new Animation(init.World, image, () => facing);
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence)); anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));
@@ -47,11 +47,11 @@ namespace OpenRA.Mods.Cnc.Traits.Render
{ {
readonly Turreted turreted; readonly Turreted turreted;
static Func<int> MakeTurretFacingFunc(Actor self) static Func<WAngle> MakeTurretFacingFunc(Actor self)
{ {
// Turret artwork is baked into the sprite, so only the first turret makes sense. // Turret artwork is baked into the sprite, so only the first turret makes sense.
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault(); var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
return () => turreted.TurretFacing; return () => WAngle.FromFacing(turreted.TurretFacing);
} }
public WithEmbeddedTurretSpriteBody(ActorInitializer init, WithSpriteBodyInfo info) public WithEmbeddedTurretSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)

View File

@@ -46,11 +46,11 @@ namespace OpenRA.Mods.Cnc.Traits.Render
readonly IFacing facing; readonly IFacing facing;
readonly Turreted turret; readonly Turreted turret;
static Func<int> MakeTurretFacingFunc(Actor self) static Func<WAngle> MakeTurretFacingFunc(Actor self)
{ {
// Turret artwork is baked into the sprite, so only the first turret makes sense. // Turret artwork is baked into the sprite, so only the first turret makes sense.
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault(); var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
return () => turreted.TurretFacing; return () => WAngle.FromFacing(turreted.TurretFacing);
} }
public WithGunboatBody(ActorInitializer init, WithGunboatBodyInfo info) public WithGunboatBody(ActorInitializer init, WithGunboatBodyInfo info)

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public WithRoof(Actor self, WithRoofInfo info) public WithRoof(Actor self, WithRoofInfo info)
{ {
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait<IFacing>().Facing); var roof = new Animation(self.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
roof.Play(info.Sequence); roof.Play(info.Sequence);
rs.Add(new AnimationWithOffset(roof, null, null, 1024)); rs.Add(new AnimationWithOffset(roof, null, null, 1024));
} }

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Effects
this.visibleThroughFog = visibleThroughFog; this.visibleThroughFog = visibleThroughFog;
this.delay = delay; this.delay = delay;
pos = posFunc(); pos = posFunc();
anim = new Animation(world, image, facingFunc); anim = new Animation(world, image, () => WAngle.FromFacing(facingFunc()));
} }
public void Tick(World world) public void Tick(World world)

View File

@@ -67,20 +67,23 @@ namespace OpenRA.Mods.Common.Graphics
return () => orientation; return () => orientation;
} }
public Func<int> GetFacing() public Func<WAngle> GetFacing()
{ {
var facingInfo = Actor.TraitInfoOrDefault<IFacingInfo>(); var facingInfo = Actor.TraitInfoOrDefault<IFacingInfo>();
if (facingInfo == null) if (facingInfo == null)
return () => 0; return () => WAngle.Zero;
// Dynamic facing takes priority // Dynamic facing takes priority
var dynamicInit = dict.GetOrDefault<DynamicFacingInit>(); var dynamicInit = dict.GetOrDefault<DynamicFacingInit>();
if (dynamicInit != null) if (dynamicInit != null)
return dynamicInit.Value(null); {
var getFacing = dynamicInit.Value(null);
return () => WAngle.FromFacing(getFacing());
}
// Fall back to initial actor facing if an Init isn't available // Fall back to initial actor facing if an Init isn't available
var facingInit = dict.GetOrDefault<FacingInit>(); var facingInit = dict.GetOrDefault<FacingInit>();
var facing = facingInit != null ? facingInit.Value(null) : facingInfo.GetInitialFacing(); var facing = WAngle.FromFacing(facingInit != null ? facingInit.Value(null) : facingInfo.GetInitialFacing());
return () => facing; return () => facing;
} }

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (!string.IsNullOrEmpty(info.Image)) if (!string.IsNullOrEmpty(info.Image))
{ {
anim = new Animation(world, info.Image, new Func<int>(GetEffectiveFacing)); anim = new Animation(world, info.Image, new Func<WAngle>(GetEffectiveFacing));
anim.PlayRepeating(info.Sequences.Random(world.SharedRandom)); anim.PlayRepeating(info.Sequences.Random(world.SharedRandom));
} }
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Projectiles
remainingBounces = info.BounceCount; remainingBounces = info.BounceCount;
} }
int GetEffectiveFacing() WAngle GetEffectiveFacing()
{ {
var at = (float)ticks / (length - 1); var at = (float)ticks / (length - 1);
var attitude = angle.Tan() * (1 - 2 * at) / (4 * 1024); var attitude = angle.Tan() * (1 - 2 * at) / (4 * 1024);
@@ -184,9 +184,11 @@ namespace OpenRA.Mods.Common.Projectiles
var u = (facing % 128) / 128f; var u = (facing % 128) / 128f;
var scale = 512 * u * (1 - u); var scale = 512 * u * (1 - u);
return (int)(facing < 128 var effective = (int)(facing < 128
? facing - scale * attitude ? facing - scale * attitude
: facing + scale * attitude); : facing + scale * attitude);
return WAngle.FromFacing(effective);
} }
public void Tick(World world) public void Tick(World world)
@@ -211,7 +213,7 @@ namespace OpenRA.Mods.Common.Projectiles
{ {
var delayedPos = WPos.LerpQuadratic(source, target, angle, ticks - info.TrailDelay, length); var delayedPos = WPos.LerpQuadratic(source, target, angle, ticks - info.TrailDelay, length);
world.AddFrameEndTask(w => w.Add(new SpriteEffect(delayedPos, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), world.AddFrameEndTask(w => w.Add(new SpriteEffect(delayedPos, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom),
trailPalette, facing: GetEffectiveFacing()))); trailPalette, facing: GetEffectiveFacing().Facing)));
smokeTicks = info.TrailInterval; smokeTicks = info.TrailInterval;
} }

View File

@@ -65,13 +65,14 @@ namespace OpenRA.Mods.Common.Projectiles
this.info = info; this.info = info;
this.args = args; this.args = args;
pos = args.Source; pos = args.Source;
var facing = WAngle.FromFacing(args.Facing);
var convertedVelocity = new WVec(info.Velocity.Y, -info.Velocity.X, info.Velocity.Z); var convertedVelocity = new WVec(info.Velocity.Y, -info.Velocity.X, info.Velocity.Z);
velocity = convertedVelocity.Rotate(WRot.FromFacing(args.Facing)); velocity = convertedVelocity.Rotate(WRot.FromYaw(facing));
acceleration = new WVec(info.Acceleration.Y, -info.Acceleration.X, info.Acceleration.Z); acceleration = new WVec(info.Acceleration.Y, -info.Acceleration.X, info.Acceleration.Z);
if (!string.IsNullOrEmpty(info.Image)) if (!string.IsNullOrEmpty(info.Image))
{ {
anim = new Animation(args.SourceActor.World, info.Image, () => args.Facing); anim = new Animation(args.SourceActor.World, info.Image, () => facing);
if (!string.IsNullOrEmpty(info.OpenSequence)) if (!string.IsNullOrEmpty(info.OpenSequence))
anim.PlayThen(info.OpenSequence, () => anim.PlayRepeating(info.Sequences.Random(args.SourceActor.World.SharedRandom))); anim.PlayThen(info.OpenSequence, () => anim.PlayRepeating(info.Sequences.Random(args.SourceActor.World.SharedRandom)));

View File

@@ -203,7 +203,7 @@ namespace OpenRA.Mods.Common.Projectiles
WDist distanceCovered; WDist distanceCovered;
WDist rangeLimit; WDist rangeLimit;
int renderFacing; WAngle renderFacing;
[Sync] [Sync]
int hFacing; int hFacing;
@@ -835,7 +835,7 @@ namespace OpenRA.Mods.Common.Projectiles
else else
move = HomingTick(world, tarDistVec, relTarHorDist); move = HomingTick(world, tarDistVec, relTarHorDist);
renderFacing = new WVec(move.X, move.Y - move.Z, 0).Yaw.Facing; renderFacing = new WVec(move.X, move.Y - move.Z, 0).Yaw;
// Move the missile // Move the missile
var lastPos = pos; var lastPos = pos;
@@ -858,7 +858,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated)) if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated))
{ {
world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom),
trailPalette, facing: renderFacing))); trailPalette, facing: renderFacing.Facing)));
ticksToNextSmoke = info.TrailInterval; ticksToNextSmoke = info.TrailInterval;
} }

View File

@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Common.Traits
if (port == null) if (port == null)
return; return;
var muzzleFacing = targetYaw.Angle / 4; var muzzleFacing = targetYaw.Facing;
paxFacing[a.Actor].Facing = muzzleFacing; paxFacing[a.Actor].Facing = muzzleFacing;
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port)); paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
@@ -172,7 +172,7 @@ namespace OpenRA.Mods.Common.Traits
if (a.Info.MuzzleSequence != null) if (a.Info.MuzzleSequence != null)
{ {
// Muzzle facing is fixed once the firing starts // Muzzle facing is fixed once the firing starts
var muzzleAnim = new Animation(self.World, paxRender[a.Actor].GetImage(a.Actor), () => muzzleFacing); var muzzleAnim = new Animation(self.World, paxRender[a.Actor].GetImage(a.Actor), () => targetYaw);
var sequence = a.Info.MuzzleSequence; var sequence = a.Info.MuzzleSequence;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
this.info = info; this.info = info;
var anim = new Animation(self.World, "fire", () => 0); var anim = new Animation(self.World, "fire");
anim.IsDecoration = true; anim.IsDecoration = true;
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);
self.Trait<RenderSprites>().Add(anim); self.Trait<RenderSprites>().Add(anim);

View File

@@ -157,11 +157,13 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly List<AnimationWrapper> anims = new List<AnimationWrapper>(); readonly List<AnimationWrapper> anims = new List<AnimationWrapper>();
string cachedImage; string cachedImage;
public static Func<int> MakeFacingFunc(Actor self) public static Func<WAngle> MakeFacingFunc(Actor self)
{ {
var facing = self.TraitOrDefault<IFacing>(); var facing = self.TraitOrDefault<IFacing>();
if (facing == null) return () => 0; if (facing == null)
return () => facing.Facing; return () => WAngle.Zero;
return () => WAngle.FromFacing(facing.Facing);
} }
public RenderSprites(ActorInitializer init, RenderSpritesInfo info) public RenderSprites(ActorInitializer init, RenderSpritesInfo info)

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly Actor self; readonly Actor self;
public WithBridgeSpriteBody(ActorInitializer init, WithBridgeSpriteBodyInfo info) public WithBridgeSpriteBody(ActorInitializer init, WithBridgeSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
self = init.Self; self = init.Self;
bridgeInfo = info; bridgeInfo = info;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly AttackCharges attackCharges; readonly AttackCharges attackCharges;
public WithChargeSpriteBody(ActorInitializer init, WithChargeSpriteBodyInfo info) public WithChargeSpriteBody(ActorInitializer init, WithChargeSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
attackCharges = init.Self.Trait<AttackCharges>(); attackCharges = init.Self.Trait<AttackCharges>();
ConfigureAnimation(init.Self); ConfigureAnimation(init.Self);

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{ {
var anim = new Animation(init.World, rs.Image, () => 0); var anim = new Animation(init.World, rs.Image);
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), IdleSequence)); anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), IdleSequence));
yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale); yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
} }

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly BridgeLayer bridgeLayer; readonly BridgeLayer bridgeLayer;
public WithDeadBridgeSpriteBody(ActorInitializer init, WithDeadBridgeSpriteBodyInfo info) public WithDeadBridgeSpriteBody(ActorInitializer init, WithDeadBridgeSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
bridgeInfo = info; bridgeInfo = info;
bridgeLayer = init.World.WorldActor.Trait<BridgeLayer>(); bridgeLayer = init.World.WorldActor.Trait<BridgeLayer>();

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits.Render
bool renderOpen; bool renderOpen;
public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info) public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
gateBodyInfo = info; gateBodyInfo = info;
gate = init.Self.Trait<Gate>(); gate = init.Self.Trait<Gate>();

View File

@@ -48,12 +48,15 @@ namespace OpenRA.Mods.Common.Traits.Render
if (Palette != null) if (Palette != null)
p = init.WorldRenderer.Palette(Palette); p = init.WorldRenderer.Palette(Palette);
Func<int> facing; Func<WAngle> facing;
if (init.Contains<DynamicFacingInit>()) if (init.Contains<DynamicFacingInit>())
facing = init.Get<DynamicFacingInit, Func<int>>(); {
var getFacing = init.Get<DynamicFacingInit, Func<int>>();
facing = () => WAngle.FromFacing(getFacing());
}
else else
{ {
var f = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0; var f = WAngle.FromFacing(init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0);
facing = () => f; facing = () => f;
} }
@@ -61,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
var body = init.Actor.TraitInfo<BodyOrientationInfo>(); var body = init.Actor.TraitInfo<BodyOrientationInfo>();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings); Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> offset = () => body.LocalToWorld(Offset.Rotate(orientation())); Func<WVec> offset = () => body.LocalToWorld(Offset.Rotate(orientation()));
Func<int> zOffset = () => Func<int> zOffset = () =>
{ {

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{ {
readonly Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>(); readonly Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
readonly Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>(); readonly Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
readonly Func<int> getFacing; readonly Func<WAngle> getFacing;
readonly Armament[] armaments; readonly Armament[] armaments;
public WithMuzzleOverlay(Actor self, WithMuzzleOverlayInfo info) public WithMuzzleOverlay(Actor self, WithMuzzleOverlayInfo info)
@@ -55,11 +55,11 @@ namespace OpenRA.Mods.Common.Traits.Render
// Workaround for broken ternary operators in certain versions of mono (3.10 and // Workaround for broken ternary operators in certain versions of mono (3.10 and
// certain versions of the 3.8 series): https://bugzilla.xamarin.com/show_bug.cgi?id=23319 // certain versions of the 3.8 series): https://bugzilla.xamarin.com/show_bug.cgi?id=23319
if (turreted != null) if (turreted != null)
getFacing = () => turreted.TurretFacing; getFacing = () => WAngle.FromFacing(turreted.TurretFacing);
else if (facing != null) else if (facing != null)
getFacing = () => facing.Facing; getFacing = () => WAngle.FromFacing(facing.Facing);
else else
getFacing = () => 0; getFacing = () => WAngle.Zero;
var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing); var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing);
visible.Add(barrel, false); visible.Add(barrel, false);
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits.Render
var sequence = a.Info.MuzzleSequence; var sequence = a.Info.MuzzleSequence;
if (a.Info.MuzzleSplitFacings > 0) if (a.Info.MuzzleSplitFacings > 0)
sequence += Util.QuantizeFacing(getFacing(), a.Info.MuzzleSplitFacings).ToString(); sequence += Util.QuantizeFacing(getFacing().Facing, a.Info.MuzzleSplitFacings).ToString();
visible[barrel] = true; visible[barrel] = true;
anims[barrel].Animation.PlayThen(sequence, () => visible[barrel] = false); anims[barrel].Animation.PlayThen(sequence, () => visible[barrel] = false);

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{ {
var anim = new Animation(init.World, image, () => 0); var anim = new Animation(init.World, image);
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0); anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
var bi = init.Actor.TraitInfo<BuildingInfo>(); var bi = init.Actor.TraitInfo<BuildingInfo>();

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render
PlayerResources playerResources; PlayerResources playerResources;
public WithResourceLevelSpriteBody(ActorInitializer init, WithResourceLevelSpriteBodyInfo info) public WithResourceLevelSpriteBody(ActorInitializer init, WithResourceLevelSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
this.info = info; this.info = info;
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>(); playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();

View File

@@ -46,11 +46,11 @@ namespace OpenRA.Mods.Common.Traits.Render
.First(tt => tt.Turret == armament.Turret); .First(tt => tt.Turret == armament.Turret);
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, armament.Turret); var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, armament.Turret);
var anim = new Animation(init.World, image, turretFacing); var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
Func<int> facing = init.GetFacing(); var facing = init.GetFacing();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings); Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation())); Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
Func<int> zOffset = () => Func<int> zOffset = () =>
{ {
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits.Render
.First(tt => tt.Name == armament.Info.Turret); .First(tt => tt.Name == armament.Info.Turret);
rs = self.Trait<RenderSprites>(); rs = self.Trait<RenderSprites>();
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing); DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => WAngle.FromFacing(turreted.TurretFacing));
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
rs.Add(new AnimationWithOffset( rs.Add(new AnimationWithOffset(
DefaultAnimation, () => BarrelOffset(), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 0))); DefaultAnimation, () => BarrelOffset(), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 0)));

View File

@@ -56,9 +56,9 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly Animation boundsAnimation; readonly Animation boundsAnimation;
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info) public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
: this(init, info, () => 0) { } : this(init, info, () => WAngle.Zero) { }
protected WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info, Func<int> baseFacing) protected WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info, Func<WAngle> baseFacing)
: base(info) : base(info)
{ {
rs = init.Self.Trait<RenderSprites>(); rs = init.Self.Trait<RenderSprites>();

View File

@@ -51,11 +51,11 @@ namespace OpenRA.Mods.Common.Traits.Render
.First(tt => tt.Turret == Turret); .First(tt => tt.Turret == Turret);
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret); var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret);
var anim = new Animation(init.World, image, turretFacing); var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
Func<int> facing = init.GetFacing(); var facing = init.GetFacing();
Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromFacing(facing()), facings); Func<WRot> orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings);
Func<WVec> offset = () => body.LocalToWorld(t.Offset.Rotate(orientation())); Func<WVec> offset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
Func<int> zOffset = () => Func<int> zOffset = () =>
{ {
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits.Render
arms = self.TraitsImplementing<Armament>() arms = self.TraitsImplementing<Armament>()
.Where(w => w.Info.Turret == info.Turret).ToArray(); .Where(w => w.Info.Turret == info.Turret).ToArray();
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing); DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => WAngle.FromFacing(t.TurretFacing));
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
rs.Add(new AnimationWithOffset(DefaultAnimation, rs.Add(new AnimationWithOffset(DefaultAnimation,
() => TurretOffset(self), () => TurretOffset(self),

View File

@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
var anim = new Animation(init.World, image, () => 0); var anim = new Animation(init.World, image);
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => adjacent); anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => adjacent);
yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale); yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void IWallConnector.SetDirty() { dirty = true; } void IWallConnector.SetDirty() { dirty = true; }
public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info) public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info)
{ {
wallInfo = info; wallInfo = info;
} }

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
// Facing rotation // Facing rotation
rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed / 1024); rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed / 1024);
var anim = new Animation(init.World, rs.GetImage(self), () => facing.Angle / 4); var anim = new Animation(init.World, rs.GetImage(self), () => facing);
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);
rs.Add(new AnimationWithOffset(anim, () => pos, null)); rs.Add(new AnimationWithOffset(anim, () => pos, null));
} }