(bob) refactor input dispatch; remove public Dispatch*Input from game; (chris) fix build failures due to rebase past gecko

This commit is contained in:
Chris Forbes
2010-11-01 18:39:37 +13:00
parent 527c60daa7
commit d7d0d371c6
13 changed files with 359 additions and 325 deletions

View File

@@ -40,7 +40,7 @@ namespace OpenRA.FileFormats.Graphics
void Begin();
void End();
void Clear( Color color );
void Present();
void Present( IInputHandler inputHandler );
void DrawIndexedPrimitives( PrimitiveType type, Range<int> vertexRange, Range<int> indexRange );
void DrawIndexedPrimitives( PrimitiveType type, int vertexPool, int numPrimitives );

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
@@ -9,16 +9,33 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace OpenRA
{
public interface IInputHandler
{
void ModifierKeys( Modifiers mods );
void OnKeyInput( KeyInput input );
void OnMouseInput( MouseInput input );
}
public struct MouseInput
{
public MouseInputEvent Event;
public int2 Location;
public MouseButton Button;
public int2 Location;
public Modifiers Modifiers;
public MouseInput( MouseInputEvent ev, MouseButton button, int2 location, Modifiers mods )
{
this.Event = ev;
this.Button = button;
this.Location = location;
this.Modifiers = mods;
}
}
public enum MouseInputEvent { Down, Move, Up };

View File

@@ -45,6 +45,7 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e">
<SpecificVersion>False</SpecificVersion>
@@ -61,6 +62,7 @@
<Compile Include="FileSystem.cs" />
<Compile Include="Folder.cs" />
<Compile Include="Graphics\IGraphicsDevice.cs" />
<Compile Include="Graphics\IInputHandler.cs" />
<Compile Include="Graphics\Vertex.cs" />
<Compile Include="Manifest.cs" />
<Compile Include="MiniYaml.cs" />

View File

@@ -99,7 +99,7 @@ namespace OpenRA
using (new PerfSample("render"))
{
++RenderFrame;
viewport.DrawRegions(worldRenderer);
viewport.DrawRegions(worldRenderer, new DefaultInputHandler( orderManager.world ));
Sound.SetListenerPosition(viewport.Location + .5f * new float2(viewport.Width, viewport.Height));
}
@@ -181,37 +181,14 @@ namespace OpenRA
AfterGameStart( orderManager.world );
}
public static void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e, Modifiers modifierKeys)
{
Sync.CheckSyncUnchanged( orderManager.world, () =>
{
var mi = new MouseInput
{
Button = (MouseButton)(int)e.Button,
Event = ev,
Location = new int2( e.Location ),
Modifiers = modifierKeys,
};
Widget.HandleInput( mi );
} );
}
public static bool IsHost
{
get { return orderManager.Connection.LocalClientId == 0; }
}
public static void HandleKeyEvent(KeyInput e)
{
Sync.CheckSyncUnchanged( orderManager.world, () =>
{
Widget.HandleKeyPress( e );
} );
}
static Modifiers modifiers;
public static Modifiers GetModifierKeys() { return modifiers; }
public static void HandleModifierKeys(Modifiers mods) { modifiers = mods; }
internal static void HandleModifierKeys(Modifiers mods) { modifiers = mods; }
internal static void Initialize(Arguments args)
{

View File

@@ -92,11 +92,11 @@ namespace OpenRA.Graphics
s.Commit();
}
public void EndFrame()
public void EndFrame( IInputHandler inputHandler )
{
Flush();
device.End();
device.Present();
device.Present( inputHandler );
}
public void DrawBatch<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Graphics
this.scrollPosition = Game.CellSize* mapStart;
}
public void DrawRegions( WorldRenderer wr )
public void DrawRegions( WorldRenderer wr, IInputHandler inputHandler )
{
renderer.BeginFrame(scrollPosition);
wr.Draw();
@@ -107,7 +107,7 @@ namespace OpenRA.Graphics
var c = new Cursor(cursorName);
c.Draw(wr, (int)cursorFrame, Viewport.LastMousePos + Location);
renderer.EndFrame();
renderer.EndFrame( inputHandler );
}
public void Tick()

58
OpenRA.Game/InputHandler.cs Executable file
View File

