Introduce a new type for representing map coordinates.
To resolve the ambiguity introduced when the introduction of isometric maps meant that cell and map coordinates were no longer equivalent, a new type has been introduced so they can each be represented separately.
This commit is contained in:
@@ -334,7 +334,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
defaultCellInfoLayer = new CellLayer<CellInfo>(map);
|
||||
for (var v = 0; v < mapSize.Height; v++)
|
||||
for (var u = 0; u < mapSize.Width; u++)
|
||||
defaultCellInfoLayer[u, v] = new CellInfo(int.MaxValue, Map.MapToCell(map.TileShape, new CPos(u, v)), false);
|
||||
defaultCellInfoLayer[new MPos(u, v)] = new CellInfo(int.MaxValue, new MPos(u, v).ToCPos(map), false);
|
||||
}
|
||||
|
||||
result.CopyValuesFrom(defaultCellInfoLayer);
|
||||
|
||||
@@ -36,12 +36,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var shroudObscured = world.ShroudObscuresTest(wr.Viewport.VisibleCells);
|
||||
foreach (var uv in wr.Viewport.VisibleCells.MapCoords)
|
||||
{
|
||||
if (shroudObscured(uv.X, uv.Y))
|
||||
if (shroudObscured(uv))
|
||||
continue;
|
||||
|
||||
var c = render[uv.X, uv.Y];
|
||||
var c = render[uv];
|
||||
if (c.Sprite != null)
|
||||
new SpriteRenderable(c.Sprite, wr.World.Map.CenterOfCell(Map.MapToCell(world.Map.TileShape, uv)),
|
||||
new SpriteRenderable(c.Sprite, wr.World.Map.CenterOfCell(uv.ToCPos(world.Map)),
|
||||
WVec.Zero, -511, c.Type.Palette, 1f, true).Render(wr); // TODO ZOffset is ignored
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,17 +151,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
notVisibleEdges = info.UseExtendedIndex ? Edges.AllSides : Edges.AllCorners;
|
||||
}
|
||||
|
||||
Edges GetEdges(int u, int v, Func<int, int, bool> isVisible)
|
||||
Edges GetEdges(MPos uv, Func<MPos, bool> isVisible)
|
||||
{
|
||||
if (!isVisible(u, v))
|
||||
if (!isVisible(uv))
|
||||
return notVisibleEdges;
|
||||
|
||||
var cell = Map.MapToCell(map.TileShape, new CPos(u, v));
|
||||
Func<CPos, bool> isCellVisible = c =>
|
||||
{
|
||||
var uv = Map.CellToMap(map.TileShape, c);
|
||||
return isVisible(uv.X, uv.Y);
|
||||
};
|
||||
var cell = uv.ToCPos(map);
|
||||
Func<CPos, bool> isCellVisible = c => isVisible(c.ToMPos(map));
|
||||
|
||||
// If a side is shrouded then we also count the corners
|
||||
var edge = Edges.None;
|
||||
@@ -208,18 +204,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Adds a 1-cell border around the border to cover any sprites peeking outside the map
|
||||
foreach (var uv in CellRegion.Expand(w.Map.Cells, 1).MapCoords)
|
||||
{
|
||||
var u = uv.X;
|
||||
var v = uv.Y;
|
||||
var screen = wr.ScreenPosition(w.Map.CenterOfCell(Map.MapToCell(map.TileShape, uv)));
|
||||
var screen = wr.ScreenPosition(w.Map.CenterOfCell(uv.ToCPos(map)));
|
||||
var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length);
|
||||
tiles[u, v] = new ShroudTile(screen, variant);
|
||||
tiles[uv] = new ShroudTile(screen, variant);
|
||||
|
||||
// Set the cells outside the border so they don't need to be touched again
|
||||
if (!map.Contains(u, v))
|
||||
if (!map.Contains(uv))
|
||||
{
|
||||
var shroudTile = tiles[u, v];
|
||||
var shroudTile = tiles[uv];
|
||||
shroudTile.Shroud = GetTile(shroudSprites, notVisibleEdges, variant);
|
||||
tiles[u, v] = shroudTile;
|
||||
tiles[uv] = shroudTile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,15 +257,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var visibleUnderFog = shroud.IsVisibleTest(updatedRegion);
|
||||
foreach (var uv in updatedRegion.MapCoords)
|
||||
{
|
||||
var u = uv.X;
|
||||
var v = uv.Y;
|
||||
var shrouded = GetEdges(u, v, visibleUnderShroud);
|
||||
var fogged = GetEdges(u, v, visibleUnderFog);
|
||||
var shroudTile = tiles[u, v];
|
||||
var shrouded = GetEdges(uv, visibleUnderShroud);
|
||||
var fogged = GetEdges(uv, visibleUnderFog);
|
||||
var shroudTile = tiles[uv];
|
||||
var variant = shroudTile.Variant;
|
||||
shroudTile.Shroud = GetTile(shroudSprites, shrouded, variant);
|
||||
shroudTile.Fog = GetTile(fogSprites, fogged, variant);
|
||||
tiles[u, v] = shroudTile;
|
||||
tiles[uv] = shroudTile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +286,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var uv in CellRegion.Expand(wr.Viewport.VisibleCells, 1).MapCoords)
|
||||
{
|
||||
var t = tiles[uv.X, uv.Y];
|
||||
var t = tiles[uv];
|
||||
|
||||
if (t.Shroud != null)
|
||||
{
|
||||
|
||||
@@ -84,10 +84,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var uv in wr.Viewport.VisibleCells.MapCoords)
|
||||
{
|
||||
var lr = Game.Renderer.WorldLineRenderer;
|
||||
var pos = wr.World.Map.CenterOfCell(Map.MapToCell(wr.World.Map.TileShape, uv));
|
||||
var pos = wr.World.Map.CenterOfCell(uv.ToCPos(wr.World.Map));
|
||||
|
||||
var height = (int)wr.World.Map.MapHeight.Value[uv.X, uv.Y];
|
||||
var tile = wr.World.Map.MapTiles.Value[uv.X, uv.Y];
|
||||
var height = (int)wr.World.Map.MapHeight.Value[uv];
|
||||
var tile = wr.World.Map.MapTiles.Value[uv];
|
||||
|
||||
TerrainTileInfo tileInfo = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user