git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1236 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -99,10 +99,10 @@ namespace OpenRa.Game
|
||||
|
||||
void Frame()
|
||||
{
|
||||
PointF r1 = new PointF(2.0f / viewport.ClientSize.Width, -2.0f / viewport.ClientSize.Height);
|
||||
PointF r2 = new PointF(-1, 1);
|
||||
float2 r1 = new float2(2, -2) / viewport.Size;
|
||||
float2 r2 = new float2(-1, 1);
|
||||
|
||||
renderer.BeginFrame(r1, r2, viewport.ScrollPosition);
|
||||
renderer.BeginFrame(r1, r2, viewport.Location);
|
||||
|
||||
renderer.Device.EnableScissor(0, 0, viewport.ClientSize.Width - 128, viewport.ClientSize.Height);
|
||||
terrain.Draw(viewport);
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.IO;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
public class Renderer
|
||||
class Renderer
|
||||
{
|
||||
readonly GraphicsDevice device;
|
||||
readonly Effect shader;
|
||||
@@ -40,10 +40,9 @@ namespace OpenRa.Game
|
||||
|
||||
public GraphicsDevice Device { get { return device; } }
|
||||
|
||||
public void BeginFrame( PointF r1, PointF r2, PointF scroll )
|
||||
public void BeginFrame( float2 r1, float2 r2, float2 scroll )
|
||||
{
|
||||
device.Begin();
|
||||
//device.Clear(Color.Gray.ToArgb(), Surfaces.Color);
|
||||
|
||||
shader.SetValue(scrollHandle, scroll);
|
||||
shader.SetValue(r1Handle, r1);
|
||||
|
||||
@@ -42,13 +42,13 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSprite(Sprite s, ref PointF p)
|
||||
void DrawSprite(Sprite s, ref float2 p)
|
||||
{
|
||||
spriteRenderer.DrawSprite(s, p, 0);
|
||||
p.Y += 48;
|
||||
}
|
||||
|
||||
void Fill(Size clientSize, PointF p)
|
||||
void Fill(Size clientSize, float2 p)
|
||||
{
|
||||
while (p.Y < clientSize.Height)
|
||||
DrawSprite(blank, ref p);
|
||||
@@ -56,8 +56,8 @@ namespace OpenRa.Game
|
||||
|
||||
public void Paint(Viewport viewport)
|
||||
{
|
||||
PointF buildPos = new PointF(viewport.ClientSize.Width - 128 + viewport.ScrollPosition.X, viewport.ScrollPosition.Y);
|
||||
PointF unitPos = new PointF(viewport.ClientSize.Width - 64 + viewport.ScrollPosition.X, viewport.ScrollPosition.Y);
|
||||
float2 buildPos = viewport.Location + new float2(viewport.ClientSize.Width - 128, 0);
|
||||
float2 unitPos = viewport.Location + new float2(viewport.ClientSize.Width - 64, 0);
|
||||
|
||||
foreach (Item i in techTree.BuildableItems)
|
||||
{
|
||||
|
||||
@@ -30,11 +30,11 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
public PointF MapTextureCoords(PointF p)
|
||||
public float2 MapTextureCoords(float2 p)
|
||||
{
|
||||
RectangleF uv = TextureCoords;
|
||||
|
||||
return new PointF(
|
||||
return new float2(
|
||||
p.X > 0 ? uv.Right : uv.Left,
|
||||
p.Y > 0 ? uv.Bottom : uv.Top);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawSprite(Sprite s, PointF location, int palette)
|
||||
public void DrawSprite(Sprite s, float2 location, int palette)
|
||||
{
|
||||
if (s.sheet != currentSheet)
|
||||
Flush();
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRa.Game
|
||||
|
||||
terrainSheet = tile.sheet;
|
||||
|
||||
Util.CreateQuad(vertices, indices, new PointF(24 * i, 24 * j), tile, 0);
|
||||
Util.CreateQuad(vertices, indices, 24 * new float2(i,j), tile, 0);
|
||||
}
|
||||
|
||||
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Count, Vertex.Format);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace OpenRa.Game
|
||||
return x < range.Start ? range.Start : x > range.End ? range.End : x;
|
||||
}
|
||||
|
||||
static PointF EncodeVertexAttributes(TextureChannel channel, int paletteLine)
|
||||
static float2 EncodeVertexAttributes(TextureChannel channel, int paletteLine)
|
||||
{
|
||||
Converter<TextureChannel, float> channelEncoder = delegate(TextureChannel c)
|
||||
{
|
||||
@@ -29,15 +29,13 @@ namespace OpenRa.Game
|
||||
}
|
||||
};
|
||||
|
||||
return new PointF(paletteLine / 16.0f, channelEncoder(channel));
|
||||
return new float2(paletteLine / 16.0f, channelEncoder(channel));
|
||||
}
|
||||
|
||||
public static Vertex MakeVertex(PointF o, PointF uv, Sprite r, int palette)
|
||||
public static Vertex MakeVertex(float2 o, float2 uv, Sprite r, int palette)
|
||||
{
|
||||
PointF farCorner = new PointF(o.X + r.bounds.Width, o.Y + r.bounds.Height);
|
||||
|
||||
return new Vertex(
|
||||
Lerp( o, farCorner, uv ),
|
||||
Lerp( o, o + new float2(r.bounds.Size), uv ),
|
||||
r.MapTextureCoords(uv),
|
||||
EncodeVertexAttributes(r.channel, palette));
|
||||
}
|
||||
@@ -47,26 +45,26 @@ namespace OpenRa.Game
|
||||
return (1 - t) * a + t * b;
|
||||
}
|
||||
|
||||
static PointF Lerp(PointF a, PointF b, PointF t)
|
||||
static float2 Lerp(float2 a, float2 b, float2 t)
|
||||
{
|
||||
return new PointF(
|
||||
return new float2(
|
||||
Lerp(a.X, b.X, t.X),
|
||||
Lerp(a.Y, b.Y, t.Y));
|
||||
}
|
||||
|
||||
static PointF[] uv =
|
||||
static float2[] uv =
|
||||
{
|
||||
new PointF( 0,0 ),
|
||||
new PointF( 1,0 ),
|
||||
new PointF( 0,1 ),
|
||||
new PointF( 1,1 ),
|
||||
new float2( 0,0 ),
|
||||
new float2( 1,0 ),
|
||||
new float2( 0,1 ),
|
||||
new float2( 1,1 ),
|
||||
};
|
||||
|
||||
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, PointF o, Sprite r, int palette)
|
||||
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, float2 o, Sprite r, int palette)
|
||||
{
|
||||
ushort offset = (ushort)vertices.Count;
|
||||
|
||||
foreach( PointF p in uv )
|
||||
foreach( float2 p in uv )
|
||||
vertices.Add(Util.MakeVertex(o, p, r, palette));
|
||||
|
||||
indices.Add(offset);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace OpenRa.Game
|
||||
public float x, y, z, u, v;
|
||||
public float p, c;
|
||||
|
||||
public Vertex(PointF xy, PointF uv, PointF pc)
|
||||
public Vertex(float2 xy, float2 uv, float2 pc)
|
||||
{
|
||||
this.x = xy.X; this.y = xy.Y; this.z = 0;
|
||||
this.u = uv.X; this.v = uv.Y;
|
||||
|
||||
@@ -7,7 +7,7 @@ using BluntDirectX.Direct3D;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
public delegate void Renderable(Renderer renderer, Viewport viewport);
|
||||
delegate void Renderable(Renderer renderer, Viewport viewport);
|
||||
class Viewport
|
||||
{
|
||||
readonly Size clientSize;
|
||||
@@ -18,6 +18,9 @@ namespace OpenRa.Game
|
||||
public PointF ScrollPosition { get { return scrollPosition.ToPointF(); } }
|
||||
public Size ClientSize { get { return clientSize; } }
|
||||
|
||||
public float2 Location { get { return scrollPosition; } }
|
||||
public float2 Size { get { return scrollPosition + new float2(ClientSize); } }
|
||||
|
||||
public void Scroll(float2 delta)
|
||||
{
|
||||
scrollPosition = (scrollPosition + delta).Constrain(new Range<float2>(float2.Zero, mapSize));
|
||||
|
||||
@@ -12,17 +12,14 @@ namespace OpenRa.Game
|
||||
List<Actor> actors = new List<Actor>();
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
public World(Renderer renderer)
|
||||
{
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
}
|
||||
public World(Renderer renderer) { spriteRenderer = new SpriteRenderer(renderer, true); }
|
||||
|
||||
public void Add(Actor a) { actors.Add(a); }
|
||||
|
||||
public void Draw(Renderer renderer, Viewport viewport)
|
||||
{
|
||||
Range<float> xr = new Range<float>(viewport.ScrollPosition.X, viewport.ScrollPosition.X + viewport.ClientSize.Width);
|
||||
Range<float> yr = new Range<float>(viewport.ScrollPosition.Y, viewport.ScrollPosition.Y + viewport.ClientSize.Height);
|
||||
Range<float2> range = new Range<float2>(viewport.Location, viewport.Size);
|
||||
|
||||
foreach (Actor a in actors)
|
||||
{
|
||||
Sprite[] images = a.CurrentImages;
|
||||
@@ -30,14 +27,14 @@ namespace OpenRa.Game
|
||||
if (images == null)
|
||||
continue;
|
||||
|
||||
if (a.location.X > xr.End || a.location.X < xr.Start - images[0].bounds.Width)
|
||||
if (a.location.X > range.End.X || a.location.X < range.Start.X - images[0].bounds.Width)
|
||||
continue;
|
||||
|
||||
if (a.location.Y > yr.End || a.location.Y < yr.Start - images[0].bounds.Height)
|
||||
if (a.location.Y > range.End.Y || a.location.Y < range.Start.Y - images[0].bounds.Height)
|
||||
continue;
|
||||
|
||||
foreach (Sprite image in images)
|
||||
spriteRenderer.DrawSprite(image, a.location.ToPointF(), a.palette);
|
||||
spriteRenderer.DrawSprite(image, a.location, a.palette);
|
||||
}
|
||||
|
||||
spriteRenderer.Flush();
|
||||
|
||||
@@ -43,5 +43,10 @@ namespace OpenRa.Game
|
||||
}
|
||||
|
||||
public static readonly float2 Zero = new float2(0, 0);
|
||||
|
||||
public static float2 operator /(float2 a, float2 b)
|
||||
{
|
||||
return new float2(a.X / b.X, a.Y / b.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user