Style fixes for Renderer.SdlCommon.

This commit is contained in:
Paul Chote
2013-07-18 18:13:16 +12:00
parent 1b4e387ecc
commit 7853c2127e
7 changed files with 127 additions and 122 deletions

View File

@@ -54,4 +54,3 @@ namespace OpenRA.Renderer.SdlCommon
}
}
}

View File

@@ -64,6 +64,22 @@ namespace OpenRA.Renderer.SdlCommon
ErrorHandler.CheckGlError();
}
static int[] ViewportRectangle()
{
var v = new int[4];
unsafe
{
fixed (int* ptr = &v[0])
{
IntPtr intPtr = new IntPtr((void*)ptr);
Gl.glGetIntegerv(Gl.GL_VIEWPORT, intPtr);
}
}
ErrorHandler.CheckGlError();
return v;
}
void FinalizeInner()
{
Gl.glDeleteFramebuffersEXT(1, ref framebuffer);
@@ -74,22 +90,6 @@ namespace OpenRA.Renderer.SdlCommon
~FrameBuffer() { Game.RunAfterTick(FinalizeInner); }
static int[] ViewportRectangle()
{
int[] v = new int[4];
unsafe
{
fixed (int *ptr = &v[0])
{
IntPtr intPtr = new IntPtr((void*)ptr);
Gl.glGetIntegerv(Gl.GL_VIEWPORT, intPtr);
}
}
ErrorHandler.CheckGlError();
return v;
}
int[] cv = new int[4];
public void Bind()
{

View File

@@ -14,33 +14,29 @@ using OpenRA.FileFormats;
public static class MultiTapDetection
{
static Cache<string, TapHistory> KeyHistoryCache =
static Cache<string, TapHistory> keyHistoryCache =
new Cache<string, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
static Cache<byte, TapHistory> ClickHistoryCache =
static Cache<byte, TapHistory> clickHistoryCache =
new Cache<byte, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
public static int DetectFromMouse(byte MBName, int2 xy)
public static int DetectFromMouse(byte button, int2 xy)
{
var clickHistory = ClickHistoryCache[MBName];
return clickHistory.GetTapCount(xy);
return clickHistoryCache[button].GetTapCount(xy);
}
public static int InfoFromMouse(byte MBName)
public static int InfoFromMouse(byte button)
{
var clickHistory = ClickHistoryCache[MBName];
return clickHistory.LastTapCount();
return clickHistoryCache[button].LastTapCount();
}
public static int DetectFromKeyboard(string KeyName)
public static int DetectFromKeyboard(string key)
{
var keyHistory = KeyHistoryCache[KeyName];
return keyHistory.GetTapCount(int2.Zero);
return keyHistoryCache[key].GetTapCount(int2.Zero);
}
public static int InfoFromKeyboard(string KeyName)
public static int InfoFromKeyboard(string key)
{
var keyHistory = KeyHistoryCache[KeyName];
return keyHistory.LastTapCount();
return keyHistoryCache[key].LastTapCount();
}
}
@@ -65,15 +61,21 @@ class TapHistory
SecondRelease = ThirdRelease;
ThirdRelease = Pair.New(DateTime.Now, xy);
if (!CloseEnough(ThirdRelease, SecondRelease)) return 1;
if (!CloseEnough(SecondRelease, FirstRelease)) return 2;
if (!CloseEnough(ThirdRelease, SecondRelease))
return 1;
if (!CloseEnough(SecondRelease, FirstRelease))
return 2;
return 3;
}
public int LastTapCount()
{
if (!CloseEnough(ThirdRelease, SecondRelease)) return 1;
if (!CloseEnough(SecondRelease, FirstRelease)) return 2;
if (!CloseEnough(ThirdRelease, SecondRelease))
return 1;
if (!CloseEnough(SecondRelease, FirstRelease))
return 2;
return 3;
}
}

View File

@@ -117,6 +117,7 @@ namespace OpenRA.Renderer.SdlCommon
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
case PrimitiveType.QuadList: return Gl.GL_QUADS;
}
throw new NotImplementedException();
}
@@ -194,4 +195,3 @@ namespace OpenRA.Renderer.SdlCommon
public abstract IShader CreateShader(string name);
}
}

