Make binary info loading lazy

This commit is contained in:
Paul Chote
2011-02-11 21:15:13 +13:00
parent b134ba41f4
commit 73020a9419
10 changed files with 88 additions and 62 deletions

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Editor
{
var z = u + v * template.Size.X;
if (tile.TileBitmapBytes[z] != null)
surface.Map.MapTiles[u + pos.X, v + pos.Y] =
surface.Map.MapTiles.Value[u + pos.X, v + pos.Y] =
new TileReference<ushort, byte>
{
type = Brush.N,
@@ -72,7 +72,7 @@ namespace OpenRA.Editor
void FloodFillWithBrush(Surface s, int2 pos)
{
var queue = new Queue<int2>();
var replace = s.Map.MapTiles[pos.X, pos.Y];
var replace = s.Map.MapTiles.Value[pos.X, pos.Y];
var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y];
Action<int, int> MaybeEnqueue = (x, y) =>
@@ -88,7 +88,7 @@ namespace OpenRA.Editor
while (queue.Count > 0)
{
var p = queue.Dequeue();
if (!s.Map.MapTiles[p.X, p.Y].Equals(replace))
if (!s.Map.MapTiles.Value[p.X, p.Y].Equals(replace))
continue;
var a = FindEdge(s, p, new int2(-1, 0), replace);
@@ -96,10 +96,10 @@ namespace OpenRA.Editor
for (var x = a.X; x <= b.X; x++)
{
s.Map.MapTiles[x, p.Y] = new TileReference<ushort, byte> { type = Brush.N, index = (byte)0 };
if (s.Map.MapTiles[x, p.Y - 1].Equals(replace))
s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { type = Brush.N, index = (byte)0 };
if (s.Map.MapTiles.Value[x, p.Y - 1].Equals(replace))
MaybeEnqueue(x, p.Y - 1);
if (s.Map.MapTiles[x, p.Y + 1].Equals(replace))
if (s.Map.MapTiles.Value[x, p.Y + 1].Equals(replace))
MaybeEnqueue(x, p.Y + 1);
}
}
@@ -115,7 +115,7 @@ namespace OpenRA.Editor
{
var q = p + d;
if (!s.Map.IsInMap(q)) return p;
if (!s.Map.MapTiles[q.X, q.Y].Equals(replace)) return p;
if (!s.Map.MapTiles.Value[q.X, q.Y].Equals(replace)) return p;
p = q;
}
}

View File

@@ -117,6 +117,7 @@ namespace OpenRA.Editor
public void ConvertIniMap(string iniFile)
{
var file = new IniFile(FileSystem.Open(iniFile));
var basic = file.GetSection("Basic");
var map = file.GetSection("Map");
@@ -134,7 +135,7 @@ namespace OpenRA.Editor
Map.MapSize.Y = MapSize;
Map.Bounds = Rectangle.FromLTRB(XOffset, YOffset, XOffset + Width, YOffset + Height);
Map.Selectable = true;
/*
if (legacyMapFormat == IniMapFormat.RedAlert)
{
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
@@ -147,7 +148,7 @@ namespace OpenRA.Editor
ReadCncOverlay(file);
ReadCncTrees(file);
}
*/
LoadActors(file, "STRUCTURES");
LoadActors(file, "UNITS");
LoadActors(file, "INFANTRY");
@@ -232,7 +233,7 @@ namespace OpenRA.Editor
return ret;
}
/*
void UnpackRATileData(MemoryStream ms)
{
Map.MapTiles = new TileReference<ushort, byte>[MapSize, MapSize];
@@ -312,7 +313,7 @@ namespace OpenRA.Editor
Map.MapTiles[i, j].index = byte.MaxValue;
}
}
void ReadCncOverlay(IniFile file)
{
IniSection overlay = file.GetSection("OVERLAY", true);
@@ -340,7 +341,7 @@ namespace OpenRA.Editor
});
}
}
*/
void ReadCncTrees(IniFile file)
{
IniSection terrain = file.GetSection("TERRAIN", true);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Editor
public void Apply(Surface surface)
{
surface.Map.MapResources[surface.GetBrushLocation().X, surface.GetBrushLocation().Y]
surface.Map.MapResources.Value[surface.GetBrushLocation().X, surface.GetBrushLocation().Y]
= new TileReference<byte, byte>
{
type = (byte)Resource.Info.ResourceType,

View File

@@ -155,9 +155,9 @@ namespace OpenRA.Editor
var key = Map.Actors.FirstOrDefault(a => a.Value.Location() == BrushLocation);
if (key.Key != null) Map.Actors.Remove(key.Key);
if (Map.MapResources[BrushLocation.X, BrushLocation.Y].type != 0)
if (Map.MapResources.Value[BrushLocation.X, BrushLocation.Y].type != 0)
{
Map.MapResources[BrushLocation.X, BrushLocation.Y] = new TileReference<byte, byte>();
Map.MapResources.Value[BrushLocation.X, BrushLocation.Y] = new TileReference<byte, byte>();
var ch = new int2((BrushLocation.X) / ChunkSize, (BrushLocation.Y) / ChunkSize);
if (Chunks.ContainsKey(ch))
{
@@ -209,7 +209,7 @@ namespace OpenRA.Editor
for (var i = 0; i < ChunkSize; i++)
for (var j = 0; j < ChunkSize; j++)
{
var tr = Map.MapTiles[u * ChunkSize + i, v * ChunkSize + j];
var tr = Map.MapTiles.Value[u * ChunkSize + i, v * ChunkSize + j];
var tile = TileSet.Tiles[tr.type];
var index = (tr.index < tile.TileBitmapBytes.Count) ? tr.index : (byte)0;
var rawImage = tile.TileBitmapBytes[index];
@@ -217,9 +217,9 @@ namespace OpenRA.Editor
for (var y = 0; y < TileSet.TileSize; y++)
p[(j * TileSet.TileSize + y) * stride + i * TileSet.TileSize + x] = Palette.GetColor(rawImage[x + TileSet.TileSize * y]).ToArgb();
if (Map.MapResources[u * ChunkSize + i, v * ChunkSize + j].type != 0)
if (Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type != 0)
{
var resourceImage = ResourceTemplates[Map.MapResources[u * ChunkSize + i, v * ChunkSize + j].type].Bitmap;
var resourceImage = ResourceTemplates[Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type].Bitmap;
var srcdata = resourceImage.LockBits(new Rectangle(0, 0, resourceImage.Width, resourceImage.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);