Split tileset artwork loading out of TileSet.

This simplifies terrain loading and allows for
non-square tiles in game.

The editor still relies on the old code for now.
This commit is contained in:
Paul Chote
2013-08-14 20:28:41 +12:00
parent 2b6b212d02
commit 387ac04d9f
7 changed files with 122 additions and 90 deletions

View File

@@ -16,16 +16,15 @@ namespace OpenRA.FileFormats
public class Terrain
{
public readonly List<byte[]> TileBitmapBytes = new List<byte[]>();
public readonly int Width;
public readonly int Height;
public Terrain( Stream stream, int size )
public Terrain(Stream stream)
{
// Try loading as a cnc .tem
BinaryReader reader = new BinaryReader( stream );
int Width = reader.ReadUInt16();
int Height = reader.ReadUInt16();
if( Width != size || Height != size )
throw new InvalidDataException( "{0}x{1} != {2}x{2}".F(Width, Height, size ) );
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
/*NumTiles = */reader.ReadUInt16();
/*Zero1 = */reader.ReadUInt16();
@@ -65,8 +64,8 @@ namespace OpenRA.FileFormats
{
if (b != 255)
{
stream.Position = ImgStart + b * size * size;
TileBitmapBytes.Add(new BinaryReader(stream).ReadBytes(size * size));
stream.Position = ImgStart + b * Width * Height;
TileBitmapBytes.Add(new BinaryReader(stream).ReadBytes(Width * Height));
}
else
TileBitmapBytes.Add(null);

View File

@@ -113,7 +113,7 @@ namespace OpenRA.FileFormats
foreach (var t in Templates)
if (t.Value.Data == null)
using (var s = FileSystem.OpenWithExts(t.Value.Image, Extensions))
t.Value.Data = new Terrain(s, TileSize);
t.Value.Data = new Terrain(s);
}
public void Save(string filepath)
@@ -144,23 +144,6 @@ namespace OpenRA.FileFormats
root.WriteToFile(filepath);
}
public byte[] GetBytes(TileReference<ushort,byte> r)
{
TileTemplate tile;
if (Templates.TryGetValue(r.type, out tile))
{
var data = tile.Data.TileBitmapBytes[r.index];
if (data != null)
return data;
}
byte[] missingTile = new byte[TileSize*TileSize];
for (var i = 0; i < missingTile.Length; i++)
missingTile[i] = 0x00;
return missingTile;
}
public string GetTerrainType(TileReference<ushort, byte> r)
{
var tt = Templates[r.type].Tiles;