Modified the RecordingSystem to work with the new InputSystem. Fixes #532

This commit is contained in:
SND\simsmaster_cp 2011-12-20 20:16:50 +00:00
parent dfa2a4665a
commit a5dbfb721a
5 changed files with 70 additions and 34 deletions

View File

@ -58,12 +58,20 @@ namespace ANX.InputSystem.Recording
{
public class Creator : IInputSystemCreator
{
//It not a good idea to have more than one RecordingDevice per Input Device, so we cache the request.
RecordingMouse mouse;
RecordingKeyboard keyboard;
RecordingGamePad gamePad;
RecordingMotionSensingDevice msd;
public IGamePad GamePad
{
get
{
AddInSystemFactory.Instance.PreventInputSystemChange();
return new RecordingGamePad();
if (gamePad == null)
gamePad = new RecordingGamePad();
return gamePad;
}
}
@ -72,7 +80,9 @@ namespace ANX.InputSystem.Recording
get
{
AddInSystemFactory.Instance.PreventInputSystemChange();
return new RecordingMouse();
if (mouse == null)
mouse = new RecordingMouse();
return mouse;
}
}
@ -81,7 +91,9 @@ namespace ANX.InputSystem.Recording
get
{
AddInSystemFactory.Instance.PreventInputSystemChange();
return new RecordingKeyboard();
if (keyboard == null)
keyboard = new RecordingKeyboard();
return keyboard;
}
}
@ -91,7 +103,9 @@ namespace ANX.InputSystem.Recording
get
{
AddInSystemFactory.Instance.PreventInputSystemChange();
return new RecordingMotionSensingDevice();
if (msd == null)
msd = new RecordingMotionSensingDevice();
return msd;
}
}
#endif

View File

@ -99,14 +99,31 @@ namespace ANX.InputSystem.Recording
protected IMouse realMouse;
protected MouseRecordInfo recordInfo;
private IntPtr tmpWindowHandle = IntPtr.Zero;
public IntPtr WindowHandle
{
get { return realMouse.WindowHandle; }
set { realMouse.WindowHandle = value; }
get
{
if (!isInitialized)
return IntPtr.Zero;
else
return realMouse.WindowHandle;
}
set
{
if (!isInitialized) //The GameWindow might assign a WindowHadle even before the real Mouse is loaded. We save this Handle and assign it in Initialize()
tmpWindowHandle = value;
else
realMouse.WindowHandle = value;
}
}
public MouseState GetState() //The main recording/playback logic is placed here
{
if (!isInitialized)
throw new InvalidOperationException("This instance is not initialized! Refer to documenation for details.");
switch (RecordingState)
{
case RecordingState.None:
@ -216,7 +233,7 @@ namespace ANX.InputSystem.Recording
/// </summary>
public void Initialize(MouseRecordInfo info)
{
this.Initialize(info, new MemoryStream(), AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse);
this.Initialize(info, new MemoryStream(), InputDeviceFactory.Instance.GetDefaultMouse());
}
/// <summary>
@ -234,7 +251,7 @@ namespace ANX.InputSystem.Recording
/// </summary>
public void Initialize(MouseRecordInfo info, Stream bufferStream)
{
this.Initialize(info, bufferStream, AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse);
this.Initialize(info, bufferStream, InputDeviceFactory.Instance.GetDefaultMouse());
}
/// <summary>
@ -245,6 +262,9 @@ namespace ANX.InputSystem.Recording
{
realMouse = mouse;
if (tmpWindowHandle != IntPtr.Zero)
WindowHandle = tmpWindowHandle;
recordInfo = info;
PacketLenght = GetPaketSize(info);

View File

@ -68,7 +68,6 @@ namespace RecordingSample
SpriteBatch spriteBatch;
Texture2D logo;
RecordingMouse mouse;
KeyboardState oldState;
public Game1()
@ -81,10 +80,8 @@ namespace RecordingSample
{
Window.Title = "Use Mouse to move arround, press r to record, p for playback and n for none";
mouse = (RecordingMouse)AddInSystemFactory.Instance.GetCreator<IInputSystemCreator>("Recording").Mouse;
mouse.Initialize(MouseRecordInfo.Position);
mouse.WindowHandle = Window.Handle;
mouse.EndOfPlaybackReached += new EventHandler((sender, args) => mouse.StopPlayback());
//We know the Mouse is a RecordingMouse - this is quite ugly... could this be improved?
((RecordingMouse)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse).Initialize(MouseRecordInfo.Position);
base.Initialize();
}
@ -94,32 +91,32 @@ namespace RecordingSample
spriteBatch = new SpriteBatch(GraphicsDevice);
logo = Content.Load<Texture2D>(@"Textures/ANX.Framework.Logo_459x121");
oldState = Keyboard.GetState();
//oldState = Keyboard.GetState();
}
protected override void Update(GameTime gameTime)
{
KeyboardState newState = Keyboard.GetState();
//KeyboardState newState = Keyboard.GetState();
if (oldState.IsKeyUp(Keys.R) && newState.IsKeyDown(Keys.R))
mouse.StartRecording();
//if (oldState.IsKeyUp(Keys.R) && newState.IsKeyDown(Keys.R))
// mouse.StartRecording();
if (oldState.IsKeyUp(Keys.P) && newState.IsKeyDown(Keys.P))
{
if (mouse.RecordingState == RecordingState.Recording)
mouse.StopRecording();
mouse.StartPlayback();
}
//if (oldState.IsKeyUp(Keys.P) && newState.IsKeyDown(Keys.P))
//{
// if (mouse.RecordingState == RecordingState.Recording)
// mouse.StopRecording();
// mouse.StartPlayback();
//}
if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
{
if (mouse.RecordingState == RecordingState.Recording)
mouse.StartRecording();
//if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
//{
// if (mouse.RecordingState == RecordingState.Recording)
// mouse.StartRecording();
mouse.StopPlayback();
}
// mouse.StopPlayback();
//}
oldState = newState;
//oldState = newState;
base.Update(gameTime);
}
@ -129,7 +126,7 @@ namespace RecordingSample
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(logo, new Rectangle(mouse.GetState().X, mouse.GetState().Y, 115, 30), Color.White);
spriteBatch.Draw(logo, new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 115, 30), Color.White);
spriteBatch.End();
base.Draw(gameTime);

View File

@ -1,15 +1,16 @@
using System;
using ANX.Framework.NonXNA;
namespace RecordingSample
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
static void Main(string[] args)
{
//This is technically unessasary, because there is only a reference to the RecordingSystem...
AddInSystemFactory.Instance.PreferredInputSystem = "Recording";
using (Game1 game = new Game1())
{
game.Run();

View File

@ -83,6 +83,10 @@
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
<Name>ANX.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputDevices.Windows.XInput\ANX.InputDevices.Windows.XInput.csproj">
<Project>{60D08399-244F-46A3-91F1-4CFD26D961A3}</Project>
<Name>ANX.InputDevices.Windows.XInput</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputSystem.Recording\ANX.InputSystem.Recording.csproj">
<Project>{DB88DDEB-7281-405D-8FCA-5681B6B2BD7A}</Project>
<Name>ANX.InputSystem.Recording</Name>