Replace CPos.CenterPosition -> Map.CenterOfCell.
This commit is contained in:
@@ -40,10 +40,6 @@ namespace OpenRA
|
||||
public float2 ToFloat2() { return new float2(X, Y); }
|
||||
public int2 ToInt2() { return new int2(X, Y); }
|
||||
|
||||
public WPos CenterPosition { get { return new WPos(1024 * X + 512, 1024 * Y + 512, 0); } }
|
||||
public WPos TopLeft { get { return new WPos(1024 * X, 1024 * Y, 0); } }
|
||||
public WPos BottomRight { get { return new WPos(1024 * X + 1023, 1024 * Y + 1023, 0); } }
|
||||
|
||||
public CPos Clamp(Rectangle r)
|
||||
{
|
||||
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Graphics
|
||||
foreach (var cell in map.Cells)
|
||||
{
|
||||
var tile = wr.Theater.TileSprite(map.MapTiles.Value[cell]);
|
||||
var pos = wr.ScreenPosition(cell.CenterPosition) - 0.5f * tile.size;
|
||||
var pos = wr.ScreenPosition(map.CenterOfCell(cell)) - 0.5f * tile.size;
|
||||
Util.FastCreateQuad(vertices, pos, tile, terrainPalette, nv, tile.size);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
10
OpenRA.Game/Graphics/Viewport.cs
Executable file → Normal file
10
OpenRA.Game/Graphics/Viewport.cs
Executable file → Normal file
@@ -90,8 +90,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
// Calculate map bounds in world-px
|
||||
var b = map.Bounds;
|
||||
var tl = wr.ScreenPxPosition(new CPos(b.Left, b.Top).TopLeft);
|
||||
var br = wr.ScreenPxPosition(new CPos(b.Right, b.Bottom).BottomRight);
|
||||
|
||||
// Expand to corners of cells
|
||||
var tl = wr.ScreenPxPosition(map.CenterOfCell(new CPos(b.Left, b.Top)) - new WVec(512, 512, 0));
|
||||
var br = wr.ScreenPxPosition(map.CenterOfCell(new CPos(b.Right, b.Bottom)) + new WVec(511, 511, 0));
|
||||
mapBounds = Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
|
||||
|
||||
CenterLocation = (tl + br) / 2;
|
||||
@@ -131,8 +133,8 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
get
|
||||
{
|
||||
var ctl = VisibleCells.TopLeft.TopLeft;
|
||||
var cbr = VisibleCells.BottomRight.BottomRight;
|
||||
var ctl = worldRenderer.world.Map.CenterOfCell(VisibleCells.TopLeft) - new WVec(512, 512, 0);
|
||||
var cbr = worldRenderer.world.Map.CenterOfCell(VisibleCells.BottomRight) + new WVec(511, 511, 0);
|
||||
var tl = WorldToViewPx(worldRenderer.ScreenPxPosition(ctl)).Clamp(ScreenClip);
|
||||
var br = WorldToViewPx(worldRenderer.ScreenPxPosition(cbr)).Clamp(ScreenClip);
|
||||
return Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
|
||||
|
||||
@@ -461,7 +461,15 @@ namespace OpenRA
|
||||
return dataStream.ToArray();
|
||||
}
|
||||
|
||||
public bool Contains(CPos xy) { return Bounds.Contains(xy.X, xy.Y); }
|
||||
public bool Contains(CPos cell)
|
||||
{
|
||||
return Bounds.Contains(cell.X, cell.Y);
|
||||
}
|
||||
|
||||
public WPos CenterOfCell(CPos c)
|
||||
{
|
||||
return new WPos(1024 * c.X + 512, 1024 * c.Y + 512, 0);
|
||||
}
|
||||
|
||||
public void Resize(int width, int height) // editor magic.
|
||||
{
|
||||
@@ -604,8 +612,8 @@ namespace OpenRA
|
||||
|
||||
public WRange DistanceToEdge(WPos pos, WVec dir)
|
||||
{
|
||||
var tl = Bounds.TopLeftAsCPos().TopLeft;
|
||||
var br = Bounds.BottomRightAsCPos().BottomRight;
|
||||
var tl = CenterOfCell(new CPos(Bounds.Left, Bounds.Top)) - new WVec(512, 512, 0);
|
||||
var br = CenterOfCell(new CPos(Bounds.Right, Bounds.Bottom)) + new WVec(511, 511, 0);
|
||||
var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X;
|
||||
var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y;
|
||||
return new WRange(Math.Min(x, y) * dir.Length);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Traits
|
||||
int generation;
|
||||
|
||||
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
|
||||
public static Target FromCell(World w, CPos c) { return new Target { pos = c.CenterPosition, type = TargetType.Terrain }; }
|
||||
public static Target FromCell(World w, CPos c) { return new Target { pos = w.Map.CenterOfCell(c), type = TargetType.Terrain }; }
|
||||
public static Target FromOrder(World w, Order o)
|
||||
{
|
||||
return o.TargetActor != null
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public static WPos BetweenCells(World w, CPos from, CPos to)
|
||||
{
|
||||
return WPos.Lerp(from.CenterPosition, to.CenterPosition, 1, 2);
|
||||
return WPos.Lerp(w.Map.CenterOfCell(from), w.Map.CenterOfCell(to), 1, 2);
|
||||
}
|
||||
|
||||
public static Activity SequenceActivities(params Activity[] acts)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
|
||||
|
||||
var c = render[cell];
|
||||
if (c.Sprite != null)
|
||||
new SpriteRenderable(c.Sprite, cell.CenterPosition,
|
||||
new SpriteRenderable(c.Sprite, wr.world.Map.CenterOfCell(cell),
|
||||
WVec.Zero, -511, c.Type.Palette, 1f, true).Render(wr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +65,13 @@ namespace OpenRA.Traits
|
||||
|
||||
static IEnumerable<CPos> FindVisibleTiles(World world, CPos position, WRange radius)
|
||||
{
|
||||
var map = world.Map;
|
||||
var r = (radius.Range + 1023) / 1024;
|
||||
var limit = radius.Range * radius.Range;
|
||||
var pos = position.CenterPosition;
|
||||
var pos = map.CenterOfCell(position);
|
||||
|
||||
foreach (var cell in world.Map.FindTilesInCircle(position, r))
|
||||
if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit)
|
||||
foreach (var cell in map.FindTilesInCircle(position, r))
|
||||
if ((map.CenterOfCell(cell) - pos).HorizontalLengthSquared <= limit)
|
||||
yield return cell;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user