Style fixes for Renderer.SdlCommon.
This commit is contained in:
@@ -54,4 +54,3 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,22 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
ErrorHandler.CheckGlError();
|
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()
|
void FinalizeInner()
|
||||||
{
|
{
|
||||||
Gl.glDeleteFramebuffersEXT(1, ref framebuffer);
|
Gl.glDeleteFramebuffersEXT(1, ref framebuffer);
|
||||||
@@ -74,22 +90,6 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
~FrameBuffer() { Game.RunAfterTick(FinalizeInner); }
|
~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];
|
int[] cv = new int[4];
|
||||||
public void Bind()
|
public void Bind()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,33 +14,29 @@ using OpenRA.FileFormats;
|
|||||||
|
|
||||||
public static class MultiTapDetection
|
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)));
|
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)));
|
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 clickHistoryCache[button].GetTapCount(xy);
|
||||||
return clickHistory.GetTapCount(xy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int InfoFromMouse(byte MBName)
|
public static int InfoFromMouse(byte button)
|
||||||
{
|
{
|
||||||
var clickHistory = ClickHistoryCache[MBName];
|
return clickHistoryCache[button].LastTapCount();
|
||||||
return clickHistory.LastTapCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int DetectFromKeyboard(string KeyName)
|
public static int DetectFromKeyboard(string key)
|
||||||
{
|
{
|
||||||
var keyHistory = KeyHistoryCache[KeyName];
|
return keyHistoryCache[key].GetTapCount(int2.Zero);
|
||||||
return keyHistory.GetTapCount(int2.Zero);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int InfoFromKeyboard(string KeyName)
|
public static int InfoFromKeyboard(string key)
|
||||||
{
|
{
|
||||||
var keyHistory = KeyHistoryCache[KeyName];
|
return keyHistoryCache[key].LastTapCount();
|
||||||
return keyHistory.LastTapCount();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,15 +61,21 @@ class TapHistory
|
|||||||
SecondRelease = ThirdRelease;
|
SecondRelease = ThirdRelease;
|
||||||
ThirdRelease = Pair.New(DateTime.Now, xy);
|
ThirdRelease = Pair.New(DateTime.Now, xy);
|
||||||
|
|
||||||
if (!CloseEnough(ThirdRelease, SecondRelease)) return 1;
|
if (!CloseEnough(ThirdRelease, SecondRelease))
|
||||||
if (!CloseEnough(SecondRelease, FirstRelease)) return 2;
|
return 1;
|
||||||
|
if (!CloseEnough(SecondRelease, FirstRelease))
|
||||||
|
return 2;
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int LastTapCount()
|
public int LastTapCount()
|
||||||
{
|
{
|
||||||
if (!CloseEnough(ThirdRelease, SecondRelease)) return 1;
|
if (!CloseEnough(ThirdRelease, SecondRelease))
|
||||||
if (!CloseEnough(SecondRelease, FirstRelease)) return 2;
|
return 1;
|
||||||
|
if (!CloseEnough(SecondRelease, FirstRelease))
|
||||||
|
return 2;
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
||||||
case PrimitiveType.QuadList: return Gl.GL_QUADS;
|
case PrimitiveType.QuadList: return Gl.GL_QUADS;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,4 +195,3 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
public abstract IShader CreateShader(string name);
|
public abstract IShader CreateShader(string name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,9 +71,10 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
inputHandler.OnMouseInput(new MouseInput(
|
inputHandler.OnMouseInput(new MouseInput(
|
||||||
MouseInputEvent.Down, button, pos, mods,
|
MouseInputEvent.Down, button, pos, mods,
|
||||||
MultiTapDetection.DetectFromMouse(e.button.button, pos)
|
MultiTapDetection.DetectFromMouse(e.button.button, pos)));
|
||||||
));
|
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEBUTTONUP:
|
case Sdl.SDL_MOUSEBUTTONUP:
|
||||||
{
|
{
|
||||||
@@ -89,18 +90,19 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
var pos = new int2(e.button.x, e.button.y);
|
var pos = new int2(e.button.x, e.button.y);
|
||||||
inputHandler.OnMouseInput(new MouseInput(
|
inputHandler.OnMouseInput(new MouseInput(
|
||||||
MouseInputEvent.Up, button, pos, mods,
|
MouseInputEvent.Up, button, pos, mods,
|
||||||
MultiTapDetection.InfoFromMouse(e.button.button)
|
MultiTapDetection.InfoFromMouse(e.button.button)));
|
||||||
));
|
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Sdl.SDL_MOUSEMOTION:
|
case Sdl.SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
pendingMotion = new MouseInput(
|
pendingMotion = new MouseInput(
|
||||||
MouseInputEvent.Move,
|
MouseInputEvent.Move, lastButtonBits,
|
||||||
lastButtonBits,
|
new int2(e.motion.x, e.motion.y), mods, 0);
|
||||||
new int2( e.motion.x, e.motion.y ),
|
|
||||||
mods, 0 );
|
break;
|
||||||
} break;
|
}
|
||||||
|
|
||||||
case Sdl.SDL_KEYDOWN:
|
case Sdl.SDL_KEYDOWN:
|
||||||
{
|
{
|
||||||
@@ -118,12 +120,13 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
if (!HandleSpecialKey(keyEvent))
|
if (!HandleSpecialKey(keyEvent))
|
||||||
inputHandler.OnKeyInput(keyEvent);
|
inputHandler.OnKeyInput(keyEvent);
|
||||||
} break;
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Sdl.SDL_KEYUP:
|
case Sdl.SDL_KEYUP:
|
||||||
{
|
{
|
||||||
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
|
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
|
||||||
|
|
||||||
var keyEvent = new KeyInput
|
var keyEvent = new KeyInput
|
||||||
{
|
{
|
||||||
Event = KeyInputEvent.Up,
|
Event = KeyInputEvent.Up,
|
||||||
@@ -135,7 +138,8 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
};
|
};
|
||||||
|
|
||||||
inputHandler.OnKeyInput(keyEvent);
|
inputHandler.OnKeyInput(keyEvent);
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,12 +168,11 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
OpenRA.Game.Exit();
|
OpenRA.Game.Exit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
size = new Size(bitmap.Width, bitmap.Height);
|
size = new Size(bitmap.Width, bitmap.Height);
|
||||||
var bits = bitmap.LockBits(bitmap.Bounds(),
|
var bits = bitmap.LockBits(bitmap.Bounds(),
|
||||||
ImageLockMode.ReadOnly,
|
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
PixelFormat.Format32bppArgb);
|
|
||||||
|
|
||||||
PrepareTexture();
|
PrepareTexture();
|
||||||
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, bits.Width, bits.Height,
|
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);
|
Gl.glGetTexImage(Gl.GL_TEXTURE_2D, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
public class VertexBuffer<T> : IVertexBuffer<T>
|
public class VertexBuffer<T> : IVertexBuffer<T>
|
||||||
where T : struct
|
where T : struct
|
||||||
{
|
{
|
||||||
|
static readonly int VertexSize = Marshal.SizeOf(typeof(T));
|
||||||
int buffer;
|
int buffer;
|
||||||
static readonly int vertexSize = Marshal.SizeOf(typeof(T));
|
|
||||||
|
|
||||||
public VertexBuffer(int size)
|
public VertexBuffer(int size)
|
||||||
{
|
{
|
||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
Bind();
|
Bind();
|
||||||
Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB,
|
Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB,
|
||||||
new IntPtr(vertexSize * size),
|
new IntPtr(VertexSize * size),
|
||||||
new T[size],
|
new T[size],
|
||||||
Gl.GL_DYNAMIC_DRAW_ARB);
|
Gl.GL_DYNAMIC_DRAW_ARB);
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
Bind();
|
Bind();
|
||||||
Gl.glBufferSubDataARB(Gl.GL_ARRAY_BUFFER_ARB,
|
Gl.glBufferSubDataARB(Gl.GL_ARRAY_BUFFER_ARB,
|
||||||
IntPtr.Zero,
|
IntPtr.Zero,
|
||||||
new IntPtr(vertexSize * length),
|
new IntPtr(VertexSize * length),
|
||||||
data);
|
data);
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,9 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
{
|
{
|
||||||
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, buffer);
|
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, buffer);
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
Gl.glVertexPointer(3, Gl.GL_FLOAT, vertexSize, IntPtr.Zero);
|
Gl.glVertexPointer(3, Gl.GL_FLOAT, VertexSize, IntPtr.Zero);
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
Gl.glTexCoordPointer(4, Gl.GL_FLOAT, vertexSize, new IntPtr(12));
|
Gl.glTexCoordPointer(4, Gl.GL_FLOAT, VertexSize, new IntPtr(12));
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user