Added sub-pixel position/vector types.

Updated Sync code to handle new sub-pixel types.
This commit is contained in:
James Dunne
2012-06-21 17:33:54 -05:00
parent 9c49143534
commit b127ae8027
16 changed files with 484 additions and 283 deletions

View File

@@ -78,6 +78,8 @@
<Compile Include="ActorInitializer.cs" />
<Compile Include="ActorMap.cs" />
<Compile Include="ActorReference.cs" />
<Compile Include="PSubVec.cs" />
<Compile Include="PSubPos.cs" />
<Compile Include="PVecInt.cs" />
<Compile Include="PVecFloat.cs" />
<Compile Include="PPos.cs" />

View File

@@ -47,6 +47,7 @@ namespace OpenRA
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public CPos ToCPos() { return new CPos((int)(1f / Game.CellSize * X), (int)(1f / Game.CellSize * Y)); }
public PSubPos ToPSubPos() { return new PSubPos(X * PSubPos.PerPx, Y * PSubPos.PerPx); }
public PPos Clamp(Rectangle r)
{

73
OpenRA.Game/PSubPos.cs Normal file
View File

@@ -0,0 +1,73 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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;
using System.Drawing;
namespace OpenRA
{
/// <summary>
/// Sub-pixel coordinate position in the world (very fine).
/// </summary>
public struct PSubPos
{
public readonly int X, Y;
public PSubPos(int x, int y) { X = x; Y = y; }
public const int PerPx = 1024;
public static readonly PSubPos Zero = new PSubPos(0, 0);
public static explicit operator PSubPos(int2 a) { return new PSubPos(a.X, a.Y); }
public static explicit operator PSubVec(PSubPos a) { return new PSubVec(a.X, a.Y); }
public static explicit operator PVecFloat(PSubPos a) { return new PVecFloat(a.X, a.Y); }
public static PSubPos operator +(PSubPos a, PSubVec b) { return new PSubPos(a.X + b.X, a.Y + b.Y); }
public static PSubVec operator -(PSubPos a, PSubPos b) { return new PSubVec(a.X - b.X, a.Y - b.Y); }
public static PSubPos operator -(PSubPos a, PSubVec b) { return new PSubPos(a.X - b.X, a.Y - b.Y); }
public static bool operator ==(PSubPos me, PSubPos other) { return (me.X == other.X && me.Y == other.Y); }
public static bool operator !=(PSubPos me, PSubPos other) { return !(me == other); }
public static PSubPos Max(PSubPos a, PSubPos b) { return new PSubPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static PSubPos Min(PSubPos a, PSubPos b) { return new PSubPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public static PSubPos Lerp(PSubPos a, PSubPos b, int mul, int div)
{
return a + ((PSubVec)(b - a) * mul / div);
}
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public PPos ToPPos() { return new PPos(X / PerPx, Y / PerPx); }
public CPos ToCPos() { return ToPPos().ToCPos(); }
public PSubPos Clamp(Rectangle r)
{
return new PSubPos(Math.Min(r.Right, Math.Max(X, r.Left)),
Math.Min(r.Bottom, Math.Max(Y, r.Top)));
}
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
PSubPos o = (PSubPos)obj;
return o == this;
}
public override string ToString() { return "{0},{1}".F(X, Y); }
}
}

103
OpenRA.Game/PSubVec.cs Normal file
View File

@@ -0,0 +1,103 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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;
using System.Drawing;
namespace OpenRA
{
/// <summary>
/// Sub-pixel coordinate vector (very fine)
/// </summary>
public struct PSubVec
{
public readonly int X, Y;
public PSubVec(int x, int y) { X = x; Y = y; }
public PSubVec(Size p) { X = p.Width; Y = p.Height; }
public static readonly PSubVec Zero = new PSubVec(0, 0);
public static PSubVec OneCell { get { return new PSubVec(Game.CellSize, Game.CellSize); } }
public static explicit operator PSubVec(int2 a) { return new PSubVec(a.X, a.Y); }
public static explicit operator PSubVec(float2 a) { return new PSubVec((int)a.X, (int)a.Y); }
public static PSubVec FromRadius(int r) { return new PSubVec(r, r); }
public static PSubVec operator +(PSubVec a, PSubVec b) { return new PSubVec(a.X + b.X, a.Y + b.Y); }
public static PSubVec operator -(PSubVec a, PSubVec b) { return new PSubVec(a.X - b.X, a.Y - b.Y); }
public static PSubVec operator *(int a, PSubVec b) { return new PSubVec(a * b.X, a * b.Y); }
public static PSubVec operator *(PSubVec b, int a) { return new PSubVec(a * b.X, a * b.Y); }
public static PSubVec operator /(PSubVec a, int b) { return new PSubVec(a.X / b, a.Y / b); }
public static PSubVec operator -(PSubVec a) { return new PSubVec(-a.X, -a.Y); }
public static bool operator ==(PSubVec me, PSubVec other) { return (me.X == other.X && me.Y == other.Y); }
public static bool operator !=(PSubVec me, PSubVec other) { return !(me == other); }
public static PSubVec Max(PSubVec a, PSubVec b) { return new PSubVec(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static PSubVec Min(PSubVec a, PSubVec b) { return new PSubVec(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public static int Dot(PSubVec a, PSubVec b) { return a.X * b.X + a.Y * b.Y; }
public PSubVec Sign() { return new PSubVec(Math.Sign(X), Math.Sign(Y)); }
public PSubVec Abs() { return new PSubVec(Math.Abs(X), Math.Abs(Y)); }
public int LengthSquared { get { return X * X + Y * Y; } }
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public PVecInt ToPVecInt() { return new PVecInt(X / PSubPos.PerPx, Y / PSubPos.PerPx); }
public PSubVec Clamp(Rectangle r)
{
return new PSubVec(
Math.Min(r.Right, Math.Max(X, r.Left)),
Math.Min(r.Bottom, Math.Max(Y, r.Top))
);
}
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
PSubVec o = (PSubVec)obj;
return o == this;
}
public override string ToString() { return "{0},{1}".F(X, Y); }
}
public static class PSubVecExtensions
{
/// <summary>
/// Scales the float2 vector up to a subpixel vector.
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
public static PSubVec ToPSubVec(this float2 vec)
{
return new PSubVec((int)(vec.X * PSubPos.PerPx), (int)(vec.Y * PSubPos.PerPx));
}
public static PSubVec ToPSubVec(this PVecInt vec)
{
return new PSubVec((vec.X * PSubPos.PerPx), (vec.Y * PSubPos.PerPx));
}
public static PSubVec ToPSubVec(this PVecFloat vec)
{
return new PSubVec((int)(vec.X * PSubPos.PerPx), (int)(vec.Y * PSubPos.PerPx));
}
}
}

View File

@@ -54,6 +54,7 @@ namespace OpenRA
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public CVec ToCVec() { return new CVec(X / Game.CellSize, Y / Game.CellSize); }
public PVecInt Clamp(Rectangle r)
{

View File

@@ -70,6 +70,16 @@ namespace OpenRA
il.EmitCall(OpCodes.Call, ((Func<PVecInt, int>)hash_PVecInt).Method, null);
il.Emit(OpCodes.Xor);
}
else if (type == typeof(PSubPos))
{
il.EmitCall(OpCodes.Call, ((Func<PSubPos, int>)hash_PSubPos).Method, null);
il.Emit(OpCodes.Xor);
}
else if (type == typeof(PSubVec))
{
il.EmitCall(OpCodes.Call, ((Func<PSubVec, int>)hash_PSubVec).Method, null);
il.Emit(OpCodes.Xor);
}
else if (type == typeof(TypeDictionary))
{
il.EmitCall(OpCodes.Call, ((Func<TypeDictionary, int>)hash_tdict).Method, null);
@@ -150,6 +160,16 @@ namespace OpenRA
return ( ( i2.X * 5) ^ ( i2.Y * 3 ) ) / 4;
}
public static int hash_PSubPos(PSubPos i2)
{
return ((i2.X * 5) ^ (i2.Y * 3)) / 4;
}
public static int hash_PSubVec(PSubVec i2)
{
return ((i2.X * 5) ^ (i2.Y * 3)) / 4;
}
public static int hash_tdict( TypeDictionary d )
{
int ret = 0;

View File

@@ -219,264 +219,264 @@ namespace OpenRA.Traits
};
public static readonly int2[] SubPxVector =
public static readonly PSubVec[] SubPxVector =
{
new int2( 0, 1024 ),
new int2( 25, 1023 ),
new int2( 50, 1022 ),
new int2( 75, 1021 ),
new int2( 100, 1019 ),
new int2( 125, 1016 ),
new int2( 150, 1012 ),
new int2( 175, 1008 ),
new int2( 199, 1004 ),
new int2( 224, 999 ),
new int2( 248, 993 ),
new int2( 273, 986 ),
new int2( 297, 979 ),
new int2( 321, 972 ),
new int2( 344, 964 ),
new int2( 368, 955 ),
new int2( 391, 946 ),
new int2( 414, 936 ),
new int2( 437, 925 ),
new int2( 460, 914 ),
new int2( 482, 903 ),
new int2( 504, 890 ),
new int2( 526, 878 ),
new int2( 547, 865 ),
new int2( 568, 851 ),
new int2( 589, 837 ),
new int2( 609, 822 ),
new int2( 629, 807 ),
new int2( 649, 791 ),
new int2( 668, 775 ),
new int2( 687, 758 ),
new int2( 706, 741 ),
new int2( 724, 724 ),
new int2( 741, 706 ),
new int2( 758, 687 ),
new int2( 775, 668 ),
new int2( 791, 649 ),
new int2( 807, 629 ),
new int2( 822, 609 ),
new int2( 837, 589 ),
new int2( 851, 568 ),
new int2( 865, 547 ),
new int2( 878, 526 ),
new int2( 890, 504 ),
new int2( 903, 482 ),
new int2( 914, 460 ),
new int2( 925, 437 ),
new int2( 936, 414 ),
new int2( 946, 391 ),
new int2( 955, 368 ),
new int2( 964, 344 ),
new int2( 972, 321 ),
new int2( 979, 297 ),
new int2( 986, 273 ),
new int2( 993, 248 ),
new int2( 999, 224 ),
new int2( 1004, 199 ),
new int2( 1008, 175 ),
new int2( 1012, 150 ),
new int2( 1016, 125 ),
new int2( 1019, 100 ),
new int2( 1021, 75 ),
new int2( 1022, 50 ),
new int2( 1023, 25 ),
new int2( 1024, 0 ),
new int2( 1023, -25 ),
new int2( 1022, -50 ),
new int2( 1021, -75 ),
new int2( 1019, -100 ),
new int2( 1016, -125 ),
new int2( 1012, -150 ),
new int2( 1008, -175 ),
new int2( 1004, -199 ),
new int2( 999, -224 ),
new int2( 993, -248 ),
new int2( 986, -273 ),
new int2( 979, -297 ),
new int2( 972, -321 ),
new int2( 964, -344 ),
new int2( 955, -368 ),
new int2( 946, -391 ),
new int2( 936, -414 ),
new int2( 925, -437 ),
new int2( 914, -460 ),
new int2( 903, -482 ),
new int2( 890, -504 ),
new int2( 878, -526 ),
new int2( 865, -547 ),
new int2( 851, -568 ),
new int2( 837, -589 ),
new int2( 822, -609 ),
new int2( 807, -629 ),
new int2( 791, -649 ),
new int2( 775, -668 ),
new int2( 758, -687 ),
new int2( 741, -706 ),
new int2( 724, -724 ),
new int2( 706, -741 ),
new int2( 687, -758 ),
new int2( 668, -775 ),
new int2( 649, -791 ),
new int2( 629, -807 ),
new int2( 609, -822 ),
new int2( 589, -837 ),
new int2( 568, -851 ),
new int2( 547, -865 ),
new int2( 526, -878 ),
new int2( 504, -890 ),
new int2( 482, -903 ),
new int2( 460, -914 ),
new int2( 437, -925 ),
new int2( 414, -936 ),
new int2( 391, -946 ),
new int2( 368, -955 ),
new int2( 344, -964 ),
new int2( 321, -972 ),
new int2( 297, -979 ),
new int2( 273, -986 ),
new int2( 248, -993 ),
new int2( 224, -999 ),
new int2( 199, -1004 ),
new int2( 175, -1008 ),
new int2( 150, -1012 ),
new int2( 125, -1016 ),
new int2( 100, -1019 ),
new int2( 75, -1021 ),
new int2( 50, -1022 ),
new int2( 25, -1023 ),
new int2( 0, -1024 ),
new int2( -25, -1023 ),
new int2( -50, -1022 ),
new int2( -75, -1021 ),
new int2( -100, -1019 ),
new int2( -125, -1016 ),
new int2( -150, -1012 ),
new int2( -175, -1008 ),
new int2( -199, -1004 ),
new int2( -224, -999 ),
new int2( -248, -993 ),
new int2( -273, -986 ),
new int2( -297, -979 ),
new int2( -321, -972 ),
new int2( -344, -964 ),
new int2( -368, -955 ),
new int2( -391, -946 ),
new int2( -414, -936 ),
new int2( -437, -925 ),
new int2( -460, -914 ),
new int2( -482, -903 ),
new int2( -504, -890 ),
new int2( -526, -878 ),
new int2( -547, -865 ),
new int2( -568, -851 ),
new int2( -589, -837 ),
new int2( -609, -822 ),
new int2( -629, -807 ),
new int2( -649, -791 ),
new int2( -668, -775 ),
new int2( -687, -758 ),
new int2( -706, -741 ),
new int2( -724, -724 ),
new int2( -741, -706 ),
new int2( -758, -687 ),
new int2( -775, -668 ),
new int2( -791, -649 ),
new int2( -807, -629 ),
new int2( -822, -609 ),
new int2( -837, -589 ),
new int2( -851, -568 ),
new int2( -865, -547 ),
new int2( -878, -526 ),
new int2( -890, -504 ),
new int2( -903, -482 ),
new int2( -914, -460 ),
new int2( -925, -437 ),
new int2( -936, -414 ),
new int2( -946, -391 ),
new int2( -955, -368 ),
new int2( -964, -344 ),
new int2( -972, -321 ),
new int2( -979, -297 ),
new int2( -986, -273 ),
new int2( -993, -248 ),
new int2( -999, -224 ),
new int2( -1004, -199 ),
new int2( -1008, -175 ),
new int2( -1012, -150 ),
new int2( -1016, -125 ),
new int2( -1019, -100 ),
new int2( -1021, -75 ),
new int2( -1022, -50 ),
new int2( -1023, -25 ),
new int2( -1024, 0 ),
new int2( -1023, 25 ),
new int2( -1022, 50 ),
new int2( -1021, 75 ),
new int2( -1019, 100 ),
new int2( -1016, 125 ),
new int2( -1012, 150 ),
new int2( -1008, 175 ),
new int2( -1004, 199 ),
new int2( -999, 224 ),
new int2( -993, 248 ),
new int2( -986, 273 ),
new int2( -979, 297 ),
new int2( -972, 321 ),
new int2( -964, 344 ),
new int2( -955, 368 ),
new int2( -946, 391 ),
new int2( -936, 414 ),
new int2( -925, 437 ),
new int2( -914, 460 ),
new int2( -903, 482 ),
new int2( -890, 504 ),
new int2( -878, 526 ),
new int2( -865, 547 ),
new int2( -851, 568 ),
new int2( -837, 589 ),
new int2( -822, 609 ),
new int2( -807, 629 ),
new int2( -791, 649 ),
new int2( -775, 668 ),
new int2( -758, 687 ),
new int2( -741, 706 ),
new int2( -724, 724 ),
new int2( -706, 741 ),
new int2( -687, 758 ),
new int2( -668, 775 ),
new int2( -649, 791 ),
new int2( -629, 807 ),
new int2( -609, 822 ),
new int2( -589, 837 ),
new int2( -568, 851 ),
new int2( -547, 865 ),
new int2( -526, 878 ),
new int2( -504, 890 ),
new int2( -482, 903 ),
new int2( -460, 914 ),
new int2( -437, 925 ),
new int2( -414, 936 ),
new int2( -391, 946 ),
new int2( -368, 955 ),
new int2( -344, 964 ),
new int2( -321, 972 ),
new int2( -297, 979 ),
new int2( -273, 986 ),
new int2( -248, 993 ),
new int2( -224, 999 ),
new int2( -199, 1004 ),
new int2( -175, 1008 ),
new int2( -150, 1012 ),
new int2( -125, 1016 ),
new int2( -100, 1019 ),
new int2( -75, 1021 ),
new int2( -50, 1022 ),
new int2( -25, 1023 )
new PSubVec( 0, 1024 ),
new PSubVec( 25, 1023 ),
new PSubVec( 50, 1022 ),
new PSubVec( 75, 1021 ),
new PSubVec( 100, 1019 ),
new PSubVec( 125, 1016 ),
new PSubVec( 150, 1012 ),
new PSubVec( 175, 1008 ),
new PSubVec( 199, 1004 ),
new PSubVec( 224, 999 ),
new PSubVec( 248, 993 ),
new PSubVec( 273, 986 ),
new PSubVec( 297, 979 ),
new PSubVec( 321, 972 ),
new PSubVec( 344, 964 ),
new PSubVec( 368, 955 ),
new PSubVec( 391, 946 ),
new PSubVec( 414, 936 ),
new PSubVec( 437, 925 ),
new PSubVec( 460, 914 ),
new PSubVec( 482, 903 ),
new PSubVec( 504, 890 ),
new PSubVec( 526, 878 ),
new PSubVec( 547, 865 ),
new PSubVec( 568, 851 ),
new PSubVec( 589, 837 ),
new PSubVec( 609, 822 ),
new PSubVec( 629, 807 ),
new PSubVec( 649, 791 ),
new PSubVec( 668, 775 ),
new PSubVec( 687, 758 ),
new PSubVec( 706, 741 ),
new PSubVec( 724, 724 ),
new PSubVec( 741, 706 ),
new PSubVec( 758, 687 ),
new PSubVec( 775, 668 ),
new PSubVec( 791, 649 ),
new PSubVec( 807, 629 ),
new PSubVec( 822, 609 ),
new PSubVec( 837, 589 ),
new PSubVec( 851, 568 ),
new PSubVec( 865, 547 ),
new PSubVec( 878, 526 ),
new PSubVec( 890, 504 ),
new PSubVec( 903, 482 ),
new PSubVec( 914, 460 ),
new PSubVec( 925, 437 ),
new PSubVec( 936, 414 ),
new PSubVec( 946, 391 ),
new PSubVec( 955, 368 ),
new PSubVec( 964, 344 ),
new PSubVec( 972, 321 ),
new PSubVec( 979, 297 ),
new PSubVec( 986, 273 ),
new PSubVec( 993, 248 ),
new PSubVec( 999, 224 ),
new PSubVec( 1004, 199 ),
new PSubVec( 1008, 175 ),
new PSubVec( 1012, 150 ),
new PSubVec( 1016, 125 ),
new PSubVec( 1019, 100 ),
new PSubVec( 1021, 75 ),
new PSubVec( 1022, 50 ),
new PSubVec( 1023, 25 ),
new PSubVec( 1024, 0 ),
new PSubVec( 1023, -25 ),
new PSubVec( 1022, -50 ),
new PSubVec( 1021, -75 ),
new PSubVec( 1019, -100 ),
new PSubVec( 1016, -125 ),
new PSubVec( 1012, -150 ),
new PSubVec( 1008, -175 ),
new PSubVec( 1004, -199 ),
new PSubVec( 999, -224 ),
new PSubVec( 993, -248 ),
new PSubVec( 986, -273 ),
new PSubVec( 979, -297 ),
new PSubVec( 972, -321 ),
new PSubVec( 964, -344 ),
new PSubVec( 955, -368 ),
new PSubVec( 946, -391 ),
new PSubVec( 936, -414 ),
new PSubVec( 925, -437 ),
new PSubVec( 914, -460 ),
new PSubVec( 903, -482 ),
new PSubVec( 890, -504 ),
new PSubVec( 878, -526 ),
new PSubVec( 865, -547 ),
new PSubVec( 851, -568 ),
new PSubVec( 837, -589 ),
new PSubVec( 822, -609 ),
new PSubVec( 807, -629 ),
new PSubVec( 791, -649 ),
new PSubVec( 775, -668 ),
new PSubVec( 758, -687 ),
new PSubVec( 741, -706 ),
new PSubVec( 724, -724 ),
new PSubVec( 706, -741 ),
new PSubVec( 687, -758 ),
new PSubVec( 668, -775 ),
new PSubVec( 649, -791 ),
new PSubVec( 629, -807 ),
new PSubVec( 609, -822 ),
new PSubVec( 589, -837 ),
new PSubVec( 568, -851 ),
new PSubVec( 547, -865 ),
new PSubVec( 526, -878 ),
new PSubVec( 504, -890 ),
new PSubVec( 482, -903 ),
new PSubVec( 460, -914 ),
new PSubVec( 437, -925 ),
new PSubVec( 414, -936 ),
new PSubVec( 391, -946 ),
new PSubVec( 368, -955 ),
new PSubVec( 344, -964 ),
new PSubVec( 321, -972 ),
new PSubVec( 297, -979 ),
new PSubVec( 273, -986 ),
new PSubVec( 248, -993 ),
new PSubVec( 224, -999 ),
new PSubVec( 199, -1004 ),
new PSubVec( 175, -1008 ),
new PSubVec( 150, -1012 ),
new PSubVec( 125, -1016 ),
new PSubVec( 100, -1019 ),
new PSubVec( 75, -1021 ),
new PSubVec( 50, -1022 ),
new PSubVec( 25, -1023 ),
new PSubVec( 0, -1024 ),
new PSubVec( -25, -1023 ),
new PSubVec( -50, -1022 ),
new PSubVec( -75, -1021 ),
new PSubVec( -100, -1019 ),
new PSubVec( -125, -1016 ),
new PSubVec( -150, -1012 ),
new PSubVec( -175, -1008 ),
new PSubVec( -199, -1004 ),
new PSubVec( -224, -999 ),
new PSubVec( -248, -993 ),
new PSubVec( -273, -986 ),
new PSubVec( -297, -979 ),
new PSubVec( -321, -972 ),
new PSubVec( -344, -964 ),
new PSubVec( -368, -955 ),
new PSubVec( -391, -946 ),
new PSubVec( -414, -936 ),
new PSubVec( -437, -925 ),
new PSubVec( -460, -914 ),
new PSubVec( -482, -903 ),
new PSubVec( -504, -890 ),
new PSubVec( -526, -878 ),
new PSubVec( -547, -865 ),
new PSubVec( -568, -851 ),
new PSubVec( -589, -837 ),
new PSubVec( -609, -822 ),
new PSubVec( -629, -807 ),
new PSubVec( -649, -791 ),
new PSubVec( -668, -775 ),
new PSubVec( -687, -758 ),
new PSubVec( -706, -741 ),
new PSubVec( -724, -724 ),
new PSubVec( -741, -706 ),
new PSubVec( -758, -687 ),
new PSubVec( -775, -668 ),
new PSubVec( -791, -649 ),
new PSubVec( -807, -629 ),
new PSubVec( -822, -609 ),
new PSubVec( -837, -589 ),
new PSubVec( -851, -568 ),
new PSubVec( -865, -547 ),
new PSubVec( -878, -526 ),
new PSubVec( -890, -504 ),
new PSubVec( -903, -482 ),
new PSubVec( -914, -460 ),
new PSubVec( -925, -437 ),
new PSubVec( -936, -414 ),
new PSubVec( -946, -391 ),
new PSubVec( -955, -368 ),
new PSubVec( -964, -344 ),
new PSubVec( -972, -321 ),
new PSubVec( -979, -297 ),
new PSubVec( -986, -273 ),
new PSubVec( -993, -248 ),
new PSubVec( -999, -224 ),
new PSubVec( -1004, -199 ),
new PSubVec( -1008, -175 ),
new PSubVec( -1012, -150 ),
new PSubVec( -1016, -125 ),
new PSubVec( -1019, -100 ),
new PSubVec( -1021, -75 ),
new PSubVec( -1022, -50 ),
new PSubVec( -1023, -25 ),
new PSubVec( -1024, 0 ),
new PSubVec( -1023, 25 ),
new PSubVec( -1022, 50 ),
new PSubVec( -1021, 75 ),
new PSubVec( -1019, 100 ),
new PSubVec( -1016, 125 ),
new PSubVec( -1012, 150 ),
new PSubVec( -1008, 175 ),
new PSubVec( -1004, 199 ),
new PSubVec( -999, 224 ),
new PSubVec( -993, 248 ),
new PSubVec( -986, 273 ),
new PSubVec( -979, 297 ),
new PSubVec( -972, 321 ),
new PSubVec( -964, 344 ),
new PSubVec( -955, 368 ),
new PSubVec( -946, 391 ),
new PSubVec( -936, 414 ),
new PSubVec( -925, 437 ),
new PSubVec( -914, 460 ),
new PSubVec( -903, 482 ),
new PSubVec( -890, 504 ),
new PSubVec( -878, 526 ),
new PSubVec( -865, 547 ),
new PSubVec( -851, 568 ),
new PSubVec( -837, 589 ),
new PSubVec( -822, 609 ),
new PSubVec( -807, 629 ),
new PSubVec( -791, 649 ),
new PSubVec( -775, 668 ),
new PSubVec( -758, 687 ),
new PSubVec( -741, 706 ),
new PSubVec( -724, 724 ),
new PSubVec( -706, 741 ),
new PSubVec( -687, 758 ),
new PSubVec( -668, 775 ),
new PSubVec( -649, 791 ),
new PSubVec( -629, 807 ),
new PSubVec( -609, 822 ),
new PSubVec( -589, 837 ),
new PSubVec( -568, 851 ),
new PSubVec( -547, 865 ),
new PSubVec( -526, 878 ),
new PSubVec( -504, 890 ),
new PSubVec( -482, 903 ),
new PSubVec( -460, 914 ),
new PSubVec( -437, 925 ),
new PSubVec( -414, 936 ),
new PSubVec( -391, 946 ),
new PSubVec( -368, 955 ),
new PSubVec( -344, 964 ),
new PSubVec( -321, 972 ),
new PSubVec( -297, 979 ),
new PSubVec( -273, 986 ),
new PSubVec( -248, 993 ),
new PSubVec( -224, 999 ),
new PSubVec( -199, 1004 ),
new PSubVec( -175, 1008 ),
new PSubVec( -150, 1012 ),
new PSubVec( -125, 1016 ),
new PSubVec( -100, 1019 ),
new PSubVec( -75, 1021 ),
new PSubVec( -50, 1022 ),
new PSubVec( -25, 1023 )
};
}
}

View File

@@ -107,8 +107,8 @@ namespace OpenRA.Mods.RA.Air
[Sync]
public int Altitude { get; set; }
[Sync]
public int2 SubPxPosition;
public PPos PxPosition { get { return new PPos( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } }
public PSubPos SubPxPosition;
public PPos PxPosition { get { return SubPxPosition.ToPPos(); } }
public CPos TopLeft { get { return PxPosition.ToCPos(); } }
readonly AircraftInfo Info;
@@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Air
{
this.self = init.self;
if( init.Contains<LocationInit>() )
this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get<LocationInit, CPos>() ).ToInt2();
this.SubPxPosition = Util.CenterOfCell( init.Get<LocationInit, CPos>() ).ToPSubPos();
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA.Air
public void SetPxPosition( Actor self, PPos px )
{
SubPxPosition = px.ToInt2() * 1024;
SubPxPosition = px.ToPSubPos();
}
public void AdjustPxPosition(Actor self, PPos px) { SetPxPosition(self, px); }
@@ -188,7 +188,7 @@ namespace OpenRA.Mods.RA.Air
public void TickMove( int speed, int facing )
{
var rawspeed = speed * 7 / (32 * 1024);
var rawspeed = speed * 7 / (32 * PSubPos.PerPx);
SubPxPosition += rawspeed * -Util.SubPxVector[facing];
}

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Air
public static void Fly(Actor self, int desiredAltitude )
{
var aircraft = self.Trait<Aircraft>();
aircraft.TickMove( 1024 * aircraft.MovementSpeed, aircraft.Facing );
aircraft.TickMove( PSubPos.PerPx * aircraft.MovementSpeed, aircraft.Facing );
aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude);
}
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Air
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
if( !float2.WithinEpsilon( float2.Zero, dist.ToFloat2(), range * Game.CellSize ) )
aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );
aircraft.TickMove(PSubPos.PerPx * aircraft.MovementSpeed, desiredFacing);
attack.DoAttack( self, target );

View File

@@ -38,13 +38,13 @@ namespace OpenRA.Mods.RA.Air
var dist = Dest - aircraft.PxPosition;
if (float2.WithinEpsilon(float2.Zero, dist.ToFloat2(), 2))
{
aircraft.SubPxPosition = (Dest.ToInt2() * 1024);
aircraft.SubPxPosition = Dest.ToPSubPos();
return NextActivity;
}
var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing );
aircraft.TickMove( PSubPos.PerPx * aircraft.MovementSpeed, desiredFacing );
return this;
}