View File

@@ -71,9 +71,10 @@ namespace OpenRA.Renderer.SdlCommon
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Down, button, pos, mods,
MultiTapDetection.DetectFromMouse(e.button.button, pos)
));
} break;
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
break;
}
case Sdl.SDL_MOUSEBUTTONUP:
{
@@ -89,18 +90,19 @@ namespace OpenRA.Renderer.SdlCommon
var pos = new int2(e.button.x, e.button.y);
inputHandler.OnMouseInput(new MouseInput(
MouseInputEvent.Up, button, pos, mods,
MultiTapDetection.InfoFromMouse(e.button.button)
));
} break;
MultiTapDetection.InfoFromMouse(e.button.button)));
break;
}
case Sdl.SDL_MOUSEMOTION:
{
pendingMotion = new MouseInput(
MouseInputEvent.Move,
lastButtonBits,
new int2( e.motion.x, e.motion.y ),
mods, 0 );
} break;
MouseInputEvent.Move, lastButtonBits,
new int2(e.motion.x, e.motion.y), mods, 0);
break;
}
case Sdl.SDL_KEYDOWN:
{
@@ -118,12 +120,13 @@ namespace OpenRA.Renderer.SdlCommon
if (!HandleSpecialKey(keyEvent))
inputHandler.OnKeyInput(keyEvent);
} break;
break;
}
case Sdl.SDL_KEYUP:
{
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Up,
@@ -135,7 +138,8 @@ namespace OpenRA.Renderer.SdlCommon
};
inputHandler.OnKeyInput(keyEvent);
} break;
break;
}
}
}
@@ -164,12 +168,11 @@ namespace OpenRA.Renderer.SdlCommon
OpenRA.Game.Exit();
return true;
}
return false;
return false;
default:
return false;
}
}
}
}

View File

@@ -107,8 +107,7 @@ namespace OpenRA.Renderer.SdlCommon
size = new Size(bitmap.Width, bitmap.Height);
var bits = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
PrepareTexture();
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, bits.Width, bits.Height,
@@ -131,6 +130,8 @@ namespace OpenRA.Renderer.SdlCommon
Gl.glGetTexImage(Gl.GL_TEXTURE_2D, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
}
}
ErrorHandler.CheckGlError();
return data;
}

View File

@@ -18,8 +18,8 @@ namespace OpenRA.Renderer.SdlCommon
public class VertexBuffer<T> : IVertexBuffer<T>
where T : struct
{
static readonly int VertexSize = Marshal.SizeOf(typeof(T));
int buffer;
static readonly int vertexSize = Marshal.SizeOf(typeof(T));
public VertexBuffer(int size)
{
@@ -27,7 +27,7 @@ namespace OpenRA.Renderer.SdlCommon
ErrorHandler.CheckGlError();
Bind();
Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB,
new IntPtr(vertexSize * size),
new IntPtr(VertexSize * size),
new T[size],
Gl.GL_DYNAMIC_DRAW_ARB);
ErrorHandler.CheckGlError();
@@ -38,7 +38,7 @@ namespace OpenRA.Renderer.SdlCommon
Bind();
Gl.glBufferSubDataARB(Gl.GL_ARRAY_BUFFER_ARB,
IntPtr.Zero,
new IntPtr(vertexSize * length),
new IntPtr(VertexSize * length),
data);
ErrorHandler.CheckGlError();
}
@@ -47,9 +47,9 @@ namespace OpenRA.Renderer.SdlCommon
{
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, buffer);
ErrorHandler.CheckGlError();
Gl.glVertexPointer(3, Gl.GL_FLOAT, vertexSize, IntPtr.Zero);
Gl.glVertexPointer(3, Gl.GL_FLOAT, VertexSize, IntPtr.Zero);
ErrorHandler.CheckGlError();
Gl.glTexCoordPointer(4, Gl.GL_FLOAT, vertexSize, new IntPtr(12));
Gl.glTexCoordPointer(4, Gl.GL_FLOAT, VertexSize, new IntPtr(12));
ErrorHandler.CheckGlError();
}