Introduce initial PPos plumbing.

PPos is best thought of as a cell grid applied in
screen space.  Multiple cells with different
terrain heights may be projected to the same PPos,
or to multiple PPos if they do not align with the
screen grid.

PPos coordinates are used primarily for map edge
checks and shroud / visibility queries.
This commit is contained in:
Paul Chote
2015-06-23 19:41:34 +01:00
parent fb5bcd3889
commit e8794032e0
14 changed files with 381 additions and 63 deletions

View File

@@ -61,4 +61,34 @@ namespace OpenRA
return new CPos(x, y);
}
}
/// <summary>
/// Projected map position
/// </summary>
public struct PPos : IEquatable<PPos>
{
public readonly int U, V;
public PPos(int u, int v) { U = u; V = v; }
public static readonly PPos Zero = new PPos(0, 0);
public static bool operator ==(PPos me, PPos other) { return me.U == other.U && me.V == other.V; }
public static bool operator !=(PPos me, PPos other) { return !(me == other); }
public static explicit operator MPos(PPos puv) { return new MPos(puv.U, puv.V); }
public static explicit operator PPos(MPos uv) { return new PPos(uv.U, uv.V); }
public PPos Clamp(Rectangle r)
{
return new PPos(Math.Min(r.Right, Math.Max(U, r.Left)),
Math.Min(r.Bottom, Math.Max(V, r.Top)));
}
public override int GetHashCode() { return U.GetHashCode() ^ V.GetHashCode(); }
public bool Equals(PPos other) { return other == this; }
public override bool Equals(object obj) { return obj is PPos && Equals((PPos)obj); }
public override string ToString() { return U + "," + V; }
}
}