git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1167 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2007-07-11 10:49:17 +00:00
parent 01cc8b7b46
commit 0b36bfacdd
4 changed files with 140 additions and 94 deletions

View File

@@ -16,20 +16,20 @@ namespace OpenRa.Game
class Tree : Actor
{
public Tree( TreeReference r, TreeRenderer renderer, Map map )
public Tree( TreeReference r, TreeCache renderer, Map map )
{
location = new PointF(24 * (r.X - map.XOffset), 24 * (r.Y - map.YOffset));
currentImages = new SheetRectangle<Sheet>[] { renderer.GetImage( r.Image ) };
}
}
class TreeRenderer
class TreeCache
{
Dictionary<string, SheetRectangle<Sheet>> trees = new Dictionary<string, SheetRectangle<Sheet>>();
public readonly Sheet sh;
public TreeRenderer(GraphicsDevice device, Map map, Package package, Palette pal)
public TreeCache(GraphicsDevice device, Map map, Package package, Palette pal)
{
Size pageSize = new Size( 1024, 512 );
List<Sheet> sheets = new List<Sheet>();
@@ -97,11 +97,12 @@ namespace OpenRa.Game
// assumption: its not going to hurt, to draw *all* units.
// in reality, 500 tanks is going to hurt our perf.
public void Draw()
public void Draw( Renderer renderer )
{
int sprites = 0;
List<Vertex> vertices = new List<Vertex>();
List<ushort> indices = new List<ushort>();
Sheet sheet = null;
foreach (Actor a in actors)
{
@@ -124,9 +125,11 @@ namespace OpenRa.Game
indices.Add((ushort)(offset + 3));
indices.Add((ushort)(offset + 2));
sheet = image.sheet;
if (++sprites >= spritesPerBatch)
{
DrawBatch(vertices, indices);
DrawBatch(vertices, indices, renderer, sheet);
vertices = new List<Vertex>();
indices = new List<ushort>();
@@ -136,19 +139,22 @@ namespace OpenRa.Game
}
if (sprites > 0)
DrawBatch(vertices, indices);
DrawBatch(vertices, indices, renderer, sheet);
}
void DrawBatch(List<Vertex> vertices, List<ushort> indices)
void DrawBatch(List<Vertex> vertices, List<ushort> indices, Renderer renderer, Sheet sheet)
{
vb.SetData(vertices.ToArray());
ib.SetData(indices.ToArray());
vb.Bind(0);
ib.Bind();
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
vertices.Count, indices.Count / 3);
renderer.DrawWithShader(ShaderQuality.High,
delegate
{
renderer.DrawBatch(vb, ib,
new Range<int>(0, vertices.Count),
new Range<int>(0, indices.Count),
sheet.texture);
});
}
static float U(SheetRectangle<Sheet> s, float u)