2014-01-11 15:05:41 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-12-01 20:55:52 +00:00
|
|
|
|
using System.Linq;
|
2013-12-07 01:50:52 +00:00
|
|
|
|
|
2013-12-01 20:55:52 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
2013-12-07 17:29:47 +00:00
|
|
|
|
public class MovieRecord
|
2013-12-01 20:55:52 +00:00
|
|
|
|
{
|
2013-12-09 17:24:32 +00:00
|
|
|
|
private byte[] _state = new byte[0];
|
2013-12-07 17:29:47 +00:00
|
|
|
|
private Dictionary<string, bool> _boolButtons = new Dictionary<string, bool>();
|
2013-12-06 15:47:23 +00:00
|
|
|
|
|
2013-12-07 21:37:52 +00:00
|
|
|
|
public MovieRecord(Dictionary<string, bool> buttons, bool captureState)
|
2013-12-07 17:29:47 +00:00
|
|
|
|
{
|
2013-12-07 21:37:52 +00:00
|
|
|
|
SetInput(buttons);
|
2013-12-07 17:29:47 +00:00
|
|
|
|
if (captureState)
|
|
|
|
|
{
|
2013-12-14 20:32:00 +00:00
|
|
|
|
CaptureSate();
|
2013-12-07 17:29:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:37:52 +00:00
|
|
|
|
public Dictionary<string, bool> Buttons
|
2013-12-07 17:29:47 +00:00
|
|
|
|
{
|
2013-12-07 21:37:52 +00:00
|
|
|
|
get { return _boolButtons; }
|
2013-12-06 18:27:06 +00:00
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
|
|
|
|
public bool Lagged { get; private set; }
|
2013-12-07 21:37:52 +00:00
|
|
|
|
|
2013-12-09 21:40:27 +00:00
|
|
|
|
#region Input Api
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
2013-12-07 17:29:47 +00:00
|
|
|
|
public bool IsPressed(string buttonName)
|
2013-12-06 18:27:06 +00:00
|
|
|
|
{
|
2013-12-07 17:29:47 +00:00
|
|
|
|
return _boolButtons[buttonName];
|
2013-12-06 18:27:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:37:52 +00:00
|
|
|
|
public void SetButton(string button, bool pressed)
|
|
|
|
|
{
|
2014-01-11 15:05:41 +00:00
|
|
|
|
InputChanged(new Dictionary<string, bool> { { button, pressed } });
|
2013-12-07 21:37:52 +00:00
|
|
|
|
_boolButtons[button] = pressed;
|
|
|
|
|
}
|
2013-12-07 01:50:52 +00:00
|
|
|
|
|
2013-12-07 21:37:52 +00:00
|
|
|
|
public void SetInput(Dictionary<string, bool> buttons)
|
2013-12-01 20:55:52 +00:00
|
|
|
|
{
|
2013-12-09 21:40:27 +00:00
|
|
|
|
InputChanged(buttons);
|
2013-12-07 17:29:47 +00:00
|
|
|
|
_boolButtons.Clear();
|
2013-12-07 21:37:52 +00:00
|
|
|
|
_boolButtons = buttons;
|
2013-12-06 15:47:23 +00:00
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
2013-12-14 20:32:00 +00:00
|
|
|
|
public void CaptureSate()
|
|
|
|
|
{
|
|
|
|
|
Lagged = Global.Emulator.IsLagFrame;
|
2013-12-23 20:34:02 +00:00
|
|
|
|
_state = (byte[])Global.Emulator.SaveStateBinary().Clone();
|
2013-12-14 20:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 15:47:23 +00:00
|
|
|
|
public void ClearInput()
|
|
|
|
|
{
|
2013-12-09 21:40:27 +00:00
|
|
|
|
InputChanged(_boolButtons);
|
2013-12-07 17:29:47 +00:00
|
|
|
|
_boolButtons.Clear();
|
2013-12-06 15:47:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 21:40:27 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region State API
|
|
|
|
|
|
|
|
|
|
public IEnumerable<byte> State
|
2013-12-09 17:24:32 +00:00
|
|
|
|
{
|
2013-12-09 21:40:27 +00:00
|
|
|
|
get { return _state; }
|
2013-12-09 17:24:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 15:47:23 +00:00
|
|
|
|
public bool HasState
|
|
|
|
|
{
|
2013-12-07 21:37:52 +00:00
|
|
|
|
get { return State.Any(); }
|
2013-12-03 01:43:02 +00:00
|
|
|
|
}
|
2013-12-09 21:40:27 +00:00
|
|
|
|
|
|
|
|
|
public void ClearState()
|
|
|
|
|
{
|
|
|
|
|
_state = new byte[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Event Handling
|
|
|
|
|
|
|
|
|
|
public class InputEventArgs
|
|
|
|
|
{
|
|
|
|
|
public InputEventArgs(Dictionary<string, bool> editedButtons)
|
|
|
|
|
{
|
|
|
|
|
EditedButtons = editedButtons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, bool> EditedButtons { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public delegate void InputEventHandler(object sender, InputEventArgs e);
|
|
|
|
|
public event InputEventHandler OnChanged;
|
|
|
|
|
|
2014-01-11 15:05:41 +00:00
|
|
|
|
private void InputChanged(Dictionary<string, bool> editedButtons)
|
2013-12-09 21:40:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (OnChanged != null)
|
|
|
|
|
{
|
|
|
|
|
OnChanged(this, new InputEventArgs(editedButtons));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-12-01 20:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|