@@ -0,0 +1,58 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenRA.Widgets;
using OpenRA.Network;
namespace OpenRA
{
public class NullInputHandler : IInputHandler
{
// ignore all input
public void ModifierKeys( Modifiers mods ) { }
public void OnKeyInput( KeyInput input ) { }
public void OnMouseInput( MouseInput input ) { }
}
public class DefaultInputHandler : IInputHandler
{
readonly World world;
public DefaultInputHandler( World world )
{
this.world = world;
}
public void ModifierKeys( Modifiers mods )
{
Game.HandleModifierKeys( mods );
}
public void OnKeyInput( KeyInput input )
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.HandleKeyPress( input );
} );
}
public void OnMouseInput( MouseInput input )
{
Sync.CheckSyncUnchanged( world, () =>
{
Widget.HandleInput( input );
} );
}
}
}

View File

@@ -139,8 +139,6 @@
<Compile Include="Graphics\SequenceProvider.cs" />
<Compile Include="Graphics\SheetBuilder.cs" />
<Compile Include="Graphics\HardwarePalette.cs" />
<Compile Include="MainWindow.cs">
</Compile>
<Compile Include="Support\Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Graphics\Renderer.cs" />
@@ -214,6 +212,7 @@
<Compile Include="ActorInitializer.cs" />
<Compile Include="ActorReference.cs" />
<Compile Include="Misc.cs" />
<Compile Include="InputHandler.cs" />
<Compile Include="ModData.cs" />
<Compile Include="Map.cs" />
<Compile Include="Network\FrameData.cs" />
@@ -257,4 +256,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@@ -1,11 +1,11 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
@@ -21,299 +21,301 @@ using Tao.Sdl;
namespace OpenRA.GlRenderer
{
public class GraphicsDevice : IGraphicsDevice
{
Size windowSize;
internal IntPtr cgContext;
internal int vertexProfile, fragmentProfile;
public class GraphicsDevice : IGraphicsDevice
{
Size windowSize;
internal IntPtr cgContext;
internal int vertexProfile, fragmentProfile;
IntPtr surf;
IntPtr surf;
public Size WindowSize { get { return windowSize; } }
public Size WindowSize { get { return windowSize; } }
public enum GlError
{
GL_NO_ERROR = Gl.GL_NO_ERROR,
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
}
public enum GlError
{
GL_NO_ERROR = Gl.GL_NO_ERROR,
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
}
internal static void CheckGlError()
{
var n = Gl.glGetError();
if (n != Gl.GL_NO_ERROR)
throw new InvalidOperationException("GL Error: " + ((GlError)n).ToString());
}
internal static void CheckGlError()
{
var n = Gl.glGetError();
if( n != Gl.GL_NO_ERROR )
throw new InvalidOperationException( "GL Error: " + ( (GlError)n ).ToString() );
}
public GraphicsDevice(int width, int height, WindowMode window, bool vsync)
{
Sdl.SDL_Init(Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 0);
public GraphicsDevice( int width, int height, WindowMode window, bool vsync )
{
Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 );
Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_ALPHA_SIZE, 0 );
int windowFlags = 0;
switch (window)
{
case WindowMode.Fullscreen:
windowFlags |= Sdl.SDL_FULLSCREEN;
break;
case WindowMode.PseudoFullscreen:
// pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else
windowFlags |= (Environment.OSVersion.Platform == PlatformID.Win32NT) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN;
Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
break;
default:
break;
}
int windowFlags = 0;
switch( window )
{
case WindowMode.Fullscreen:
windowFlags |= Sdl.SDL_FULLSCREEN;
break;
case WindowMode.PseudoFullscreen:
// pseudo-fullscreen only reliably works on windows; fall back to fullscreen for everyone else
windowFlags |= ( Environment.OSVersion.Platform == PlatformID.Win32NT ) ? Sdl.SDL_NOFRAME : Sdl.SDL_FULLSCREEN;
Environment.SetEnvironmentVariable( "SDL_VIDEO_WINDOW_POS", "0,0" );
break;
default:
break;
}
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | windowFlags);
surf = Sdl.SDL_SetVideoMode( width, height, 0, Sdl.SDL_OPENGL | windowFlags );
Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA");
Sdl.SDL_ShowCursor(0);
Sdl.SDL_EnableUNICODE(1);
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL);
Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
Sdl.SDL_ShowCursor( 0 );
Sdl.SDL_EnableUNICODE( 1 );
Sdl.SDL_EnableKeyRepeat( Sdl.SDL_DEFAULT_REPEAT_DELAY, Sdl.SDL_DEFAULT_REPEAT_INTERVAL );
CheckGlError();
CheckGlError();
windowSize = new Size(width, height);
windowSize = new Size( width, height );
cgContext = Cg.cgCreateContext();
cgContext = Cg.cgCreateContext();
Cg.cgSetErrorCallback(CgErrorCallback);
Cg.cgSetErrorCallback( CgErrorCallback );
CgGl.cgGLRegisterStates(cgContext);
CgGl.cgGLSetManageTextureParameters(cgContext, true);
vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
CgGl.cgGLRegisterStates( cgContext );
CgGl.cgGLSetManageTextureParameters( cgContext, true );
vertexProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_VERTEX );
fragmentProfile = CgGl.cgGLGetLatestProfile( CgGl.CG_GL_FRAGMENT );
//Console.WriteLine("VP Profile: " + vertexProfile);
//Console.WriteLine("FP Profile: " + fragmentProfile);
//Console.WriteLine("VP Profile: " + vertexProfile);
//Console.WriteLine("FP Profile: " + fragmentProfile);
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
CheckGlError();
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
CheckGlError();
Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY );
CheckGlError();
Gl.glEnableClientState( Gl.GL_TEXTURE_COORD_ARRAY );
CheckGlError();
Sdl.SDL_SetModState(0); // i have had enough.
}
Sdl.SDL_SetModState( 0 ); // i have had enough.
}
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
{
var err = Cg.cgGetError();
var str = Cg.cgGetErrorString(err);
throw new InvalidOperationException(
string.Format("CG Error: {0}: {1}", err, str));
};
static Cg.CGerrorCallbackFuncDelegate CgErrorCallback = () =>
{
var err = Cg.cgGetError();
var str = Cg.cgGetErrorString( err );
throw new InvalidOperationException(
string.Format( "CG Error: {0}: {1}", err, str ) );
};
public void EnableScissor(int left, int top, int width, int height)
{
if (width < 0) width = 0;
if (height < 0) height = 0;
Gl.glScissor(left, windowSize.Height - (top + height), width, height);
CheckGlError();
Gl.glEnable(Gl.GL_SCISSOR_TEST);
CheckGlError();
}
public void EnableScissor( int left, int top, int width, int height )
{
if( width < 0 ) width = 0;
if( height < 0 ) height = 0;
Gl.glScissor( left, windowSize.Height - ( top + height ), width, height );
CheckGlError();
Gl.glEnable( Gl.GL_SCISSOR_TEST );
CheckGlError();
}
public void DisableScissor()
{
Gl.glDisable(Gl.GL_SCISSOR_TEST);
CheckGlError();
}
public void DisableScissor()
{
Gl.glDisable( Gl.GL_SCISSOR_TEST );
CheckGlError();
}
public void Begin() { }
public void End() { }
public void Begin() { }
public void End() { }
public void Clear(Color c)
{
Gl.glClearColor(0, 0, 0, 0);
CheckGlError();
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
CheckGlError();
}
public void Clear( Color c )
{
Gl.glClearColor( 0, 0, 0, 0 );
CheckGlError();
Gl.glClear( Gl.GL_COLOR_BUFFER_BIT );
CheckGlError();
}
MouseButtons lastButtonBits = (MouseButtons)0;
MouseButton lastButtonBits = (MouseButton)0;
static MouseButtons MakeButton(byte b)
{
return b == Sdl.SDL_BUTTON_LEFT ? MouseButtons.Left
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButtons.Right
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButtons.Middle
: 0;
}
static MouseButton MakeButton( byte b )
{
return b == Sdl.SDL_BUTTON_LEFT ? MouseButton.Left
: b == Sdl.SDL_BUTTON_RIGHT ? MouseButton.Right
: b == Sdl.SDL_BUTTON_MIDDLE ? MouseButton.Middle
: 0;
}
static Modifiers MakeModifiers(int raw)
{
return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
| ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
}
static Modifiers MakeModifiers( int raw )
{
return ( ( raw & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
| ( ( raw & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
| ( ( raw & Sdl.KMOD_SHIFT ) != 0 ? Modifiers.Shift : 0 );
}
bool HandleSpecialKey(KeyInput k)
{
switch (k.VirtKey)
{
case Sdl.SDLK_F13:
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString("OpenRA-yyyy-MM-ddThhmmssZ") + ".bmp";
Sdl.SDL_SaveBMP(surf, path);
return true;
bool HandleSpecialKey( KeyInput k )
{
switch( k.VirtKey )
{
case Sdl.SDLK_F13:
var path = Environment.GetFolderPath( Environment.SpecialFolder.Personal )
+ Path.DirectorySeparatorChar + DateTime.UtcNow.ToString( "OpenRA-yyyy-MM-ddThhmmssZ" ) + ".bmp";
Sdl.SDL_SaveBMP( surf, path );
return true;
case Sdl.SDLK_F4:
if (k.Modifiers.HasModifier(Modifiers.Alt))
{
OpenRA.Game.Exit();
return true;
}
return false;
case Sdl.SDLK_F4:
if( k.Modifiers.HasModifier( Modifiers.Alt ) )
{
OpenRA.Game.Exit();
return true;
}
return false;
default:
return false;
}
}
default:
return false;
}
}
public void Present()
{
Sdl.SDL_GL_SwapBuffers();
Game.HasInputFocus = 0 != (Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS);
var mods = MakeModifiers(Sdl.SDL_GetModState());
Game.HandleModifierKeys(mods);
MouseEventArgs pendingMotion = null;
public void Present( IInputHandler inputHandler )
{
Sdl.SDL_GL_SwapBuffers();
Game.HasInputFocus = 0 != ( Sdl.SDL_GetAppState() & Sdl.SDL_APPINPUTFOCUS );
Sdl.SDL_Event e;
while (Sdl.SDL_PollEvent(out e) != 0)
{
switch (e.type)
{
case Sdl.SDL_QUIT:
OpenRA.Game.Exit();
break;
var mods = MakeModifiers( Sdl.SDL_GetModState() );
inputHandler.ModifierKeys( mods );
MouseInput? pendingMotion = null;
case Sdl.SDL_MOUSEBUTTONDOWN:
{
if (pendingMotion != null)
{
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
pendingMotion = null;
}
Sdl.SDL_Event e;
while( Sdl.SDL_PollEvent( out e ) != 0 )
{
switch( e.type )
{
case Sdl.SDL_QUIT:
OpenRA.Game.Exit();
break;
var button = MakeButton(e.button.button);
lastButtonBits |= button;
case Sdl.SDL_MOUSEBUTTONDOWN:
{
if( pendingMotion != null )
{
inputHandler.OnMouseInput( pendingMotion.Value );
pendingMotion = null;
}
Game.DispatchMouseInput(MouseInputEvent.Down,
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
mods);
} break;
var button = MakeButton( e.button.button );
lastButtonBits |= button;
case Sdl.SDL_MOUSEBUTTONUP:
{
if (pendingMotion != null)
{
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
pendingMotion = null;
}
inputHandler.OnMouseInput( new MouseInput(
MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods ) );
} break;
var button = MakeButton(e.button.button);
lastButtonBits &= ~button;
case Sdl.SDL_MOUSEBUTTONUP:
{
if( pendingMotion != null )
{
inputHandler.OnMouseInput( pendingMotion.Value );
pendingMotion = null;
}
Game.DispatchMouseInput(MouseInputEvent.Up,
new MouseEventArgs(button, 1, e.button.x, e.button.y, 0),
mods);
} break;
var button = MakeButton( e.button.button );
lastButtonBits &= ~button;
case Sdl.SDL_MOUSEMOTION:
{
pendingMotion = new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0);
} break;
inputHandler.OnMouseInput( new MouseInput(
MouseInputEvent.Up, button, new int2( e.button.x, e.button.y ), mods ) );
} break;
case Sdl.SDL_KEYDOWN:
{
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Down,
Modifiers = mods,
KeyChar = (char)e.key.keysym.unicode,
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
};
case Sdl.SDL_MOUSEMOTION:
{
pendingMotion = new MouseInput(
MouseInputEvent.Move,
lastButtonBits,
new int2( e.motion.x, e.motion.y ),
mods );
} break;
if (!HandleSpecialKey(keyEvent))
Game.HandleKeyEvent(keyEvent);
} break;
case Sdl.SDL_KEYDOWN:
{
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Down,
Modifiers = mods,
KeyChar = (char)e.key.keysym.unicode,
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
VirtKey = e.key.keysym.sym
};
case Sdl.SDL_KEYUP:
{
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Up,
Modifiers = mods,
KeyChar = (char)e.key.keysym.unicode,
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
};
if( !HandleSpecialKey( keyEvent ) )
inputHandler.OnKeyInput( keyEvent );
} break;
Game.HandleKeyEvent(keyEvent);
} break;
}
}
case Sdl.SDL_KEYUP:
{
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Up,
Modifiers = mods,
KeyChar = (char)e.key.keysym.unicode,
KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ),
VirtKey = e.key.keysym.sym
};
if (pendingMotion != null)
{
Game.DispatchMouseInput(MouseInputEvent.Move, pendingMotion, mods);
pendingMotion = null;
}
inputHandler.OnKeyInput( keyEvent );
} break;
}
}
CheckGlError();
}
if( pendingMotion != null )
{
inputHandler.OnMouseInput( pendingMotion.Value );
pendingMotion = null;
}
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
{
Gl.glDrawElements(ModeFromPrimitiveType(pt), indices.End - indices.Start,
Gl.GL_UNSIGNED_SHORT, new IntPtr(indices.Start * 2));
CheckGlError();
}
CheckGlError();
}
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
{
Gl.glDrawElements(ModeFromPrimitiveType(pt), numPrimitives * IndicesPerPrimitive(pt),
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero);
CheckGlError();
}
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
{
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
Gl.GL_UNSIGNED_SHORT, new IntPtr( indices.Start * 2 ) );
CheckGlError();
}
static int ModeFromPrimitiveType(PrimitiveType pt)
{
switch (pt)
{
case PrimitiveType.PointList: return Gl.GL_POINTS;
case PrimitiveType.LineList: return Gl.GL_LINES;
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
}
throw new NotImplementedException();
}
public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives )
{
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero );
CheckGlError();
}
static int IndicesPerPrimitive(PrimitiveType pt)
{
switch (pt)
{
case PrimitiveType.PointList: return 1;
case PrimitiveType.LineList: return 2;
case PrimitiveType.TriangleList: return 3;
}
throw new NotImplementedException();
}
static int ModeFromPrimitiveType( PrimitiveType pt )
{
switch( pt )
{
case PrimitiveType.PointList: return Gl.GL_POINTS;
case PrimitiveType.LineList: return Gl.GL_LINES;
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
}
throw new NotImplementedException();
}
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new VertexBuffer<Vertex>(this, size); }
public IIndexBuffer CreateIndexBuffer(int size) { return new IndexBuffer(this, size); }
public ITexture CreateTexture() { return new Texture(this); }
public ITexture CreateTexture(Bitmap bitmap) { return new Texture(this, bitmap); }
public IShader CreateShader(Stream stream) { return new Shader(this, stream); }
}
static int IndicesPerPrimitive( PrimitiveType pt )
{
switch( pt )
{
case PrimitiveType.PointList: return 1;
case PrimitiveType.LineList: return 2;
case PrimitiveType.TriangleList: return 3;
}
throw new NotImplementedException();
}
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( this, size ); }
public IIndexBuffer CreateIndexBuffer( int size ) { return new IndexBuffer( this, size ); }
public ITexture CreateTexture() { return new Texture( this ); }
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); }
public IShader CreateShader( Stream stream ) { return new Shader( this, stream ); }
}
}

