Rename MapGridType.Diamond to MapGridType.RectangularIsometric

This commit is contained in:
Pavel Penev
2015-10-01 01:00:29 +03:00
parent 0e417a3cf3
commit b16ebd480b
13 changed files with 38 additions and 40 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)

View File

@@ -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));

View File

@@ -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;

View File

@@ -23,7 +23,7 @@ namespace OpenRA
{
public sealed class MapCache : IEnumerable<MapPreview>, 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<string, MapPreview> previews;
readonly ModData modData;
readonly SheetBuilder sheetBuilder;

View File

@@ -13,7 +13,7 @@ using System.IO;
namespace OpenRA
{
public enum MapGridType { Rectangular, Diamond }
public enum MapGridType { Rectangular, RectangularIsometric }
public class MapGrid : IGlobalModData
{

View File

@@ -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));

View File

@@ -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));

View File

@@ -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<RadarPings>();
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);

View File

@@ -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));

View File

@@ -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