View File

@@ -116,28 +116,29 @@ namespace OpenRA.Mods.RA.Air
var f = otherHelis
.Select(h => GetRepulseForce(self, h))
.Aggregate(int2.Zero, (a, b) => a + b);
.Aggregate(PSubVec.Zero, (a, b) => a + b);
int repulsionFacing = Util.GetFacing( f, -1 );
// FIXME(jsd): not sure which units GetFacing accepts; code is unclear to me.
int repulsionFacing = Util.GetFacing( f.ToInt2(), -1 );
if( repulsionFacing != -1 )
TickMove( 1024 * MovementSpeed, repulsionFacing );
TickMove(PSubPos.PerPx * MovementSpeed, repulsionFacing);
}
// Returns an int2 in subPx units
public int2 GetRepulseForce(Actor self, Actor h)
// Returns a vector in subPx units
public PSubVec GetRepulseForce(Actor self, Actor h)
{
if (self == h)
return int2.Zero;
return PSubVec.Zero;
if( h.Trait<Helicopter>().Altitude < Altitude )
return int2.Zero;
return PSubVec.Zero;
var d = self.CenterLocation - h.CenterLocation;
if (d.Length > Info.IdealSeparation)
return int2.Zero;
return PSubVec.Zero;
if (d.LengthSquared < 1)
return Util.SubPxVector[self.World.SharedRandom.Next(255)];
return (5120 / d.LengthSquared) * d.ToInt2();
return (5 * d.ToPSubVec()) / d.LengthSquared;
}
}
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Air
var desiredFacing = Util.GetFacing(d, aircraft.Facing);
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
aircraft.TickMove( 1024 * aircraft.MovementSpeed, aircraft.Facing );
aircraft.TickMove(PSubPos.PerPx * aircraft.MovementSpeed, aircraft.Facing);
return this;
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
public void TickIdle(Actor self)
{
var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024) + self.Location;
var target = (Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius).ToPVecInt().ToCVec() + self.Location;
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = target });
}
}

