Bk2 - take the log key into account when replaying a movie input log

This commit is contained in:
adelikat 2014-06-21 14:33:33 +00:00
parent 0b21085a98
commit 10c48bb3f8
8 changed files with 112 additions and 54 deletions

View File

@ -87,6 +87,12 @@ namespace BizHawk.Client.Common
}
}
public void MovieLoad()
{
Movie.Load();
MovieControllerAdapter = Movie.LogGeneratorInstance().MovieControllerAdapter;
}
public void StopMovie(bool saveChanges = true)
{
var message = "Movie ";

View File

@ -10,6 +10,31 @@ namespace BizHawk.Client.Common
{
public class Bk2ControllerAdapter : IMovieController
{
private string _logKey = string.Empty;
public Bk2ControllerAdapter(string key)
{
_logKey = key;
SetLogOverride();
}
private void SetLogOverride()
{
if (!string.IsNullOrEmpty(_logKey))
{
// TODO: this could be cleaned up into a LINQ select
List<List<string>> controls = new List<List<string>>();
var groups = _logKey.Split(new[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var group in groups)
{
var buttons = group.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList();
controls.Add(buttons);
}
_type.ControlsFromLog = controls;
}
}
#region IController Implementation
public bool this[string button]
@ -31,7 +56,21 @@ namespace BizHawk.Client.Common
#region IMovieController Implementation
public ControllerDefinition Type { get; set; }
private Bk2ControllerDefinition _type = new Bk2ControllerDefinition();
public ControllerDefinition Type
{
get
{
return _type;
}
set
{
_type = new Bk2ControllerDefinition(value);
SetLogOverride();
}
}
/// <summary>
/// latches one player from the source
@ -79,6 +118,7 @@ namespace BizHawk.Client.Common
{
if (!string.IsNullOrWhiteSpace(mnemonic))
{
var def = Global.Emulator.ControllerDefinition;
var trimmed = mnemonic.Replace("|", "");
var buttons = Type.ControlsOrdered.SelectMany(x => x).ToList();
var iterator = 0;
@ -87,20 +127,19 @@ namespace BizHawk.Client.Common
for (int i = 0; i < buttons.Count; i++)
{
if (Type.BoolButtons.Contains(buttons[i]))
var b = buttons[i];
if (def.BoolButtons.Contains(buttons[i]))
{
var boolBtn = Type.BoolButtons.First(x => x == buttons[i]);
MyBoolButtons[boolBtn] = trimmed[iterator] == '.' ? false : true;
MyBoolButtons[buttons[i]] = trimmed[iterator] == '.' ? false : true;
iterator++;
boolIt++;
}
else if (Type.FloatControls.Contains(buttons[i]))
else if (def.FloatControls.Contains(buttons[i]))
{
var temp = trimmed.Substring(iterator, 3);
var val = int.Parse(temp);
var floatBtn = Type.FloatControls.First(x => x == buttons[i]);
MyFloatControls[floatBtn] = val;
MyFloatControls[buttons[i]] = val;
iterator += 4;
floatIt++;
}
@ -110,6 +149,38 @@ namespace BizHawk.Client.Common
#endregion
public class Bk2ControllerDefinition : ControllerDefinition
{
public Bk2ControllerDefinition()
: base()
{
}
public Bk2ControllerDefinition(ControllerDefinition source)
: base(source)
{
}
public List<List<string>> ControlsFromLog = new List<List<string>>();
public override IEnumerable<IEnumerable<string>> ControlsOrdered
{
get
{
if (ControlsFromLog.Any())
{
return ControlsFromLog;
}
return base.ControlsOrdered;
}
}
}
private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> MyFloatControls = new WorkingDictionary<string, float>();
}

View File

@ -11,12 +11,18 @@ namespace BizHawk.Client.Common
{
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
private IController _source;
private string _logKey = string.Empty;
public Bk2LogEntryGenerator(string logKey)
{
_logKey = logKey;
}
public IMovieController MovieControllerAdapter
{
get
{
return new Bk2ControllerAdapter();
return new Bk2ControllerAdapter(_logKey);
}
}
@ -69,8 +75,9 @@ namespace BizHawk.Client.Common
var sb = new StringBuilder();
sb.Append("LogKey:");
foreach (var group in _source.Type.ControlsOrdered)
foreach (var group in _source.Type.ControlsOrdered.Where(c => c.Any()))
{
sb.Append("#");
foreach (var button in group)
{
sb

View File

@ -107,14 +107,8 @@ namespace BizHawk.Client.Common
bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
{
string line;
while ((line = tr.ReadLine()) != null)
{
if (line != null && line.StartsWith("|"))
{
_log.Add(line);
}
}
string errorMessage = string.Empty;
ExtractInputLog(tr, out errorMessage);
});
if (StartsFromSavestate)

View File

@ -10,6 +10,7 @@ namespace BizHawk.Client.Common
public partial class Bk2Movie : IMovie
{
private readonly List<string> _log = new List<string>();
private string _logKey = string.Empty;
public string GetInputLog()
{
@ -40,22 +41,11 @@ namespace BizHawk.Client.Common
while (true)
{
var line = reader.ReadLine();
if (line == null)
if (string.IsNullOrEmpty(line))
{
break;
}
if (line.Trim() == string.Empty || line == "[Input]")
{
continue;
}
if (line == "[/Input]")
{
break;
}
if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay
else if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay
{
var strs = line.Split('x');
try
@ -81,6 +71,10 @@ namespace BizHawk.Client.Common
return false;
}
}
else if (line.StartsWith("LogKey:"))
{
_logKey = line.Replace("LogKey:", "");
}
else if (line[0] == '|')
{
_log.Add(line);
@ -98,16 +92,6 @@ namespace BizHawk.Client.Common
break;
}
if (line.Trim() == string.Empty || line == "[Input]")
{
continue;
}
if (line == "[/Input]")
{
break;
}
if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay
{
var strs = line.Split('x');
@ -134,6 +118,10 @@ namespace BizHawk.Client.Common
return false;
}
}
else if (line.StartsWith("LogKey:"))
{
_logKey = line.Replace("LogKey:", "");
}
else if (line.StartsWith("|"))
{
SetFrameAt(i, line);
@ -185,7 +173,7 @@ namespace BizHawk.Client.Common
var line = reader.ReadLine();
if (line == null)
{
return false;
break;
}
if (line.Trim() == string.Empty)
@ -219,14 +207,6 @@ namespace BizHawk.Client.Common
return false;
}
}
else if (line == "[Input]")
{
continue;
}
else if (line == "[/Input]")
{
break;
}
else if (line[0] == '|')
{
newLog.Add(line);
@ -286,7 +266,7 @@ namespace BizHawk.Client.Common
private StringBuilder RawInputLog()
{
var lg = new Bk2LogEntryGenerator();
var lg = new Bk2LogEntryGenerator(_logKey);
lg.SetSource(Global.MovieOutputHardpoint);
var sb = new StringBuilder();

View File

@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
public ILogEntryGenerator LogGeneratorInstance()
{
return new Bk2LogEntryGenerator();
return new Bk2LogEntryGenerator(_logKey);
}
public double FrameCount
@ -180,7 +180,7 @@ namespace BizHawk.Client.Common
getframe = frame;
}
var adapter = new Bk2ControllerAdapter();
var adapter = new Bk2ControllerAdapter(_logKey);
adapter.Type = Global.MovieSession.MovieControllerAdapter.Type;
adapter.SetControllersAsMnemonic(_log[getframe]);
return adapter;

View File

@ -34,7 +34,7 @@ namespace BizHawk.Client.EmuHawk
if (!record)
{
Global.MovieSession.Movie.Load();
Global.MovieSession.MovieLoad();
}
try

View File

@ -265,7 +265,7 @@ namespace BizHawk.Client.EmuHawk
if (AskSave())
{
_tas.Filename = path;
var loadResult = _tas.Load();
var loadResult = _tas.Load(); // TODO: Global.MovieSession.MovieLoad() needs to be called in order to set up the Movie adapter properly
if (!loadResult)
{
ToolHelpers.HandleLoadError(Global.Config.RecentTas, path);