Completed work for RecordingKeyboard, updated sample Game.

This commit is contained in:
SND\simsmaster_cp 2012-01-02 16:45:51 +00:00
parent 70c5870e28
commit 900404c333
3 changed files with 49 additions and 25 deletions

View File

@ -113,6 +113,7 @@ namespace ANX.InputSystem.Recording
if (RecordingState != RecordingState.Recording)
throw new InvalidOperationException("Recording wasn't started for this device!");
nullStateCounter = 0;
RecordingState = RecordingState.None;
}
@ -155,6 +156,7 @@ namespace ANX.InputSystem.Recording
{
recordStream.WriteByte((byte)PacketType.NullFrameCounter);
recordStream.Write(BitConverter.GetBytes(nullStateCounter), 0, 4);
nullStateCounter = 0;
}
recordStream.WriteByte((byte)PacketType.InputData);
@ -198,11 +200,13 @@ namespace ANX.InputSystem.Recording
}
/// <summary>
/// Fires the EndOfPlaybackReaced event. Overwrite this method to change
/// this behavoir.
/// Fires the EndOfPlaybackReaced event and Calls StopPlayback().
/// Overwrite this method to change this behavoir.
/// </summary>
protected virtual void OnEndOfPlaybackReached()
{
StopPlayback();
if (EndOfPlaybackReached != null)
EndOfPlaybackReached(this, EventArgs.Empty);
}

View File

@ -140,7 +140,7 @@ namespace ANX.InputSystem.Recording
{
for (int j = 0; j < 8; j++)
{
if (i == PacketLenght - 1 && j == (i + 2) % 8)
if (i == PacketLenght - 1 && j == recordedKeys.Length % 8)
break;
if (state.IsKeyDown(recordedKeys[i * 8 + j]))
@ -156,18 +156,18 @@ namespace ANX.InputSystem.Recording
byte[] buffer = ReadState();
if (buffer == null)
return new KeyboardState();
return new KeyboardState(new Keys[0]);
if ((PlayerIndex)(buffer[0] & 3) != expectedIndex)
throw new InvalidOperationException("The requested playerIndex does no match the next recorded state. Refer to documetation.");
KeyboardState state = new KeyboardState();
KeyboardState state = new KeyboardState(new Keys[0]);
for (int i = 0; i < PacketLenght; i++)
{
for (int j = 0; j < 8; j++)
{
if (i == PacketLenght - 1 && j == (i + 2) % 8)
if (i == PacketLenght - 1 && j == recordedKeys.Length % 8)
break;
if ((buffer[i] & keyBitmasks[i * 8 + j]) != 0)

View File

@ -70,6 +70,9 @@ namespace RecordingSample
Texture2D logo;
KeyboardState oldState;
RecordingMouse recMouse;
RecordingKeyboard recKeyboard;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
@ -80,8 +83,11 @@ namespace RecordingSample
{
Window.Title = "Use Mouse to move arround, press r to record, p for playback and n for none";
//We know the Mouse is a RecordingMouse - this is quite ugly... could this be improved?
((RecordingMouse)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse).Initialize(MouseRecordInfo.Position);
//this is quite ugly... could this be improved?
recMouse = ((RecordingMouse)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse);
recMouse.Initialize(MouseRecordInfo.Position);
recKeyboard = ((RecordingKeyboard)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard);
recKeyboard.Initialize(Keys.Enter);
base.Initialize();
}
@ -91,32 +97,42 @@ 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))
{
recMouse.StartRecording();
recKeyboard.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 (recMouse.RecordingState == RecordingState.Recording)
recMouse.StopRecording();
recMouse.StartPlayback();
//if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
//{
// if (mouse.RecordingState == RecordingState.Recording)
// mouse.StartRecording();
if (recKeyboard.RecordingState == RecordingState.Recording)
recKeyboard.StopRecording();
recKeyboard.StartPlayback();
}
// mouse.StopPlayback();
//}
if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
{
if (recMouse.RecordingState == RecordingState.Recording)
recMouse.StopRecording();
recMouse.StopPlayback();
//oldState = newState;
if (recKeyboard.RecordingState == RecordingState.Recording)
recKeyboard.StopRecording();
recKeyboard.StopPlayback();
}
oldState = newState;
base.Update(gameTime);
}
@ -125,6 +141,10 @@ namespace RecordingSample
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
if(Keyboard.GetState().IsKeyDown(Keys.Enter))
spriteBatch.Draw(logo, Vector2.Zero, Color.White);
spriteBatch.End();
spriteBatch.Begin();
spriteBatch.Draw(logo, new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 115, 30), Color.White);
spriteBatch.End();