View File

@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Cnc
r.BeginFrame(float2.Zero);
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame();
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame( new NullInputHandler() );
}
}
}

View File

@@ -19,9 +19,9 @@ namespace OpenRA.Mods.RA
return;
// Draw a black screen
Game.Renderer.BeginFrame(float2.Zero);
Game.Renderer.EndFrame();
}
Game.Renderer.BeginFrame(float2.Zero);
Game.Renderer.EndFrame( new NullInputHandler() );
}
}
}

View File

@@ -64,8 +64,8 @@ namespace OpenRA.Mods.RA
r.BeginFrame(float2.Zero);
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame();
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame( new NullInputHandler() );
}
}
}

View File

@@ -1,10 +1,8 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using OpenRA.FileFormats.Graphics;
using OpenRA.Graphics;
[assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))]
namespace OpenRA.Renderer.Null
@@ -18,42 +16,23 @@ namespace OpenRA.Renderer.Null
WindowSize = new Size(width, height);
}
public void EnableScissor(int left, int top, int width, int height)
{
}
public void DisableScissor()
{
}
public void EnableScissor(int left, int top, int width, int height) { }
public void DisableScissor() { }
public void Begin() { }
public void End() { }
public void Clear(Color c) { }
public void Clear(Color c)
{
}
public void Present()
public void Present(IInputHandler ih)
{
Game.HasInputFocus = false;
Game.HandleModifierKeys(Modifiers.None);
ih.ModifierKeys(Modifiers.None);
}
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices)
{
}
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives)
{
}
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
{
return new NullVertexBuffer<Vertex>();
}
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices) { }
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { }
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new NullVertexBuffer<Vertex>(); }
public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); }
public ITexture CreateTexture() { return new NullTexture(); }
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }