git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1169 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -31,7 +31,7 @@ namespace OpenRa.Game
|
|||||||
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
|
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
|
||||||
|
|
||||||
World world;
|
World world;
|
||||||
TreeCache treeRenderer;
|
TreeCache treeCache;
|
||||||
|
|
||||||
void LoadTextures()
|
void LoadTextures()
|
||||||
{
|
{
|
||||||
@@ -68,26 +68,10 @@ namespace OpenRa.Game
|
|||||||
s.LoadTexture(renderer.Device);
|
s.LoadTexture(renderer.Device);
|
||||||
|
|
||||||
world = new World(renderer.Device);
|
world = new World(renderer.Device);
|
||||||
treeRenderer = new TreeCache(renderer.Device, map, TileMix, pal);
|
treeCache = new TreeCache(renderer.Device, map, TileMix, pal);
|
||||||
|
|
||||||
foreach (TreeReference treeReference in map.Trees)
|
foreach (TreeReference treeReference in map.Trees)
|
||||||
world.Add(new Tree(treeReference, treeRenderer, map));
|
world.Add(new Tree(treeReference, treeCache, map));
|
||||||
}
|
|
||||||
|
|
||||||
float U(SheetRectangle<Sheet> s, float u)
|
|
||||||
{
|
|
||||||
float u0 = (float)(s.origin.X + 0.5f) / (float)s.sheet.bitmap.Width;
|
|
||||||
float u1 = (float)(s.origin.X + s.size.Width) / (float)s.sheet.bitmap.Width;
|
|
||||||
|
|
||||||
return (u > 0) ? u1 : u0;// (1 - u) * u0 + u * u1;
|
|
||||||
}
|
|
||||||
|
|
||||||
float V(SheetRectangle<Sheet> s, float v)
|
|
||||||
{
|
|
||||||
float v0 = (float)(s.origin.Y + 0.5f) / (float)s.sheet.bitmap.Height;
|
|
||||||
float v1 = (float)(s.origin.Y + s.size.Height) / (float)s.sheet.bitmap.Height;
|
|
||||||
|
|
||||||
return (v > 0) ? v1 : v0;// return (1 - v) * v0 + v * v1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadVertexBuffer()
|
void LoadVertexBuffer()
|
||||||
@@ -100,24 +84,13 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
SheetRectangle<Sheet> tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]];
|
SheetRectangle<Sheet> tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]];
|
||||||
|
|
||||||
ushort offset = (ushort)vertices.Count;
|
|
||||||
|
|
||||||
vertices.Add(new Vertex(24 * i, 24 * j, 0, U(tile, 0), V(tile, 0)));
|
|
||||||
vertices.Add(new Vertex(24 + 24 * i, 24 * j, 0, U(tile, 1), V(tile, 0)));
|
|
||||||
vertices.Add(new Vertex(24 * i, 24 + 24 * j, 0, U(tile, 0), V(tile, 1)));
|
|
||||||
vertices.Add(new Vertex(24 + 24 * i, 24 + 24 * j, 0, U(tile, 1), V(tile, 1)));
|
|
||||||
|
|
||||||
List<ushort> indexList;
|
List<ushort> indexList;
|
||||||
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
||||||
indexMap.Add(tile.sheet, indexList = new List<ushort>());
|
indexMap.Add(tile.sheet, indexList = new List<ushort>());
|
||||||
|
|
||||||
indexList.Add(offset);
|
ushort offset = (ushort)vertices.Count;
|
||||||
indexList.Add((ushort)(offset + 1));
|
|
||||||
indexList.Add((ushort)(offset + 2));
|
|
||||||
|
|
||||||
indexList.Add((ushort)(offset + 1));
|
Util.CreateQuad(vertices, indexList, new PointF(24 * i, 24 * j), tile);
|
||||||
indexList.Add((ushort)(offset + 3));
|
|
||||||
indexList.Add((ushort)(offset + 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Count, Vertex.Format);
|
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Count, Vertex.Format);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
<Compile Include="Sheet.cs" />
|
<Compile Include="Sheet.cs" />
|
||||||
<Compile Include="Tree.cs" />
|
<Compile Include="Tree.cs" />
|
||||||
<Compile Include="TreeCache.cs" />
|
<Compile Include="TreeCache.cs" />
|
||||||
|
<Compile Include="Util.cs" />
|
||||||
<Compile Include="Vertex.cs" />
|
<Compile Include="Vertex.cs" />
|
||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
58
OpenRa.Game/Util.cs
Normal file
58
OpenRa.Game/Util.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
static class Util
|
||||||
|
{
|
||||||
|
public static float U(SheetRectangle<Sheet> s, float u)
|
||||||
|
{
|
||||||
|
float u0 = (float)(s.origin.X + 0.5f) / (float)s.sheet.bitmap.Width;
|
||||||
|
float u1 = (float)(s.origin.X + s.size.Width) / (float)s.sheet.bitmap.Width;
|
||||||
|
|
||||||
|
return (u > 0) ? u1 : u0;// (1 - u) * u0 + u * u1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float V(SheetRectangle<Sheet> s, float v)
|
||||||
|
{
|
||||||
|
float v0 = (float)(s.origin.Y + 0.5f) / (float)s.sheet.bitmap.Height;
|
||||||
|
float v1 = (float)(s.origin.Y + s.size.Height) / (float)s.sheet.bitmap.Height;
|
||||||
|
|
||||||
|
return (v > 0) ? v1 : v0;// return (1 - v) * v0 + v * v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vertex MakeVertex(PointF o, float u, float v, SheetRectangle<Sheet> r)
|
||||||
|
{
|
||||||
|
float x2 = o.X + r.size.Width;
|
||||||
|
float y2 = o.Y + r.size.Height;
|
||||||
|
|
||||||
|
return new Vertex(Lerp(o.X, x2, u), Lerp(o.Y, y2, v), 0, U(r, u), V(r, v));
|
||||||
|
}
|
||||||
|
|
||||||
|
static float Lerp(float a, float b, float t)
|
||||||
|
{
|
||||||
|
return (1 - t) * a + t * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, PointF o, SheetRectangle<Sheet> r)
|
||||||
|
{
|
||||||
|
ushort offset = (ushort)vertices.Count;
|
||||||
|
|
||||||
|
vertices.Add(Util.MakeVertex(o, 0, 0, r));
|
||||||
|
vertices.Add(Util.MakeVertex(o, 1, 0, r));
|
||||||
|
vertices.Add(Util.MakeVertex(o, 0, 1, r));
|
||||||
|
vertices.Add(Util.MakeVertex(o, 1, 1, r));
|
||||||
|
|
||||||
|
indices.Add(offset);
|
||||||
|
indices.Add((ushort)(offset + 1));
|
||||||
|
indices.Add((ushort)(offset + 2));
|
||||||
|
|
||||||
|
indices.Add((ushort)(offset + 1));
|
||||||
|
indices.Add((ushort)(offset + 3));
|
||||||
|
indices.Add((ushort)(offset + 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using BluntDirectX.Direct3D;
|
using BluntDirectX.Direct3D;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -47,21 +48,8 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
foreach (SheetRectangle<Sheet> image in a.currentImages)
|
foreach (SheetRectangle<Sheet> image in a.currentImages)
|
||||||
{
|
{
|
||||||
int offset = vertices.Count;
|
|
||||||
vertices.Add(new Vertex(a.location.X, a.location.Y, 0, U(image, 0), V(image, 0)));
|
|
||||||
vertices.Add(new Vertex(a.location.X + image.size.Width, a.location.Y, 0, U(image, 1), V(image, 0)));
|
|
||||||
vertices.Add(new Vertex(a.location.X, a.location.Y + image.size.Height, 0, U(image, 0), V(image, 1)));
|
|
||||||
vertices.Add(new Vertex(a.location.X + image.size.Width, a.location.Y + image.size.Height, 0, U(image, 1), V(image, 1)));
|
|
||||||
|
|
||||||
indices.Add((ushort)offset);
|
|
||||||
indices.Add((ushort)(offset + 1));
|
|
||||||
indices.Add((ushort)(offset + 2));
|
|
||||||
|
|
||||||
indices.Add((ushort)(offset + 1));
|
|
||||||
indices.Add((ushort)(offset + 3));
|
|
||||||
indices.Add((ushort)(offset + 2));
|
|
||||||
|
|
||||||
sheet = image.sheet;
|
sheet = image.sheet;
|
||||||
|
Util.CreateQuad(vertices, indices, a.location, image);
|
||||||
|
|
||||||
if (++sprites >= spritesPerBatch)
|
if (++sprites >= spritesPerBatch)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user