Completed work for RecordingKeyboard, updated sample Game.
This commit is contained in:
parent
70c5870e28
commit
900404c333
@ -113,6 +113,7 @@ namespace ANX.InputSystem.Recording
|
|||||||
if (RecordingState != RecordingState.Recording)
|
if (RecordingState != RecordingState.Recording)
|
||||||
throw new InvalidOperationException("Recording wasn't started for this device!");
|
throw new InvalidOperationException("Recording wasn't started for this device!");
|
||||||
|
|
||||||
|
nullStateCounter = 0;
|
||||||
RecordingState = RecordingState.None;
|
RecordingState = RecordingState.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +156,7 @@ namespace ANX.InputSystem.Recording
|
|||||||
{
|
{
|
||||||
recordStream.WriteByte((byte)PacketType.NullFrameCounter);
|
recordStream.WriteByte((byte)PacketType.NullFrameCounter);
|
||||||
recordStream.Write(BitConverter.GetBytes(nullStateCounter), 0, 4);
|
recordStream.Write(BitConverter.GetBytes(nullStateCounter), 0, 4);
|
||||||
|
nullStateCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
recordStream.WriteByte((byte)PacketType.InputData);
|
recordStream.WriteByte((byte)PacketType.InputData);
|
||||||
@ -198,11 +200,13 @@ namespace ANX.InputSystem.Recording
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires the EndOfPlaybackReaced event. Overwrite this method to change
|
/// Fires the EndOfPlaybackReaced event and Calls StopPlayback().
|
||||||
/// this behavoir.
|
/// Overwrite this method to change this behavoir.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnEndOfPlaybackReached()
|
protected virtual void OnEndOfPlaybackReached()
|
||||||
{
|
{
|
||||||
|
StopPlayback();
|
||||||
|
|
||||||
if (EndOfPlaybackReached != null)
|
if (EndOfPlaybackReached != null)
|
||||||
EndOfPlaybackReached(this, EventArgs.Empty);
|
EndOfPlaybackReached(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ namespace ANX.InputSystem.Recording
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
if (i == PacketLenght - 1 && j == (i + 2) % 8)
|
if (i == PacketLenght - 1 && j == recordedKeys.Length % 8)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (state.IsKeyDown(recordedKeys[i * 8 + j]))
|
if (state.IsKeyDown(recordedKeys[i * 8 + j]))
|
||||||
@ -156,18 +156,18 @@ namespace ANX.InputSystem.Recording
|
|||||||
byte[] buffer = ReadState();
|
byte[] buffer = ReadState();
|
||||||
|
|
||||||
if (buffer == null)
|
if (buffer == null)
|
||||||
return new KeyboardState();
|
return new KeyboardState(new Keys[0]);
|
||||||
|
|
||||||
if ((PlayerIndex)(buffer[0] & 3) != expectedIndex)
|
if ((PlayerIndex)(buffer[0] & 3) != expectedIndex)
|
||||||
throw new InvalidOperationException("The requested playerIndex does no match the next recorded state. Refer to documetation.");
|
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 i = 0; i < PacketLenght; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
if (i == PacketLenght - 1 && j == (i + 2) % 8)
|
if (i == PacketLenght - 1 && j == recordedKeys.Length % 8)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((buffer[i] & keyBitmasks[i * 8 + j]) != 0)
|
if ((buffer[i] & keyBitmasks[i * 8 + j]) != 0)
|
||||||
|
@ -70,6 +70,9 @@ namespace RecordingSample
|
|||||||
Texture2D logo;
|
Texture2D logo;
|
||||||
KeyboardState oldState;
|
KeyboardState oldState;
|
||||||
|
|
||||||
|
RecordingMouse recMouse;
|
||||||
|
RecordingKeyboard recKeyboard;
|
||||||
|
|
||||||
public Game1()
|
public Game1()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
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";
|
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?
|
//this is quite ugly... could this be improved?
|
||||||
((RecordingMouse)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse).Initialize(MouseRecordInfo.Position);
|
recMouse = ((RecordingMouse)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse);
|
||||||
|
recMouse.Initialize(MouseRecordInfo.Position);
|
||||||
|
recKeyboard = ((RecordingKeyboard)AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard);
|
||||||
|
recKeyboard.Initialize(Keys.Enter);
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
@ -91,32 +97,42 @@ namespace RecordingSample
|
|||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
|
||||||
logo = Content.Load<Texture2D>(@"Textures/ANX.Framework.Logo_459x121");
|
logo = Content.Load<Texture2D>(@"Textures/ANX.Framework.Logo_459x121");
|
||||||
//oldState = Keyboard.GetState();
|
oldState = Keyboard.GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
//KeyboardState newState = Keyboard.GetState();
|
KeyboardState newState = Keyboard.GetState();
|
||||||
|
|
||||||
//if (oldState.IsKeyUp(Keys.R) && newState.IsKeyDown(Keys.R))
|
if (oldState.IsKeyUp(Keys.R) && newState.IsKeyDown(Keys.R))
|
||||||
// mouse.StartRecording();
|
{
|
||||||
|
recMouse.StartRecording();
|
||||||
|
recKeyboard.StartRecording();
|
||||||
|
}
|
||||||
|
|
||||||
//if (oldState.IsKeyUp(Keys.P) && newState.IsKeyDown(Keys.P))
|
if (oldState.IsKeyUp(Keys.P) && newState.IsKeyDown(Keys.P))
|
||||||
//{
|
{
|
||||||
// if (mouse.RecordingState == RecordingState.Recording)
|
if (recMouse.RecordingState == RecordingState.Recording)
|
||||||
// mouse.StopRecording();
|
recMouse.StopRecording();
|
||||||
// mouse.StartPlayback();
|
recMouse.StartPlayback();
|
||||||
//}
|
|
||||||
|
|
||||||
//if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N))
|
if (recKeyboard.RecordingState == RecordingState.Recording)
|
||||||
//{
|
recKeyboard.StopRecording();
|
||||||
// if (mouse.RecordingState == RecordingState.Recording)
|
recKeyboard.StartPlayback();
|
||||||
// mouse.StartRecording();
|
}
|
||||||
|
|
||||||
// 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);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
@ -125,6 +141,10 @@ namespace RecordingSample
|
|||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
|
spriteBatch.Begin();
|
||||||
|
if(Keyboard.GetState().IsKeyDown(Keys.Enter))
|
||||||
|
spriteBatch.Draw(logo, Vector2.Zero, Color.White);
|
||||||
|
spriteBatch.End();
|
||||||
spriteBatch.Begin();
|
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();
|
spriteBatch.End();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user