TasMovie - more cleanup

This commit is contained in:
adelikat 2019-11-24 16:06:01 -06:00
parent 60487c6a96
commit 1f4a2274d3
3 changed files with 40 additions and 45 deletions

View File

@ -20,25 +20,25 @@ namespace BizHawk.Client.Common
{ {
if (frame < FrameCount && frame >= 0) if (frame < FrameCount && frame >= 0)
{ {
int getframe; int getFrame;
if (LoopOffset.HasValue) if (LoopOffset.HasValue)
{ {
if (frame < Log.Count) if (frame < Log.Count)
{ {
getframe = frame; getFrame = frame;
} }
else else
{ {
getframe = ((frame - LoopOffset.Value) % (Log.Count - LoopOffset.Value)) + LoopOffset.Value; getFrame = ((frame - LoopOffset.Value) % (Log.Count - LoopOffset.Value)) + LoopOffset.Value;
} }
} }
else else
{ {
getframe = frame; getFrame = frame;
} }
return Log[getframe]; return Log[getFrame];
} }
return ""; return "";
@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
// in BK2, this is part of the input log, and not involved with the core state at all // in BK2, this is part of the input log, and not involved with the core state at all
// accordingly, this case (for special neshawk format frame numbers) is irrelevant // accordingly, this case (for special neshawk format frame numbers) is irrelevant
// probably // probably
else if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay
{ {
var strs = line.Split('x'); var strs = line.Split('x');
try try

View File

@ -15,8 +15,8 @@ namespace BizHawk.Client.Common
private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants(); private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants();
private readonly Dictionary<int, IController> _inputStateCache = new Dictionary<int, IController>(); private readonly Dictionary<int, IController> _inputStateCache = new Dictionary<int, IController>();
public readonly IStringLog VerificationLog = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state public IStringLog VerificationLog { get; } = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state
public readonly TasBranchCollection Branches = new TasBranchCollection(); public TasBranchCollection Branches { get; } = new TasBranchCollection();
public TasSession Session { get; private set; } public TasSession Session { get; private set; }
public new const string Extension = "tasproj"; public new const string Extension = "tasproj";
@ -30,12 +30,16 @@ namespace BizHawk.Client.Common
public int CurrentBranch { get; set; } public int CurrentBranch { get; set; }
public TasLagLog TasLagLog { get; } = new TasLagLog(); public TasLagLog TasLagLog { get; } = new TasLagLog();
public IStringLog InputLog => Log;
public int BranchCount => Branches.Count;
public int LastStatedFrame => TasStateManager.Last; public int LastStatedFrame => TasStateManager.Last;
public override string PreferredExtension => Extension; public override string PreferredExtension => Extension;
public IStateManager TasStateManager { get; } public IStateManager TasStateManager { get; }
public IStringLog CloneInput()
{
return Log.Clone();
}
public TasMovieRecord this[int index] => new TasMovieRecord public TasMovieRecord this[int index] => new TasMovieRecord
{ {
HasState = TasStateManager.HasState(index), HasState = TasStateManager.HasState(index),
@ -279,10 +283,10 @@ namespace BizHawk.Client.Common
if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay
{ {
var strs = line.Split('x'); var split = line.Split('x');
try try
{ {
stateFrame = int.Parse(strs[1], NumberStyles.HexNumber); stateFrame = int.Parse(split[1], NumberStyles.HexNumber);
} }
catch catch
{ {
@ -292,10 +296,10 @@ namespace BizHawk.Client.Common
} }
else if (line.Contains("Frame ")) else if (line.Contains("Frame "))
{ {
var strs = line.Split(' '); var split = line.Split(' ');
try try
{ {
stateFrame = int.Parse(strs[1]); stateFrame = int.Parse(split[1]);
} }
catch catch
{ {
@ -377,16 +381,16 @@ namespace BizHawk.Client.Common
errorMessage = "Savestate Frame number failed to parse"; errorMessage = "Savestate Frame number failed to parse";
} }
var stateFramei = stateFrame ?? 0; var stateFrameValue = stateFrame ?? 0;
if (stateFramei > 0 && stateFramei < Log.Count) if (stateFrameValue > 0 && stateFrameValue < Log.Count)
{ {
if (!Global.Config.VBAStyleMovieLoadState) if (!Global.Config.VBAStyleMovieLoadState)
{ {
Truncate(stateFramei); Truncate(stateFrameValue);
} }
} }
else if (stateFramei > Log.Count) // Post movie savestate else if (stateFrameValue > Log.Count) // Post movie savestate
{ {
if (!Global.Config.VBAStyleMovieLoadState) if (!Global.Config.VBAStyleMovieLoadState)
{ {

View File

@ -93,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
{ {
text = ""; text = "";
if (index >= Movie.BranchCount) if (index >= Movie.Branches.Count)
{ {
return; return;
} }
@ -154,26 +154,17 @@ namespace BizHawk.Client.EmuHawk
TasBranch branch = CreateBranch(); TasBranch branch = CreateBranch();
Movie.NewBranchText = ""; // reset every time it's used Movie.NewBranchText = ""; // reset every time it's used
Movie.AddBranch(branch); Movie.AddBranch(branch);
BranchView.RowCount = Movie.BranchCount; BranchView.RowCount = Movie.Branches.Count;
Movie.CurrentBranch = Movie.BranchCount - 1; Movie.CurrentBranch = Movie.Branches.Count - 1;
BranchView.ScrollToIndex(Movie.CurrentBranch); BranchView.ScrollToIndex(Movie.CurrentBranch);
Select(Movie.CurrentBranch, true); Select(Movie.CurrentBranch, true);
BranchView.Refresh(); BranchView.Refresh();
Tastudio.RefreshDialog(); Tastudio.RefreshDialog();
} }
public TasBranch SelectedBranch public TasBranch SelectedBranch => BranchView.AnyRowsSelected
{ ? GetBranch(BranchView.SelectedRows.First())
get : null;
{
if (BranchView.AnyRowsSelected)
{
return GetBranch(BranchView.SelectedRows.First());
}
return null;
}
}
private TasBranch CreateBranch() private TasBranch CreateBranch()
{ {
@ -181,7 +172,7 @@ namespace BizHawk.Client.EmuHawk
{ {
Frame = Tastudio.Emulator.Frame, Frame = Tastudio.Emulator.Frame,
CoreData = (byte[])(Tastudio.StatableEmulator.SaveStateBinary().Clone()), CoreData = (byte[])(Tastudio.StatableEmulator.SaveStateBinary().Clone()),
InputLog = Movie.InputLog.Clone(), InputLog = Movie.CloneInput(),
CoreFrameBuffer = GlobalWin.MainForm.MakeScreenshotImage(), CoreFrameBuffer = GlobalWin.MainForm.MakeScreenshotImage(),
OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(), OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(),
ChangeLog = new TasMovieChangeLog(Movie), ChangeLog = new TasMovieChangeLog(Movie),
@ -243,7 +234,7 @@ namespace BizHawk.Client.EmuHawk
private void AddBranchToolStripMenuItem_Click(object sender, EventArgs e) private void AddBranchToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Branch(); Branch();
CallSavedCallback(Movie.BranchCount - 1); CallSavedCallback(Movie.Branches.Count - 1);
GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}");
} }
@ -251,7 +242,7 @@ namespace BizHawk.Client.EmuHawk
{ {
Branch(); Branch();
EditBranchTextPopUp(Movie.CurrentBranch); EditBranchTextPopUp(Movie.CurrentBranch);
CallSavedCallback(Movie.BranchCount - 1); CallSavedCallback(Movie.Branches.Count - 1);
GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}");
} }
@ -348,12 +339,12 @@ namespace BizHawk.Client.EmuHawk
_branchUndo = BranchUndo.Remove; _branchUndo = BranchUndo.Remove;
Movie.RemoveBranch(SelectedBranch); Movie.RemoveBranch(SelectedBranch);
BranchView.RowCount = Movie.BranchCount; BranchView.RowCount = Movie.Branches.Count;
if (index == Movie.BranchCount) if (index == Movie.Branches.Count)
{ {
BranchView.ClearSelectedRows(); BranchView.ClearSelectedRows();
Select(Movie.BranchCount - 1, true); Select(Movie.Branches.Count - 1, true);
} }
CallRemovedCallback(index); CallRemovedCallback(index);
@ -384,7 +375,7 @@ namespace BizHawk.Client.EmuHawk
else if (_branchUndo == BranchUndo.Remove) else if (_branchUndo == BranchUndo.Remove)
{ {
Movie.AddBranch(_backupBranch); Movie.AddBranch(_backupBranch);
BranchView.RowCount = Movie.BranchCount; BranchView.RowCount = Movie.Branches.Count;
CallSavedCallback(Movie.Branches.IndexOf(_backupBranch)); CallSavedCallback(Movie.Branches.IndexOf(_backupBranch));
GlobalWin.OSD.AddMessage("Branch Removal canceled"); GlobalWin.OSD.AddMessage("Branch Removal canceled");
} }
@ -524,14 +515,14 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues() public void UpdateValues()
{ {
BranchView.RowCount = Movie.BranchCount; BranchView.RowCount = Movie.Branches.Count;
BranchView.Refresh(); BranchView.Refresh();
} }
public void Restart() public void Restart()
{ {
BranchView.DeselectAll(); BranchView.DeselectAll();
BranchView.RowCount = Movie.BranchCount; BranchView.RowCount = Movie.Branches.Count;
BranchView.Refresh(); BranchView.Refresh();
} }
@ -653,7 +644,7 @@ namespace BizHawk.Client.EmuHawk
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e) private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
{ {
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.BranchCount) if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.Branches.Count)
{ {
var guid = Movie.BranchGuidByIndex(Movie.CurrentBranch); var guid = Movie.BranchGuidByIndex(Movie.CurrentBranch);
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
@ -665,11 +656,11 @@ namespace BizHawk.Client.EmuHawk
private void BranchView_PointedCellChanged(object sender, InputRoll.CellEventArgs e) private void BranchView_PointedCellChanged(object sender, InputRoll.CellEventArgs e)
{ {
if (e.NewCell?.RowIndex != null && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.BranchCount) if (e.NewCell?.RowIndex != null && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.Branches.Count)
{ {
if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName && if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName &&
BranchView.CurrentCell.RowIndex.HasValue && BranchView.CurrentCell.RowIndex.HasValue &&
BranchView.CurrentCell.RowIndex < Movie.BranchCount) BranchView.CurrentCell.RowIndex < Movie.Branches.Count)
{ {
TasBranch branch = GetBranch(BranchView.CurrentCell.RowIndex.Value); TasBranch branch = GetBranch(BranchView.CurrentCell.RowIndex.Value);
Point location = PointToScreen(Location); Point location = PointToScreen(Location);