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

@@ -18,7 +18,6 @@ namespace OpenRA.Graphics
{
class TerrainRenderer
{
SheetBuilder sheetBuilder;
IVertexBuffer<Vertex> vertexBuffer;
World world;
@@ -29,23 +28,6 @@ namespace OpenRA.Graphics
this.world = world;
this.map = world.Map;
var allocated = false;
Func<Sheet> allocate = () =>
{
if (allocated)
throw new SheetOverflowException("Terrain sheet overflow");
allocated = true;
// TODO: Use a fixed sheet size specified in the tileset yaml
return SheetBuilder.AllocateSheet();
};
sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);
var tileSize = new Size(Game.CellSize, Game.CellSize);
var tileMapping = new Cache<TileReference<ushort,byte>, Sprite>(
x => sheetBuilder.Add(world.TileSet.GetBytes(x), tileSize));
var terrainPalette = wr.Palette("terrain").Index;
var vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width];
int nv = 0;
@@ -53,7 +35,7 @@ namespace OpenRA.Graphics
for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
for (var i = map.Bounds.Left; i < map.Bounds.Right; i++)
{
var tile = tileMapping[map.MapTiles.Value[i, j]];
var tile = wr.Theater.TileSprite(map.MapTiles.Value[i, j]);
Util.FastCreateQuad(vertices, Game.CellSize * new float2(i, j), tile, terrainPalette, nv, tile.size);
nv += 4;
}
@@ -96,7 +78,7 @@ namespace OpenRA.Graphics
Game.Renderer.WorldSpriteRenderer.DrawVertexBuffer(
vertexBuffer, verticesPerRow * firstRow, verticesPerRow * (lastRow - firstRow),
PrimitiveType.QuadList, sheetBuilder.Current);
PrimitiveType.QuadList, wr.Theater.Sheet);
foreach (var r in world.WorldActor.TraitsImplementing<IRenderOverlay>())
r.Render(wr);