View File

@@ -47,8 +47,8 @@ namespace OpenRA.Mods.RA.Effects
readonly ProjectileArgs Args;
PVecInt offset;
public int2 SubPxPosition;
public PPos PxPosition { get { return new PPos(SubPxPosition.X / 1024, SubPxPosition.Y / 1024); } }
public PSubPos SubPxPosition;
public PPos PxPosition { get { return SubPxPosition.ToPPos(); } }
readonly Animation anim;
int Facing;
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA.Effects
Info = info;
Args = args;
SubPxPosition = 1024 * Args.src.ToInt2();
SubPxPosition = Args.src.ToPSubPos();
Altitude = Args.srcAltitude;
Facing = Args.facing;
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.RA.Effects
Explode(world);
// TODO: Replace this with a lookup table
var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))*1024).ToInt2();
var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))).ToPSubVec();
var move = Info.Speed * dir;
if (targetAltitude > 0 && Info.TurboBoost)
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Effects
if (Info.Trail != null)
{
var sp = (PPos)((SubPxPosition - (move * 3) / 2) / 1024) - new PVecInt(0, Altitude);
var sp = ((SubPxPosition - (move * 3) / 2)).ToPPos() - new PVecInt(0, Altitude);
if (--ticksToNextSmoke < 0)
{

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
{
if (!Panicked) return;
var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024 ) + self.Location;
var target = ( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius ).ToPVecInt().ToCVec() + self.Location;
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
}