Refactored IQuantizeBodyOrientation implementation
Moved BodyOrientation and related interfaces from Game to Mods.Common. Introduced QuantizeFacingsFromSequence trait. With*Body render traits no longer implement IQuantizeBodyOrientation themselves.
This commit is contained in:
@@ -191,7 +191,6 @@
|
||||
<Compile Include="Graphics\VoxelRenderer.cs" />
|
||||
<Compile Include="Graphics\VoxelLoader.cs" />
|
||||
<Compile Include="Graphics\VoxelProvider.cs" />
|
||||
<Compile Include="Traits\BodyOrientation.cs" />
|
||||
<Compile Include="Graphics\VoxelAnimation.cs" />
|
||||
<Compile Include="Traits\Player\FrozenActorLayer.cs" />
|
||||
<Compile Include="Graphics\Theater.cs" />
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class BodyOrientationInfo : ITraitInfo, IBodyOrientationInfo
|
||||
{
|
||||
[Desc("Number of facings for gameplay calculations. -1 indicates auto-detection from another trait")]
|
||||
public readonly int QuantizedFacings = -1;
|
||||
|
||||
[Desc("Camera pitch for rotation calculations")]
|
||||
public readonly WAngle CameraPitch = WAngle.FromDegrees(40);
|
||||
|
||||
[Desc("Fudge the coordinate system angles like the early games.")]
|
||||
public readonly bool UseClassicPerspectiveFudge = true;
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
// Rotate by 90 degrees
|
||||
if (!UseClassicPerspectiveFudge)
|
||||
return new WVec(vec.Y, -vec.X, vec.Z);
|
||||
|
||||
// RA's 2d perspective doesn't correspond to an orthonormal 3D
|
||||
// coordinate system, so fudge the y axis to make things look good
|
||||
return new WVec(vec.Y, -CameraPitch.Sin() * vec.X / 1024, vec.Z);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(WRot orientation, int facings)
|
||||
{
|
||||
// Quantization disabled
|
||||
if (facings == 0)
|
||||
return orientation;
|
||||
|
||||
// Map yaw to the closest facing
|
||||
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, facings) * (256 / facings);
|
||||
|
||||
// Roll and pitch are always zero if yaw is quantized
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
||||
}
|
||||
|
||||
public class BodyOrientation : IBodyOrientation
|
||||
{
|
||||
readonly BodyOrientationInfo info;
|
||||
readonly Lazy<int> quantizedFacings;
|
||||
|
||||
[Sync] public int QuantizedFacings { get { return quantizedFacings.Value; } }
|
||||
|
||||
public BodyOrientation(ActorInitializer init, BodyOrientationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
var self = init.Self;
|
||||
var faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
||||
|
||||
quantizedFacings = Exts.Lazy(() =>
|
||||
{
|
||||
// Override value is set
|
||||
if (info.QuantizedFacings >= 0)
|
||||
return info.QuantizedFacings;
|
||||
|
||||
var qboi = self.Info.Traits.GetOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
if (qboi == null)
|
||||
throw new InvalidOperationException("Actor type '" + self.Info.Name + "' does not define a quantized body orientation.");
|
||||
|
||||
return qboi.QuantizedBodyFacings(self.Info, self.World.Map.SequenceProvider, faction);
|
||||
});
|
||||
}
|
||||
|
||||
public WAngle CameraPitch { get { return info.CameraPitch; } }
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
return info.LocalToWorld(vec);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(Actor self, WRot orientation)
|
||||
{
|
||||
return info.QuantizeOrientation(orientation, quantizedFacings.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,22 +308,6 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface IPostRenderSelection { IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr); }
|
||||
|
||||
public interface IBodyOrientation
|
||||
{
|
||||
WAngle CameraPitch { get; }
|
||||
int QuantizedFacings { get; }
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(Actor self, WRot orientation);
|
||||
}
|
||||
|
||||
public interface IBodyOrientationInfo : ITraitInfo
|
||||
{
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(WRot orientation, int facings);
|
||||
}
|
||||
|
||||
public interface IQuantizeBodyOrientationInfo { int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string faction); }
|
||||
|
||||
public interface ITargetableInfo
|
||||
{
|
||||
string[] GetTargetTypes();
|
||||
|
||||
Reference in New Issue
Block a user