Rename LocalCoordinatesModel -> BodyOrientation.

This commit is contained in:
Paul Chote
2013-05-25 14:45:44 +12:00
parent e7aa6ce998
commit 53aa698491
12 changed files with 44 additions and 44 deletions

View File

@@ -16,7 +16,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Traits
{
public class RenderSimpleInfo : RenderSpritesInfo, LocalCoordinatesModelInfo
public class RenderSimpleInfo : RenderSpritesInfo, IBodyOrientationInfo
{
[Desc("Number of facings for gameplay calculations. -1 indiciates auto-detection from sequence")]
public readonly int QuantizedFacings = -1;
@@ -34,7 +34,7 @@ namespace OpenRA.Traits
}
}
public class RenderSimple : RenderSprites, ILocalCoordinatesModel, IAutoSelectionSize
public class RenderSimple : RenderSprites, IBodyOrientation, IAutoSelectionSize
{
RenderSimpleInfo Info;

View File

@@ -187,12 +187,12 @@ namespace OpenRA.Traits
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); }
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
public interface IRenderAsTerrain { IEnumerable<IRenderable> RenderAsTerrain(WorldRenderer wr, Actor self); }
public interface ILocalCoordinatesModel
public interface IBodyOrientation
{
WVec LocalToWorld(WVec vec);
WRot QuantizeOrientation(Actor self, WRot orientation);
}
public interface LocalCoordinatesModelInfo {}
public interface IBodyOrientationInfo {}
public interface ITargetable
{

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc
{
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<LocalCoordinatesModelInfo>
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Cargo position relative to turret or body. (forward, right, up) triples")]
public readonly WRange[] LocalOffset = {};
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc
IFacing facing;
WithCargoInfo Info;
WVec[] positions;
ILocalCoordinatesModel coords;
IBodyOrientation body;
public WithCargo(Actor self, WithCargoInfo info)
{
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc
facing = self.TraitOrDefault<IFacing>();
Info = info;
coords = self.Trait<ILocalCoordinatesModel>();
body = self.Trait<IBodyOrientation>();
if (info.LocalOffset.Length % 3 != 0)
throw new InvalidOperationException("Invalid LocalOffset array length");
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc
foreach (var rr in r)
yield return rr;
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
var pos = self.CenterPosition;
int i = 0;
foreach (var c in cargo.Passengers)
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Cnc
var cargoPassenger = c.Trait<Passenger>();
if (Info.DisplayTypes.Contains(cargoPassenger.info.CargoType))
{
var offset = pos - c.CenterPosition + coords.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation));
var offset = pos - c.CenterPosition + body.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation));
foreach (var cr in c.Render(wr))
yield return cr.WithPos(cr.Pos + offset).WithZOffset(1);
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels;
Lazy<Turreted> Turret;
Lazy<ILocalCoordinatesModel> Coords;
Lazy<IBodyOrientation> Coords;
public WRange Recoil;
public int FireDelay { get; private set; }
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA
// We can't resolve these until runtime
Turret = Lazy.New(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
Coords = Lazy.New(() => self.Trait<ILocalCoordinatesModel>());
Coords = Lazy.New(() => self.Trait<IBodyOrientation>());
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
Burst = Weapon.Burst;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class ContrailInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo>
class ContrailInfo : ITraitInfo, Requires<IBodyOrientationInfo>
{
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
{
ContrailInfo info;
ContrailHistory history;
ILocalCoordinatesModel coords;
IBodyOrientation body;
public Contrail(Actor self, ContrailInfo info)
{
@@ -40,13 +40,13 @@ namespace OpenRA.Mods.RA
history = new ContrailHistory(info.TrailLength,
info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color);
coords = self.Trait<ILocalCoordinatesModel>();
body = self.Trait<IBodyOrientation>();
}
public void Tick(Actor self)
{
var local = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation));
history.Tick(self.CenterPosition + coords.LocalToWorld(local));
var local = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
history.Tick(self.CenterPosition + body.LocalToWorld(local));
}
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); }

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<LocalCoordinatesModelInfo>
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
@@ -29,12 +29,12 @@ namespace OpenRA.Mods.RA.Render
public WithRotor(Actor self, WithRotorInfo info)
{
var rs = self.Trait<RenderSprites>();
var coords = self.Trait<ILocalCoordinatesModel>();
var body = self.Trait<IBodyOrientation>();
rotorAnim = new Animation(rs.GetImage(self));
rotorAnim.PlayRepeating("rotor");
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => coords.LocalToWorld(info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation))),
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
}

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class WithSpinnerInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<LocalCoordinatesModelInfo>
class WithSpinnerInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "spinner";
@@ -30,12 +30,12 @@ namespace OpenRA.Mods.RA.Render
public WithSpinner(Actor self, WithSpinnerInfo info)
{
var rs = self.Trait<RenderSprites>();
var coords = self.Trait<ILocalCoordinatesModel>();
var body = self.Trait<IBodyOrientation>();
var spinner = new Animation(rs.GetImage(self));
spinner.PlayRepeating(info.Sequence);
rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner,
() => coords.LocalToWorld(info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation))),
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
}
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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
@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class WithTurretInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<LocalCoordinatesModelInfo>
class WithTurretInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "turret";
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Render
{
WithTurretInfo info;
RenderSprites rs;
ILocalCoordinatesModel coords;
IBodyOrientation body;
AttackBase ab;
Turreted t;
IEnumerable<Armament> arms;
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Render
{
this.info = info;
rs = self.Trait<RenderSprites>();
coords = self.Trait<ILocalCoordinatesModel>();
body = self.Trait<IBodyOrientation>();
ab = self.TraitOrDefault<AttackBase>();
t = self.TraitsImplementing<Turreted>()
@@ -72,9 +72,9 @@ namespace OpenRA.Mods.RA.Render
var recoil = arms.Aggregate(WRange.Zero, (a,b) => a + b.Recoil);
var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero);
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
var turretOrientation = coords.QuantizeOrientation(self, t.LocalOrientation(self));
return t.Position(self) + coords.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
var turretOrientation = body.QuantizeOrientation(self, t.LocalOrientation(self));
return t.Position(self) + body.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
}
public void Tick(Actor self)

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo>
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<IBodyOrientationInfo>
{
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.RA
class SmokeTrailWhenDamaged : ITick
{
ILocalCoordinatesModel coords;
IBodyOrientation body;
SmokeTrailWhenDamagedInfo info;
int ticks;
public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info)
{
this.info = info;
coords = self.Trait<ILocalCoordinatesModel>();
body = self.Trait<IBodyOrientation>();
}
public void Tick(Actor self)
@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA
if (position.Z > 0 && self.GetDamageState() >= DamageState.Heavy &&
!self.World.FogObscures(new CPos(position)))
{
var offset = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation));
var pos = position + coords.LocalToWorld(offset);
var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var pos = position + body.LocalToWorld(offset);
self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite)));
}

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class NukePowerInfo : SupportPowerInfo, Requires<LocalCoordinatesModelInfo>
class NukePowerInfo : SupportPowerInfo, Requires<IBodyOrientationInfo>
{
[WeaponReference]
public readonly string MissileWeapon = "";
@@ -25,12 +25,12 @@ namespace OpenRA.Mods.RA
class NukePower : SupportPower
{
ILocalCoordinatesModel coords;
IBodyOrientation body;
public NukePower(Actor self, NukePowerInfo info)
: base(self, info)
{
coords = self.Trait<ILocalCoordinatesModel>();
body = self.Trait<IBodyOrientation>();
}
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
var rb = self.Trait<RenderSimple>();
rb.PlayCustomAnim(self, "active");
self.World.AddFrameEndTask(w => w.Add(
new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + coords.LocalToWorld(npi.SpawnOffset), order.TargetLocation)));
new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + body.LocalToWorld(npi.SpawnOffset), order.TargetLocation)));
}
}
}

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<LocalCoordinatesModelInfo>
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<IBodyOrientationInfo>
{
public readonly string Anim = null;
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
var self = init.self;
var rs = self.Trait<RenderSimple>();
var coords = self.Trait<ILocalCoordinatesModel>();
var body = self.Trait<IBodyOrientation>();
// TODO: Carry orientation over from the parent instead of just facing
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 0;
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
var throwOffset = new WVec((int)(Game.CosmeticRandom.Gauss1D(1)*info.ThrowRange.Range), 0, 0).Rotate(throwRotation);
initialPos = pos = info.Offset.Rotate(coords.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
finalPos = initialPos + throwOffset;
// Facing rotation

View File

@@ -84,9 +84,9 @@ namespace OpenRA.Mods.RA
// Turret offset in world-space
public WVec Position(Actor self)
{
var coords = self.Trait<ILocalCoordinatesModel>();
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
return coords.LocalToWorld(Offset.Rotate(bodyOrientation));
var body = self.Trait<IBodyOrientation>();
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
return body.LocalToWorld(Offset.Rotate(bodyOrientation));
}
// Orientation in unit-space