2013-12-01 20:55:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2013-12-07 01:50:52 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
2013-12-01 20:55:52 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
2013-12-02 04:24:45 +00:00
|
|
|
|
public class MovieRecord : IMovieRecord
|
2013-12-01 20:55:52 +00:00
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
Dictionary<string, bool> BoolButtons = new Dictionary<string, bool>();
|
2013-12-06 15:47:23 +00:00
|
|
|
|
private byte[] _state;
|
|
|
|
|
|
2013-12-06 18:27:06 +00:00
|
|
|
|
public string Input
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
SimpleController controller = new SimpleController { Type = new ControllerDefinition() };
|
|
|
|
|
foreach (var kvp in BoolButtons)
|
|
|
|
|
{
|
|
|
|
|
controller["P1 " + kvp.Key] = kvp.Value; // TODO: multi-player, all cores
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.Type.Name = Global.Emulator.ControllerDefinition.Name;
|
|
|
|
|
MnemonicsGenerator mg = new MnemonicsGenerator();
|
|
|
|
|
mg.SetSource(controller);
|
|
|
|
|
return mg.GetControllersAsMnemonic();
|
2013-12-06 18:27:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
|
|
|
|
public bool Lagged { get; private set; }
|
|
|
|
|
public IEnumerable<byte> State
|
|
|
|
|
{
|
|
|
|
|
get { return _state; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 18:27:06 +00:00
|
|
|
|
public bool IsPressed(int player, string mnemonic)
|
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
return BoolButtons[mnemonic]; // TODO: player
|
2013-12-06 18:27:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 01:50:52 +00:00
|
|
|
|
|
|
|
|
|
public void SetInput(IController controller)
|
2013-12-01 20:55:52 +00:00
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
var mnemonics = MnemonicConstants.BUTTONS[Global.Emulator.Controller.Type.Name].Select(x => x.Value);
|
|
|
|
|
foreach (var mnemonic in mnemonics)
|
|
|
|
|
{
|
|
|
|
|
BoolButtons[mnemonic] = controller["P1 " + mnemonic]; // TODO: doesn't work on every core, can't do multiplayer
|
|
|
|
|
}
|
2013-12-06 15:47:23 +00:00
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
|
2013-12-06 15:47:23 +00:00
|
|
|
|
public void ClearInput()
|
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
foreach (var key in BoolButtons.Keys)
|
|
|
|
|
{
|
|
|
|
|
BoolButtons[key] = false;
|
|
|
|
|
}
|
2013-12-06 15:47:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 01:50:52 +00:00
|
|
|
|
public MovieRecord(IController controller, bool captureState)
|
2013-12-06 15:47:23 +00:00
|
|
|
|
{
|
2013-12-07 01:50:52 +00:00
|
|
|
|
SetInput(controller);
|
|
|
|
|
|
2013-12-06 15:47:23 +00:00
|
|
|
|
if (captureState)
|
|
|
|
|
{
|
|
|
|
|
Lagged = Global.Emulator.IsLagFrame;
|
|
|
|
|
_state = Global.Emulator.SaveStateBinary();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasState
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return State.Count() > 0;
|
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
}
|
2013-12-02 04:24:45 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
//TODO: consider the fileformat of binary and lagged data
|
|
|
|
|
return Input;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MovieRecordList : List<MovieRecord>
|
|
|
|
|
{
|
2013-12-02 14:59:38 +00:00
|
|
|
|
public MovieRecordList()
|
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
|
2013-12-04 03:04:29 +00:00
|
|
|
|
}
|
2013-12-02 14:59:38 +00:00
|
|
|
|
|
2013-12-02 04:24:45 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
2013-12-02 14:59:38 +00:00
|
|
|
|
sb
|
|
|
|
|
.AppendLine("[Input]")
|
2013-12-04 03:04:29 +00:00
|
|
|
|
|
2013-12-04 00:31:50 +00:00
|
|
|
|
.Append("Frame ")
|
|
|
|
|
.Append(Global.Emulator.Frame)
|
2013-12-02 14:59:38 +00:00
|
|
|
|
.AppendLine();
|
|
|
|
|
|
2013-12-02 04:24:45 +00:00
|
|
|
|
foreach (var record in this)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(record.ToString());
|
|
|
|
|
}
|
2013-12-02 14:59:38 +00:00
|
|
|
|
sb.AppendLine("[/Input]");
|
2013-12-02 04:24:45 +00:00
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2013-12-03 01:43:02 +00:00
|
|
|
|
|
|
|
|
|
public void Truncate(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < Count)
|
|
|
|
|
{
|
|
|
|
|
RemoveRange(index, Count - index);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-01 20:55:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|