From afa33004d4ed0f3c74d9aa75de1b58388c1245ca Mon Sep 17 00:00:00 2001 From: chrisf Date: Sat, 7 Jul 2007 04:06:58 +0000 Subject: [PATCH] MS suck at perf :) (System.ValueType) git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1121 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.FileFormats/Map.cs | 24 ++++++++++++++++++++++++ OpenRa.Game/MainWindow.cs | 23 ++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index 6b1b1d24bb..19e887ae61 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -123,6 +123,30 @@ namespace OpenRa.FileFormats { public ushort tile; public byte image; + + public override int GetHashCode() + { + return tile.GetHashCode() ^ image.GetHashCode(); + } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + TileReference r = (TileReference)obj; + return (r.image == image && r.tile == tile); + } + + public static bool operator ==(TileReference a, TileReference b) + { + return a.Equals(b); + } + + public static bool operator !=(TileReference a, TileReference b) + { + return !a.Equals(b); + } } public struct TreeReference diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 88fd26b107..7327432798 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -26,7 +26,6 @@ namespace OpenRa.Game new Dictionary>(); FvfVertexBuffer vertexBuffer; - IndexBuffer indexBuffer; void LoadTextures() { @@ -63,26 +62,40 @@ namespace OpenRa.Game void LoadVertexBuffer() { + Dictionary> indexMap = new Dictionary>(); + Vertex[] vertices = new Vertex[4 * 128 * 128];//map.Width * map.Height]; for( int i = 0; i < 128; i++ ) for (int j = 0; j < 128; j++) { - int offset = 4 * (i * 128 + j); + SheetRectangle tile = tileMapping[map.MapTiles[i, j]]; + + ushort offset = (ushort)(4 * (i * 128 + j)); vertices[offset] = new Vertex(24 * i, 24 * j, 0, 0, 0); vertices[offset + 1] = new Vertex(24 + 24 * i, 24 * j, 0, 1, 0); vertices[offset + 2] = new Vertex(24 * i, 24 + 24 * j, 0, 0, 1); vertices[offset + 3] = new Vertex(24 + 24 * i, 24 + 24 * j, 0, 1, 1); + + List indexList; + if (!indexMap.TryGetValue(tile.sheet, out indexList)) + indexMap.Add(tile.sheet, indexList = new List()); + + indexList.Add(offset); + indexList.Add((ushort)(offset + 1)); + indexList.Add((ushort)(offset + 2)); + + indexList.Add((ushort)(offset + 1)); + indexList.Add((ushort)(offset + 3)); + indexList.Add((ushort)(offset + 2)); } vertexBuffer = new FvfVertexBuffer(device, vertices.Length, Vertex.Format); vertexBuffer.SetData(vertices); - ushort[] indices = new ushort[6 * map.Width * map.Height]; + Dictionary indexBuffers = new Dictionary(); - indexBuffer = new IndexBuffer(device, indices.Length); - indexBuffer.SetData(indices); } public MainWindow()