Move ClassicFacingFudge support to Mods.Cnc
This moves the TD/RA-specific re-mapping of sprite facings and coordinates to Mods.Cnc.
This commit is contained in:
@@ -95,11 +95,11 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
static readonly WDist DefaultShadowSpriteZOffset = new WDist(-5);
|
||||
protected Sprite[] sprites;
|
||||
readonly bool reverseFacings, transpose, useClassicFacingFudge;
|
||||
readonly bool reverseFacings, transpose;
|
||||
readonly string sequence;
|
||||
|
||||
protected readonly ISpriteSequenceLoader Loader;
|
||||
|
||||
readonly string sequence;
|
||||
public string Name { get; private set; }
|
||||
public int Start { get; private set; }
|
||||
public int Length { get; private set; }
|
||||
@@ -156,7 +156,6 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
Tick = LoadField(d, "Tick", 40);
|
||||
transpose = LoadField(d, "Transpose", false);
|
||||
Frames = LoadField<int[]>(d, "Frames", null);
|
||||
useClassicFacingFudge = LoadField(d, "UseClassicFacingFudge", false);
|
||||
|
||||
var flipX = LoadField(d, "FlipX", false);
|
||||
var flipY = LoadField(d, "FlipY", false);
|
||||
@@ -168,11 +167,6 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
Facings = -Facings;
|
||||
}
|
||||
|
||||
if (useClassicFacingFudge && Facings != 32)
|
||||
throw new InvalidOperationException(
|
||||
"{0}: Sequence {1}.{2}: UseClassicFacingFudge is only valid for 32 facings"
|
||||
.F(info.Nodes[0].Location, sequence, animation));
|
||||
|
||||
var offset = LoadField(d, "Offset", float3.Zero);
|
||||
var blendMode = LoadField(d, "BlendMode", BlendMode.Alpha);
|
||||
|
||||
@@ -384,7 +378,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
protected virtual Sprite GetSprite(int start, int frame, int facing)
|
||||
{
|
||||
var f = Util.QuantizeFacing(facing, Facings, useClassicFacingFudge);
|
||||
var f = QuantizeFacing(facing);
|
||||
if (reverseFacings)
|
||||
f = (Facings - f) % Facings;
|
||||
|
||||
@@ -398,5 +392,10 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
return sprites[j];
|
||||
}
|
||||
|
||||
protected virtual int QuantizeFacing(int facing)
|
||||
{
|
||||
return Util.QuantizeFacing(facing, Facings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class BodyOrientationInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Number of facings for gameplay calculations. -1 indicates auto-detection from another trait")]
|
||||
[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")]
|
||||
[Desc("Camera pitch for rotation calculations.")]
|
||||
public readonly WAngle CameraPitch = WAngle.FromDegrees(40);
|
||||
|
||||
[Desc("Fudge the coordinate system angles like the early games.")]
|
||||
[Desc("Fudge the coordinate system angles to simulate non-top-down perspective in mods with square cells.")]
|
||||
public readonly bool UseClassicPerspectiveFudge = true;
|
||||
|
||||
[Desc("Fudge the coordinate system angles like the early games.")]
|
||||
public readonly bool UseClassicFacingFudge = false;
|
||||
|
||||
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
|
||||
// The 2d perspective of older games with square cells 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);
|
||||
}
|
||||
@@ -53,12 +50,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
|
||||
public int QuantizeFacing(int facing, int facings)
|
||||
public virtual int QuantizeFacing(int facing, int facings)
|
||||
{
|
||||
return Util.QuantizeFacing(facing, facings, UseClassicFacingFudge) * (256 / facings);
|
||||
return Util.QuantizeFacing(facing, facings) * (256 / facings);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
||||
public virtual object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
||||
}
|
||||
|
||||
public class BodyOrientation : ISync
|
||||
|
||||
@@ -53,30 +53,6 @@ namespace OpenRA.Mods.Common
|
||||
return a / step;
|
||||
}
|
||||
|
||||
public static int QuantizeFacing(int facing, int numFrames, bool useClassicFacingFudge)
|
||||
{
|
||||
if (!useClassicFacingFudge || numFrames != 32)
|
||||
return Util.QuantizeFacing(facing, numFrames);
|
||||
|
||||
// TD and RA divided the facing artwork into 3 frames from (north|south) to (north|south)-(east|west)
|
||||
// and then 5 frames from (north|south)-(east|west) to (east|west)
|
||||
var quadrant = ((facing + 31) & 0xFF) / 64;
|
||||
if (quadrant == 0 || quadrant == 2)
|
||||
{
|
||||
var frame = Util.QuantizeFacing(facing, 24);
|
||||
if (frame > 18)
|
||||
return frame + 6;
|
||||
if (frame > 4)
|
||||
return frame + 3;
|
||||
return frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
var frame = Util.QuantizeFacing(facing, 40);
|
||||
return frame < 20 ? frame - 3 : frame - 8;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Wraps an arbitrary integer facing value into the range 0 - 255</summary>
|
||||
public static int NormalizeFacing(int f)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user