Use CellLayer for terrain.
This commit is contained in:
@@ -37,16 +37,15 @@ namespace OpenRA.Editor
|
||||
for (var u = 0; u < template.Size.X; u++)
|
||||
for (var v = 0; v < template.Size.Y; v++)
|
||||
{
|
||||
if (surface.Map.IsInMap(new CVec(u, v) + pos))
|
||||
var cell = pos + new CVec(u, v);
|
||||
if (surface.Map.IsInMap(cell))
|
||||
{
|
||||
var z = u + v * template.Size.X;
|
||||
if (tile[z].Length > 0)
|
||||
surface.Map.MapTiles.Value[u + pos.X, v + pos.Y] =
|
||||
new TileReference<ushort, byte>
|
||||
{
|
||||
Type = brushTemplate.N,
|
||||
Index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z,
|
||||
};
|
||||
{
|
||||
var index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z;
|
||||
surface.Map.MapTiles.Value[cell] = new TerrainTile(brushTemplate.N, index);
|
||||
}
|
||||
|
||||
var ch = new int2((pos.X + u) / Surface.ChunkSize, (pos.Y + v) / Surface.ChunkSize);
|
||||
if (surface.Chunks.ContainsKey(ch))
|
||||
@@ -70,7 +69,7 @@ namespace OpenRA.Editor
|
||||
void FloodFillWithBrush(Surface s, CPos pos)
|
||||
{
|
||||
var queue = new Queue<CPos>();
|
||||
var replace = s.Map.MapTiles.Value[pos.X, pos.Y];
|
||||
var replace = s.Map.MapTiles.Value[pos];
|
||||
var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];
|
||||
|
||||
Action<int, int> maybeEnqueue = (x, y) =>
|
||||
@@ -87,7 +86,7 @@ namespace OpenRA.Editor
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var p = queue.Dequeue();
|
||||
if (s.Map.MapTiles.Value[p.X, p.Y].Type != replace.Type)
|
||||
if (s.Map.MapTiles.Value[p].Type != replace.Type)
|
||||
continue;
|
||||
|
||||
var a = FindEdge(s, p, new CVec(-1, 0), replace);
|
||||
@@ -95,10 +94,10 @@ namespace OpenRA.Editor
|
||||
|
||||
for (var x = a.X; x <= b.X; x++)
|
||||
{
|
||||
s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { Type = brushTemplate.N, Index = (byte)0 };
|
||||
if (s.Map.MapTiles.Value[x, p.Y - 1].Type == replace.Type)
|
||||
s.Map.MapTiles.Value[new CPos(x, p.Y)] = new TerrainTile(brushTemplate.N, (byte)0);
|
||||
if (s.Map.MapTiles.Value[new CPos(x, p.Y - 1)].Type == replace.Type)
|
||||
maybeEnqueue(x, p.Y - 1);
|
||||
if (s.Map.MapTiles.Value[x, p.Y + 1].Type == replace.Type)
|
||||
if (s.Map.MapTiles.Value[new CPos(x, p.Y + 1)].Type == replace.Type)
|
||||
maybeEnqueue(x, p.Y + 1);
|
||||
}
|
||||
}
|
||||
@@ -108,13 +107,13 @@ namespace OpenRA.Editor
|
||||
s.Chunks.Clear();
|
||||
}
|
||||
|
||||
static CPos FindEdge(Surface s, CPos p, CVec d, TileReference<ushort, byte> replace)
|
||||
static CPos FindEdge(Surface s, CPos p, CVec d, TerrainTile replace)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
var q = p + d;
|
||||
if (!s.Map.IsInMap(q)) return p;
|
||||
if (s.Map.MapTiles.Value[q.X, q.Y].Type != replace.Type) return p;
|
||||
if (s.Map.MapTiles.Value[q].Type != replace.Type) return p;
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Editor
|
||||
public bool ShowRuler;
|
||||
|
||||
public bool IsPaste { get { return TileSelection != null && ResourceSelection != null; } }
|
||||
public TileReference<ushort, byte>[,] TileSelection;
|
||||
public TerrainTile[,] TileSelection;
|
||||
public ResourceTile[,] ResourceSelection;
|
||||
public CPos SelectionStart;
|
||||
public CPos SelectionEnd;
|
||||
@@ -272,7 +272,7 @@ namespace OpenRA.Editor
|
||||
for (var j = 0; j < ChunkSize; j++)
|
||||
{
|
||||
var cell = new CPos(u * ChunkSize + i, v * ChunkSize + j);
|
||||
var tr = Map.MapTiles.Value[u * ChunkSize + i, v * ChunkSize + j];
|
||||
var tr = Map.MapTiles.Value[cell];
|
||||
var tile = TileSetRenderer.Data(tr.Type);
|
||||
var index = (tr.Index < tile.Count) ? tr.Index : (byte)0;
|
||||
var rawImage = tile[index];
|
||||
@@ -509,7 +509,7 @@ namespace OpenRA.Editor
|
||||
var width = Math.Abs((start - end).X);
|
||||
var height = Math.Abs((start - end).Y);
|
||||
|
||||
TileSelection = new TileReference<ushort, byte>[width, height];
|
||||
TileSelection = new TerrainTile[width, height];
|
||||
ResourceSelection = new ResourceTile[width, height];
|
||||
|
||||
for (var x = 0; x < width; x++)
|
||||
@@ -518,7 +518,7 @@ namespace OpenRA.Editor
|
||||
{
|
||||
// TODO: crash prevention
|
||||
var cell = new CPos(start.X + x, start.Y + y);
|
||||
TileSelection[x, y] = Map.MapTiles.Value[start.X + x, start.Y + y];
|
||||
TileSelection[x, y] = Map.MapTiles.Value[cell];
|
||||
ResourceSelection[x, y] = Map.MapResources.Value[cell];
|
||||
}
|
||||
}
|
||||
@@ -539,7 +539,7 @@ namespace OpenRA.Editor
|
||||
var cell = new CPos(mapX, mapY);
|
||||
|
||||
// TODO: crash prevention for outside of bounds
|
||||
Map.MapTiles.Value[mapX, mapY] = TileSelection[x, y];
|
||||
Map.MapTiles.Value[cell] = TileSelection[x, y];
|
||||
Map.MapResources.Value[cell] = ResourceSelection[x, y];
|
||||
|
||||
var ch = new int2(mapX / ChunkSize, mapY / ChunkSize);
|
||||
|
||||
Reference in New Issue
Block a user