From b16ebd480bf642e6534d941f86f6e2559ef622a6 Mon Sep 17 00:00:00 2001 From: Pavel Penev Date: Thu, 1 Oct 2015 01:00:29 +0300 Subject: [PATCH] Rename MapGridType.Diamond to MapGridType.RectangularIsometric --- OpenRA.Game/CPos.cs | 2 +- OpenRA.Game/Graphics/Minimap.cs | 10 +++++----- OpenRA.Game/Graphics/Viewport.cs | 10 ++++------ OpenRA.Game/MPos.cs | 2 +- OpenRA.Game/Map/CellLayer.cs | 4 ++-- OpenRA.Game/Map/Map.cs | 20 +++++++++---------- OpenRA.Game/Map/MapCache.cs | 2 +- OpenRA.Game/Map/MapGrid.cs | 2 +- OpenRA.Game/Map/ProjectedCellRegion.cs | 4 ++-- .../Widgets/MapPreviewWidget.cs | 2 +- OpenRA.Mods.Common/Widgets/RadarWidget.cs | 16 +++++++-------- OpenRA.Test/OpenRA.Game/CoordinateTest.cs | 2 +- mods/ts/mod.yaml | 2 +- 13 files changed, 38 insertions(+), 40 deletions(-) diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 9377121eb3..eb23b4f60c 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -52,7 +52,7 @@ namespace OpenRA if (gridType == MapGridType.Rectangular) return new MPos(X, Y); - // Convert from diamond cell (x, y) position to rectangular map position (u, v) + // Convert from RectangularIsometric cell (x, y) position to rectangular map position (u, v) // - The staggered rows make this fiddly (hint: draw a diagram!) // (a) Consider the relationships: // - +1x (even -> odd) adds (0, 1) to (u, v) diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index f446f2ac14..17a310dfb5 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -20,7 +20,7 @@ namespace OpenRA.Graphics { public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false) { - var isDiamond = map.Grid.Type == MapGridType.Diamond; + var isRectangularIsometric = map.Grid.Type == MapGridType.RectangularIsometric; var b = map.Bounds; // Fudge the heightmap offset by adding as much extra as we need / can. @@ -30,7 +30,7 @@ namespace OpenRA.Graphics var height = b.Height + heightOffset; var bitmapWidth = width; - if (isDiamond) + if (isRectangularIsometric) bitmapWidth = 2 * bitmapWidth - 1; if (!actualSize) @@ -55,7 +55,7 @@ namespace OpenRA.Graphics var type = tileset.GetTileInfo(mapTiles[uv]); var leftColor = type != null ? type.LeftColor : Color.Black; - if (isDiamond) + if (isRectangularIsometric) { // Odd rows are shifted right by 1px var dx = uv.V & 1; @@ -81,7 +81,7 @@ namespace OpenRA.Graphics static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap) { var terrain = new Bitmap(terrainBitmap); - var isDiamond = map.Grid.Type == MapGridType.Diamond; + var isRectangularIsometric = map.Grid.Type == MapGridType.RectangularIsometric; var b = map.Bounds; // Fudge the heightmap offset by adding as much extra as we need / can @@ -113,7 +113,7 @@ namespace OpenRA.Graphics continue; var color = tileset[tileset.GetTerrainIndex(res)].Color.ToArgb(); - if (isDiamond) + if (isRectangularIsometric) { // Odd rows are shifted right by 1px var dx = uv.V & 1; diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 08b4652506..98d6466f03 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -9,7 +9,6 @@ #endregion using System; -using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -100,7 +99,7 @@ namespace OpenRA.Graphics // The full map is visible in the editor var width = map.MapSize.X * grid.TileSize.Width; var height = map.MapSize.Y * grid.TileSize.Height; - if (wr.World.Map.Grid.Type == MapGridType.Diamond) + if (wr.World.Map.Grid.Type == MapGridType.RectangularIsometric) height /= 2; mapBounds = new Rectangle(0, 0, width, height); @@ -240,10 +239,9 @@ namespace OpenRA.Graphics var tl = (PPos)map.CellContaining(worldRenderer.ProjectedPosition(TopLeft)).ToMPos(map); var br = (PPos)map.CellContaining(worldRenderer.ProjectedPosition(BottomRight)).ToMPos(map); - // Diamond tile shapes don't have straight edges, and so we need - // an additional cell margin to include the cells that are half - // visible on each edge. - if (map.Grid.Type == MapGridType.Diamond) + // RectangularIsometric maps don't have straight edges, and so we need an additional + // cell margin to include the cells that are half visible on each edge. + if (map.Grid.Type == MapGridType.RectangularIsometric) { tl = new PPos(tl.U - 1, tl.V - 1); br = new PPos(br.U + 1, br.V + 1); diff --git a/OpenRA.Game/MPos.cs b/OpenRA.Game/MPos.cs index 7ec7e7c519..b678628bed 100644 --- a/OpenRA.Game/MPos.cs +++ b/OpenRA.Game/MPos.cs @@ -46,7 +46,7 @@ namespace OpenRA if (gridType == MapGridType.Rectangular) return new CPos(U, V); - // Convert from rectangular map position to diamond cell position + // Convert from rectangular map position to RectangularIsometric cell position // - The staggered rows make this fiddly (hint: draw a diagram!) // (a) Consider the relationships: // - +1u (even -> odd) adds (1, -1) to (x, y) diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index 4982a01f5b..e9267b46d9 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -128,9 +128,9 @@ namespace OpenRA public bool Contains(CPos cell) { // .ToMPos() returns the same result if the X and Y coordinates - // are switched. X < Y is invalid in the Diamond coordinate system, + // are switched. X < Y is invalid in the RectangularIsometric coordinate system, // so we pre-filter these to avoid returning the wrong result - if (GridType == MapGridType.Diamond && cell.X < cell.Y) + if (GridType == MapGridType.RectangularIsometric && cell.X < cell.Y) return false; return Contains(cell.ToMPos(GridType)); diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 74bb9364e3..13822d6a0f 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -426,10 +426,10 @@ namespace OpenRA foreach (var uv in AllCells.MapCoords) CustomTerrain[uv] = byte.MaxValue; - var leftDelta = Grid.Type == MapGridType.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0); - var topDelta = Grid.Type == MapGridType.Diamond ? new WVec(0, -512, 0) : new WVec(512, -512, 0); - var rightDelta = Grid.Type == MapGridType.Diamond ? new WVec(512, 0, 0) : new WVec(512, 512, 0); - var bottomDelta = Grid.Type == MapGridType.Diamond ? new WVec(0, 512, 0) : new WVec(-512, 512, 0); + var leftDelta = Grid.Type == MapGridType.RectangularIsometric ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0); + var topDelta = Grid.Type == MapGridType.RectangularIsometric ? new WVec(0, -512, 0) : new WVec(512, -512, 0); + var rightDelta = Grid.Type == MapGridType.RectangularIsometric ? new WVec(512, 0, 0) : new WVec(512, 512, 0); + var bottomDelta = Grid.Type == MapGridType.RectangularIsometric ? new WVec(0, 512, 0) : new WVec(-512, 512, 0); CellCorners = CellCornerHalfHeights.Select(ramp => new WVec[] { leftDelta + new WVec(0, 0, 512 * ramp[0]), @@ -752,9 +752,9 @@ namespace OpenRA public bool Contains(CPos cell) { // .ToMPos() returns the same result if the X and Y coordinates - // are switched. X < Y is invalid in the Diamond coordinate system, + // are switched. X < Y is invalid in the RectangularIsometric coordinate system, // so we pre-filter these to avoid returning the wrong result - if (Grid.Type == MapGridType.Diamond && cell.X < cell.Y) + if (Grid.Type == MapGridType.RectangularIsometric && cell.X < cell.Y) return false; return Contains(cell.ToMPos(this)); @@ -789,7 +789,7 @@ namespace OpenRA if (Grid.Type == MapGridType.Rectangular) return new WPos(1024 * cell.X + 512, 1024 * cell.Y + 512, 0); - // Convert from diamond cell position (x, y) to world position (u, v): + // Convert from isometric cell position (x, y) to world position (u, v): // (a) Consider the relationships: // - Center of origin cell is (512, 512) // - +x adds (512, 512) to world pos @@ -821,7 +821,7 @@ namespace OpenRA if (Grid.Type == MapGridType.Rectangular) return new CPos(pos.X / 1024, pos.Y / 1024); - // Convert from world position to diamond cell position: + // Convert from world position to isometric cell position: // (a) Subtract (512, 512) to move the rotation center to the middle of the corner cell // (b) Rotate axes by -pi/4 // (c) Divide through by sqrt(2) to bring us to an equivalent world pos aligned with u,v axes @@ -896,10 +896,10 @@ namespace OpenRA // Directly calculate the projected map corners in world units avoiding unnecessary // conversions. This abuses the definition that the width of the cell is always // 1024 units, and that the height of two rows is 2048 for classic cells and 1024 - // for diamond cells. + // for isometric cells. var wtop = tl.V * 1024; var wbottom = (br.V + 1) * 1024; - if (Grid.Type == MapGridType.Diamond) + if (Grid.Type == MapGridType.RectangularIsometric) { wtop /= 2; wbottom /= 2; diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 02b141e998..da0eace73c 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -23,7 +23,7 @@ namespace OpenRA { public sealed class MapCache : IEnumerable, IDisposable { - public static readonly MapPreview UnknownMap = new MapPreview(null, MapGridType.Rectangle, null); + public static readonly MapPreview UnknownMap = new MapPreview(null, MapGridType.Rectangular, null); readonly Cache previews; readonly ModData modData; readonly SheetBuilder sheetBuilder; diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index 2e879d6994..04abfb17c2 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -13,7 +13,7 @@ using System.IO; namespace OpenRA { - public enum MapGridType { Rectangular, Diamond } + public enum MapGridType { Rectangular, RectangularIsometric } public class MapGrid : IGlobalModData { diff --git a/OpenRA.Game/Map/ProjectedCellRegion.cs b/OpenRA.Game/Map/ProjectedCellRegion.cs index c40ba94c98..878c1e97be 100644 --- a/OpenRA.Game/Map/ProjectedCellRegion.cs +++ b/OpenRA.Game/Map/ProjectedCellRegion.cs @@ -39,9 +39,9 @@ namespace OpenRA // The bottom edge is trickier: cells at MPos.V > bottomRight.V may have // been projected into this region if they have height > 0. // Each height step is equivalent to 512 WRange units, which is one MPos - // step for diamond cells, but only half a MPos step for classic cells. Doh! + // step for isometric cells, but only half a MPos step for classic cells. Doh! var maxHeight = map.Grid.MaximumTerrainHeight; - var heightOffset = map.Grid.Type == MapGridType.Diamond ? maxHeight : maxHeight / 2; + var heightOffset = map.Grid.Type == MapGridType.RectangularIsometric ? maxHeight : maxHeight / 2; // Use the MapHeight data array to clamp the bottom coordinate so it doesn't overflow the map mapBottomRight = map.MapHeight.Value.Clamp(new MPos(bottomRight.U, bottomRight.V + heightOffset)); diff --git a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs index fe77fe1422..aa3bb996f4 100644 --- a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs @@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets { var preview = Preview(); var point = cell.ToMPos(gridType); - var cellWidth = gridType == MapGridType.Diamond ? 2 : 1; + var cellWidth = gridType == MapGridType.RectangularIsometric ? 2 : 1; var dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left)); var dy = (int)(previewScale * (point.V - preview.Bounds.Top)); diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index 9d4c19aaf6..99c1164f7a 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets readonly World world; readonly WorldRenderer worldRenderer; readonly RadarPings radarPings; - readonly bool isDiamond; + readonly bool isRectangularIsometric; readonly int cellWidth; readonly int previewWidth; readonly int previewHeight; @@ -64,11 +64,11 @@ namespace OpenRA.Mods.Common.Widgets this.worldRenderer = worldRenderer; radarPings = world.WorldActor.TraitOrDefault(); - isDiamond = world.Map.Grid.Type == MapGridType.Diamond; - cellWidth = isDiamond ? 2 : 1; + isRectangularIsometric = world.Map.Grid.Type == MapGridType.RectangularIsometric; + cellWidth = isRectangularIsometric ? 2 : 1; previewWidth = world.Map.MapSize.X; previewHeight = world.Map.MapSize.Y; - if (isDiamond) + if (isRectangularIsometric) previewWidth = 2 * previewWidth - 1; } @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets fixed (byte* colorBytes = &radarData[0]) { var colors = (int*)colorBytes; - if (isDiamond) + if (isRectangularIsometric) { // Odd rows are shifted right by 1px var dx = uv.V & 1; @@ -189,7 +189,7 @@ namespace OpenRA.Mods.Common.Widgets var colors = (int*)colorBytes; foreach (var uv in world.Map.Unproject(puv)) { - if (isDiamond) + if (isRectangularIsometric) { // Odd rows are shifted right by 1px var dx = uv.V & 1; @@ -381,7 +381,7 @@ namespace OpenRA.Mods.Common.Widgets var uv = cell.First.ToMPos(world.Map.Grid.Type); var color = cell.Second.ToArgb(); - if (isDiamond) + if (isRectangularIsometric) { // Odd rows are shifted right by 1px var dx = uv.V & 1; @@ -430,7 +430,7 @@ namespace OpenRA.Mods.Common.Widgets var dy = (int)(previewScale * (uv.V - world.Map.Bounds.Top)); // Odd rows are shifted right by 1px - if (isDiamond && (uv.V & 1) == 1) + if (isRectangularIsometric && (uv.V & 1) == 1) dx += 1; return new int2(mapRect.X + dx, mapRect.Y + dy); diff --git a/OpenRA.Test/OpenRA.Game/CoordinateTest.cs b/OpenRA.Test/OpenRA.Game/CoordinateTest.cs index 11bfc2eb02..77cc56e84f 100644 --- a/OpenRA.Test/OpenRA.Game/CoordinateTest.cs +++ b/OpenRA.Test/OpenRA.Game/CoordinateTest.cs @@ -34,7 +34,7 @@ namespace OpenRA.Test catch (Exception e) { // Known problem on isometric mods that shouldn't be visible to players as these are outside the map. - if (gridType == MapGridType.Diamond && y > x) + if (gridType == MapGridType.RectangularIsometric && y > x) continue; Console.WriteLine("Coordinate {0} on grid type {1} failed to convert back.".F(cell, gridType)); diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index e90dd9a683..fe85a82a54 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -113,7 +113,7 @@ TileSets: MapGrid: TileSize: 48,24 - Type: Diamond + Type: RectangularIsometric MaximumTerrainHeight: 16 SubCellOffsets: 0,0,0, -256,128,0, 0,-128,0, 256,128,0 SubCellDefaultIndex: 2