From d235dad7547893a4ac9d0c5b1af9b13a1b491325 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 15 Jan 2016 17:05:00 +0000 Subject: [PATCH] Fix voxel barrel rendering. --- .../Traits/Render/WithVoxelBarrel.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs index b944bdb5fb..5be2a84bed 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs @@ -44,20 +44,26 @@ namespace OpenRA.Mods.Common.Traits var turretFacing = Turreted.GetInitialTurretFacing(init, t.InitialFacing, t.Turret); var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw), facings); - var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation)); - yield return new VoxelAnimation(voxel, () => turretOffset, () => new[] { turretOrientation, orientation }, + var quantizedTurret = body.QuantizeOrientation(turretOrientation, facings); + var quantizedBody = body.QuantizeOrientation(orientation, facings); + var barrelOffset = body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret)).Rotate(quantizedBody)); + + yield return new VoxelAnimation(voxel, () => barrelOffset, () => new[] { turretOrientation, orientation }, () => false, () => 0); } } - public class WithVoxelBarrel : UpgradableTrait + public class WithVoxelBarrel : UpgradableTrait, INotifyBuildComplete, INotifySold, INotifyTransform { readonly Actor self; readonly Armament armament; readonly Turreted turreted; readonly BodyOrientation body; + // TODO: This should go away once https://github.com/OpenRA/OpenRA/issues/7035 is implemented + bool buildComplete; + public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info) : base(info) { @@ -68,21 +74,23 @@ namespace OpenRA.Mods.Common.Traits turreted = self.TraitsImplementing() .First(tt => tt.Name == armament.Info.Turret); + buildComplete = !self.Info.HasTraitInfo(); // always render instantly for units + var rv = self.Trait(); rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence), BarrelOffset, BarrelRotation, - () => IsTraitDisabled, () => 0)); + () => IsTraitDisabled || !buildComplete, () => 0)); } WVec BarrelOffset() { var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero); - var turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero; + var turretLocalOffset = turreted != null ? turreted.Offset : WVec.Zero; var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero; var quantizedBody = body.QuantizeOrientation(self, self.Orientation); var quantizedTurret = body.QuantizeOrientation(self, turretOrientation); - return turretOffset + body.LocalToWorld(localOffset.Rotate(quantizedTurret).Rotate(quantizedBody)); + return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(quantizedTurret)).Rotate(quantizedBody)); } IEnumerable BarrelRotation() @@ -92,5 +100,12 @@ namespace OpenRA.Mods.Common.Traits yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw); yield return qb; } + + void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; } + void INotifySold.Selling(Actor self) { buildComplete = false; } + void INotifySold.Sold(Actor self) { } + void INotifyTransform.BeforeTransform(Actor self) { buildComplete = false; } + void INotifyTransform.OnTransform(Actor self) { } + void INotifyTransform.AfterTransform(Actor toActor) { } } }