nice clean maths, nice perf boost :D

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1163 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
chrisf
2007-07-10 08:13:35 +00:00
parent 88d24e18da
commit c59850008e
2 changed files with 18 additions and 12 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenRa.Game
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>(); Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
Effect effect; Effect effect;
IntPtr texture, scroll; IntPtr texture, scroll, r1h, r2h;
void LoadTextures() void LoadTextures()
{ {
@@ -148,6 +148,9 @@ namespace OpenRa.Game
effect = new Effect(device, File.OpenRead("../../../" + shaderName)); effect = new Effect(device, File.OpenRead("../../../" + shaderName));
texture = effect.GetHandle("DiffuseTexture"); texture = effect.GetHandle("DiffuseTexture");
scroll = effect.GetHandle("Scroll"); scroll = effect.GetHandle("Scroll");
r1h = effect.GetHandle("r1");
r2h = effect.GetHandle("r2");
} }
internal void Run() internal void Run()
@@ -178,11 +181,9 @@ namespace OpenRa.Game
if (e.Button != 0) if (e.Button != 0)
{ {
int dx = x1 - e.X;
int dy = y1 - e.Y;
scrollPos = oldPos; scrollPos = oldPos;
scrollPos.X += (float)dx / (ClientSize.Width / 2); scrollPos.X += x1 - e.X;
scrollPos.Y += (float)dy / (ClientSize.Height / 2); scrollPos.Y += y1 - e.Y;
} }
} }
@@ -198,6 +199,9 @@ namespace OpenRa.Game
void Frame() void Frame()
{ {
PointF r1 = new PointF(2.0f / ClientSize.Width, -2.0f / ClientSize.Height);
PointF r2 = new PointF(-1, 1);
device.Begin(); device.Begin();
device.Clear( 0, Surfaces.Color ); device.Clear( 0, Surfaces.Color );
@@ -208,6 +212,8 @@ namespace OpenRa.Game
effect.BeginPass(0); effect.BeginPass(0);
effect.SetValue(scroll, scrollPos); effect.SetValue(scroll, scrollPos);
effect.SetValue(r1h, r1);
effect.SetValue(r2h, r2);
foreach (KeyValuePair<Sheet, IndexBuffer> batch in drawBatches) foreach (KeyValuePair<Sheet, IndexBuffer> batch in drawBatches)
{ {
@@ -219,9 +225,9 @@ namespace OpenRa.Game
int indicesPerRow = map.Width * 6; int indicesPerRow = map.Width * 6;
int verticesPerRow = map.Width * 4; int verticesPerRow = map.Width * 4;
int visibleRows = (int)Math.Ceiling(800.0f / 24.0f) + 3; int visibleRows = (int)(ClientSize.Height / 24.0f + 2);
int firstRow = (int)((scrollPos.Y - 1) * 16.0f); int firstRow = (int)(scrollPos.Y / 24.0f);
int lastRow = firstRow + visibleRows; int lastRow = firstRow + visibleRows;
if (firstRow < 0) if (firstRow < 0)

View File

@@ -4,7 +4,8 @@
shared texture DiffuseTexture; shared texture DiffuseTexture;
shared float2 Scroll; shared float2 Scroll;
const float2 ScreenSize = { 640, 400 };
shared float2 r1, r2; // matrix elements
sampler s_DiffuseTexture = sampler_state { sampler s_DiffuseTexture = sampler_state {
Texture = <DiffuseTexture>; Texture = <DiffuseTexture>;
@@ -33,10 +34,9 @@ struct FragmentIn {
VertexOut Simple_vp(VertexIn v) { VertexOut Simple_vp(VertexIn v) {
VertexOut o; VertexOut o;
o.Position = float4(
v.Position.x / ScreenSize.x - 0.5f - Scroll.x, float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
Scroll.y - v.Position.y / ScreenSize.y, o.Position = float4(p.x,p.y,0,1);
0, 1 );
o.Tex0 = v.Tex0; o.Tex0 = v.Tex0;
return o; return o;
} }