Remove conversions between legacy and world types.

This commit is contained in:
Paul Chote
2014-04-25 23:55:21 +12:00
parent 9487f49cd5
commit a256e722d5
11 changed files with 26 additions and 31 deletions

View File

@@ -37,9 +37,6 @@ namespace OpenRA
public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static CPos Min(CPos a, CPos b) { return new CPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public CPos Clamp(Rectangle r)
{
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),

View File

@@ -21,13 +21,8 @@ namespace OpenRA
public readonly int X, Y;
public CVec(int x, int y) { X = x; Y = y; }
public CVec(Size p) { X = p.Width; Y = p.Height; }
public static readonly CVec Zero = new CVec(0, 0);
public static explicit operator CVec(int2 a) { return new CVec(a.X, a.Y); }
public static explicit operator CVec(float2 a) { return new CVec((int)a.X, (int)a.Y); }
public static CVec operator +(CVec a, CVec b) { return new CVec(a.X + b.X, a.Y + b.Y); }
public static CVec operator -(CVec a, CVec b) { return new CVec(a.X - b.X, a.Y - b.Y); }
public static CVec operator *(int a, CVec b) { return new CVec(a * b.X, a * b.Y); }
@@ -49,8 +44,6 @@ namespace OpenRA
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 WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); }
public CVec Clamp(Rectangle r)

View File

@@ -57,10 +57,10 @@ namespace OpenRA
public class LocationInit : IActorInit<CPos>
{
[FieldFromYamlKey] public readonly int2 value = int2.Zero;
[FieldFromYamlKey] public readonly CPos value = CPos.Zero;
public LocationInit() { }
public LocationInit(CPos init) { value = init.ToInt2(); }
public CPos Value(World world) { return (CPos)value; }
public LocationInit(CPos init) { value = init; }
public CPos Value(World world) { return value; }
}
public class SubCellInit : IActorInit<SubCell>

View File

@@ -113,11 +113,11 @@ namespace OpenRA
if (TargetActor != null)
w.Write(UIntFromActor(TargetActor));
if (TargetLocation != CPos.Zero)
w.Write(TargetLocation.ToInt2());
w.Write(TargetLocation);
if (TargetString != null)
w.Write(TargetString);
if (ExtraLocation != CPos.Zero)
w.Write(ExtraLocation.ToInt2());
w.Write(ExtraLocation);
if (ExtraData != 0)
w.Write(ExtraData);

View File

@@ -58,5 +58,11 @@ namespace OpenRA.Network
w.Write(p.X);
w.Write(p.Y);
}
public static void Write(this BinaryWriter w, CPos cell)
{
w.Write(cell.X);
w.Write(cell.Y);
}
}
}