Replace WPos.ToCPos -> Map.CellContaining.

This commit is contained in:
Paul Chote
2013-09-17 22:57:30 +12:00
parent 4bc09692e0
commit 9487f49cd5
43 changed files with 81 additions and 83 deletions

View File

@@ -67,13 +67,13 @@ namespace OpenRA.Graphics
// Start of the first line segment is the tail of the list - don't smooth it.
var curPos = trail[idx(next - skip - 1)];
var curCell = curPos.ToCPos();
var curCell = wr.world.Map.CellContaining(curPos);
var curColor = color;
for (var i = 0; i < length - skip - 4; i++)
{
var j = next - skip - i - 2;
var nextPos = Average(trail[idx(j)], trail[idx(j-1)], trail[idx(j-2)], trail[idx(j-3)]);
var nextCell = nextPos.ToCPos();
var nextCell = wr.world.Map.CellContaining(nextPos);
var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent);
if (!world.FogObscures(curCell) && !world.FogObscures(nextCell))

View File

@@ -100,6 +100,11 @@ namespace OpenRA.Graphics
Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
}
public CPos ViewToWorld(int2 view)
{
return worldRenderer.world.Map.CellContaining(worldRenderer.Position(ViewToWorldPx(view)));
}
public int2 ViewToWorldPx(int2 view) { return (1f / Zoom * view.ToFloat2()).ToInt2() + TopLeft; }
public int2 WorldToViewPx(int2 world) { return (Zoom * (world - TopLeft).ToFloat2()).ToInt2(); }
@@ -149,8 +154,8 @@ namespace OpenRA.Graphics
{
// Calculate the intersection of the visible rectangle and the map.
var map = worldRenderer.world.Map;
var tl = map.Clamp(worldRenderer.Position(TopLeft).ToCPos() - new CVec(1, 1));
var br = map.Clamp(worldRenderer.Position(BottomRight).ToCPos());
var tl = map.Clamp(map.CellContaining(worldRenderer.Position(TopLeft)) - new CVec(1, 1));
var br = map.Clamp(map.CellContaining(worldRenderer.Position(BottomRight)));
cells = new CellRegion(tl, br);
cellsDirty = false;