Skip to content

Commit

Permalink
Test: Load c&c terrain tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Mar 3, 2010
1 parent 88f322d commit 3fd7af5
Show file tree
Hide file tree
Showing 8 changed files with 1,176 additions and 21 deletions.
53 changes: 39 additions & 14 deletions OpenRA.FileFormats/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,52 @@ public class Terrain

public Terrain( Stream stream )
{
int Width, Height;

int Width, Height, IndexEnd, IndexStart;
uint ImgStart;
// Try loading as a cnc .tem
BinaryReader reader = new BinaryReader( stream );
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();

if( Width != 24 || Height != 24 )
throw new InvalidDataException( string.Format( "{0}x{1}", Width, Height ) );

/*NumTiles = */reader.ReadUInt16();
reader.ReadUInt16();
/*XDim = */reader.ReadUInt16();
/*YDim = */reader.ReadUInt16();
/*uint FileSize = */reader.ReadUInt32();
uint ImgStart = reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt32();
int IndexEnd = reader.ReadInt32();
reader.ReadUInt32();
int IndexStart = reader.ReadInt32();

/*Zero1 = */reader.ReadUInt16();
/*uint Size = */reader.ReadUInt32();
ImgStart = reader.ReadUInt32();
/*Zero2 = */reader.ReadUInt32();

if (reader.ReadUInt16() == 65535) // ID1 = FFFFh for cnc
{
/*ID2 = */reader.ReadUInt16();
IndexEnd = reader.ReadInt32();
IndexStart = reader.ReadInt32();
}
else // Load as a ra .tem
{
stream.Position = 0;
// Try loading as an RA .tem
reader = new BinaryReader( stream );
Width = reader.ReadUInt16();
Height = reader.ReadUInt16();
if( Width != 24 || Height != 24 )
throw new InvalidDataException( string.Format( "{0}x{1}", Width, Height ) );

/*NumTiles = */reader.ReadUInt16();
reader.ReadUInt16();
/*XDim = */reader.ReadUInt16();
/*YDim = */reader.ReadUInt16();
/*uint FileSize = */reader.ReadUInt32();
ImgStart = reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt32();
IndexEnd = reader.ReadInt32();
reader.ReadUInt32();
IndexStart = reader.ReadInt32();
}

Log.Write("IndexStart: {0}",IndexStart);
stream.Position = IndexStart;

foreach( byte b in new BinaryReader(stream).ReadBytes(IndexEnd - IndexStart) )
Expand Down
9 changes: 6 additions & 3 deletions OpenRA.FileFormats/TileSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public TileSet( string suffix )

using( Stream s = FileSystem.Open( tilename + suffix ) )
{
Log.Write(tilename+suffix);
if( !tiles.ContainsKey( (ushort)( start + i ) ) )
tiles.Add( (ushort)( start + i ), new Terrain( s ) );
}
Expand All @@ -88,9 +89,11 @@ public TileSet( string suffix )
public byte[] GetBytes(TileReference r)
{
Terrain tile;
if( tiles.TryGetValue( r.tile, out tile ) )
return tile.TileBitmapBytes[ r.image ];

try {
if( tiles.TryGetValue( r.tile, out tile ) )
return tile.TileBitmapBytes[ r.image ];
} catch (System.ArgumentOutOfRangeException) {}

byte[] missingTile = new byte[ 24 * 24 ];
for( int i = 0 ; i < missingTile.Length ; i++ )
missingTile[ i ] = 0x36;
Expand Down
6 changes: 4 additions & 2 deletions OpenRA.Game/Shroud.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
Expand Down Expand Up @@ -34,7 +34,9 @@ public class Shroud
Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow");
Sprite[,] sprites = new Sprite[128, 128];
bool dirty = true;
bool hasGPS = false;

// TODO: Testing
bool hasGPS = true;
Player owner;
Map map;
public Rectangle? bounds;
Expand Down
Loading

0 comments on commit 3fd7af5

Please sign in to comment.