Change QuantizeFacing to return a facing instead of an index.
This commit is contained in:
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Cnc.Graphics
|
|||||||
|
|
||||||
protected override int GetFacingFrameOffset(WAngle facing)
|
protected override int GetFacingFrameOffset(WAngle facing)
|
||||||
{
|
{
|
||||||
return Util.ClassicQuantizeFacing(facing.Facing, Facings, useClassicFacings);
|
return useClassicFacings ? Util.ClassicIndexFacing(facing.Facing, Facings) : Common.Util.IndexFacing(facing.Facing, Facings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
public override int QuantizeFacing(int facing, int facings)
|
public override int QuantizeFacing(int facing, int facings)
|
||||||
{
|
{
|
||||||
return OpenRA.Mods.Cnc.Util.ClassicQuantizeFacing(facing, facings, true) * (256 / facings);
|
return Util.ClassicQuantizeFacing(facing, facings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new ClassicFacingBodyOrientation(init, this); }
|
public override object Create(ActorInitializer init) { return new ClassicFacingBodyOrientation(init, this); }
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
// This table defines the exclusive maximum facing for the i'th sprite frame.
|
// This table defines the exclusive maximum facing for the i'th sprite frame.
|
||||||
// i.e. sprite frame 1 is used for facings 5-13, sprite frame 2 for 14-21, and so on.
|
// i.e. sprite frame 1 is used for facings 5-13, sprite frame 2 for 14-21, and so on.
|
||||||
// Sprite frame 0 is used for facings smaller than 5 or larger than 249.
|
// Sprite frame 0 is used for facings smaller than 5 or larger than 249.
|
||||||
static readonly int[] SpriteFacings =
|
static readonly int[] SpriteRanges =
|
||||||
{
|
{
|
||||||
5, 14, 22, 33, 39, 46, 53, 60,
|
5, 14, 22, 33, 39, 46, 53, 60,
|
||||||
67, 74, 81, 88, 96, 104, 113, 122,
|
67, 74, 81, 88, 96, 104, 113, 122,
|
||||||
@@ -25,18 +25,44 @@ namespace OpenRA.Mods.Cnc
|
|||||||
195, 202, 209, 216, 224, 232, 241, 250
|
195, 202, 209, 216, 224, 232, 241, 250
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int ClassicQuantizeFacing(int facing, int numFrames, bool useClassicFacingFudge)
|
// The actual facing associated with each sprite frame.
|
||||||
|
static readonly int[] SpriteFacings =
|
||||||
{
|
{
|
||||||
if (useClassicFacingFudge && numFrames == 32)
|
0, 10, 18, 28, 36, 43, 50, 57,
|
||||||
|
64, 71, 78, 85, 92, 100, 109, 118,
|
||||||
|
128, 138, 147, 156, 164, 171, 178, 185,
|
||||||
|
192, 199, 206, 213, 220, 228, 237, 246
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate the frame index (between 0..numFrames) that
|
||||||
|
/// should be used for the given facing value, accounting
|
||||||
|
/// for the non-linear facing mapping for sprites with 32 directions.
|
||||||
|
/// </summary>
|
||||||
|
public static int ClassicIndexFacing(int facing, int numFrames)
|
||||||
|
{
|
||||||
|
if (numFrames == 32)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < SpriteFacings.Length; i++)
|
for (var i = 0; i < SpriteRanges.Length; i++)
|
||||||
if (facing < SpriteFacings[i])
|
if (facing < SpriteRanges[i])
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Common.Util.QuantizeFacing(facing, numFrames);
|
return Common.Util.IndexFacing(facing, numFrames);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rounds the given facing value to the nearest quantized step,
|
||||||
|
/// accounting for the non-linear facing mapping for sprites with 32 directions.
|
||||||
|
/// </summary>
|
||||||
|
public static int ClassicQuantizeFacing(int facing, int steps)
|
||||||
|
{
|
||||||
|
if (steps == 32)
|
||||||
|
return SpriteFacings[ClassicIndexFacing(facing, steps)];
|
||||||
|
|
||||||
|
return Common.Util.QuantizeFacing(facing, steps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
|
|
||||||
protected virtual int GetFacingFrameOffset(WAngle facing)
|
protected virtual int GetFacingFrameOffset(WAngle facing)
|
||||||
{
|
{
|
||||||
return Util.QuantizeFacing(facing.Facing, Facings);
|
return Util.IndexFacing(facing.Facing, Facings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var sequence = a.Info.MuzzleSequence;
|
var sequence = a.Info.MuzzleSequence;
|
||||||
|
|
||||||
if (a.Info.MuzzleSplitFacings > 0)
|
if (a.Info.MuzzleSplitFacings > 0)
|
||||||
sequence += Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString();
|
sequence += Util.IndexFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString();
|
||||||
|
|
||||||
var muzzleFlash = new AnimationWithOffset(muzzleAnim,
|
var muzzleFlash = new AnimationWithOffset(muzzleAnim,
|
||||||
() => PortOffset(self, port),
|
() => PortOffset(self, port),
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public virtual int QuantizeFacing(int facing, int facings)
|
public virtual int QuantizeFacing(int facing, int facings)
|
||||||
{
|
{
|
||||||
return Util.QuantizeFacing(facing, facings) * (256 / facings);
|
return Util.QuantizeFacing(facing, facings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
public override object Create(ActorInitializer init) { return new BodyOrientation(init, this); }
|
||||||
|
|||||||
@@ -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().Facing, a.Info.MuzzleSplitFacings).ToString();
|
sequence += Util.IndexFacing(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);
|
||||||
|
|||||||
@@ -46,13 +46,23 @@ namespace OpenRA.Mods.Common
|
|||||||
return facing + turn;
|
return facing + turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int QuantizeFacing(int facing, int numFrames)
|
/// <summary>
|
||||||
|
/// Calculate the frame index (between 0..numFrames) that
|
||||||
|
/// should be used for the given facing value.
|
||||||
|
/// </summary>
|
||||||
|
public static int IndexFacing(int facing, int numFrames)
|
||||||
{
|
{
|
||||||
var step = 256 / numFrames;
|
var step = 256 / numFrames;
|
||||||
var a = (facing + step / 2) & 0xff;
|
var a = (facing + step / 2) & 0xff;
|
||||||
return a / step;
|
return a / step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Rounds the given facing value to the nearest quantized step.</summary>
|
||||||
|
public static int QuantizeFacing(int facing, int steps)
|
||||||
|
{
|
||||||
|
return IndexFacing(facing, steps) * (256 / steps);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Wraps an arbitrary integer facing value into the range 0 - 255</summary>
|
/// <summary>Wraps an arbitrary integer facing value into the range 0 - 255</summary>
|
||||||
public static int NormalizeFacing(int f)
|
public static int NormalizeFacing(int f)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user