From 1f4a2274d3d5406f347ed282122e44e36ba4043a Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 24 Nov 2019 16:06:01 -0600 Subject: [PATCH] TasMovie - more cleanup --- .../movie/bk2/Bk2Movie.InputLog.cs | 12 ++--- .../movie/tasproj/TasMovie.cs | 28 +++++++----- .../tools/TAStudio/BookmarksBranchesBox.cs | 45 ++++++++----------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs index fafc214ad0..da2d16a3ea 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs @@ -20,25 +20,25 @@ namespace BizHawk.Client.Common { if (frame < FrameCount && frame >= 0) { - int getframe; + int getFrame; if (LoopOffset.HasValue) { if (frame < Log.Count) { - getframe = frame; + getFrame = frame; } else { - getframe = ((frame - LoopOffset.Value) % (Log.Count - LoopOffset.Value)) + LoopOffset.Value; + getFrame = ((frame - LoopOffset.Value) % (Log.Count - LoopOffset.Value)) + LoopOffset.Value; } } else { - getframe = frame; + getFrame = frame; } - return Log[getframe]; + return Log[getFrame]; } 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 // accordingly, this case (for special neshawk format frame numbers) is irrelevant // 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'); try diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 3573536451..1c48c66254 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -15,8 +15,8 @@ namespace BizHawk.Client.Common private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants(); private readonly Dictionary _inputStateCache = new Dictionary(); - 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 readonly TasBranchCollection Branches = new TasBranchCollection(); + 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 TasBranchCollection Branches { get; } = new TasBranchCollection(); public TasSession Session { get; private set; } public new const string Extension = "tasproj"; @@ -30,12 +30,16 @@ namespace BizHawk.Client.Common public int CurrentBranch { get; set; } public TasLagLog TasLagLog { get; } = new TasLagLog(); - public IStringLog InputLog => Log; - public int BranchCount => Branches.Count; + public int LastStatedFrame => TasStateManager.Last; public override string PreferredExtension => Extension; public IStateManager TasStateManager { get; } + public IStringLog CloneInput() + { + return Log.Clone(); + } + public TasMovieRecord this[int index] => new TasMovieRecord { HasState = TasStateManager.HasState(index), @@ -279,10 +283,10 @@ namespace BizHawk.Client.Common if (line.Contains("Frame 0x")) // NES stores frame count in hex, yay { - var strs = line.Split('x'); + var split = line.Split('x'); try { - stateFrame = int.Parse(strs[1], NumberStyles.HexNumber); + stateFrame = int.Parse(split[1], NumberStyles.HexNumber); } catch { @@ -292,10 +296,10 @@ namespace BizHawk.Client.Common } else if (line.Contains("Frame ")) { - var strs = line.Split(' '); + var split = line.Split(' '); try { - stateFrame = int.Parse(strs[1]); + stateFrame = int.Parse(split[1]); } catch { @@ -377,16 +381,16 @@ namespace BizHawk.Client.Common 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) { - Truncate(stateFramei); + Truncate(stateFrameValue); } } - else if (stateFramei > Log.Count) // Post movie savestate + else if (stateFrameValue > Log.Count) // Post movie savestate { if (!Global.Config.VBAStyleMovieLoadState) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 949bbe3942..dfc36c7fb0 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -93,7 +93,7 @@ namespace BizHawk.Client.EmuHawk { text = ""; - if (index >= Movie.BranchCount) + if (index >= Movie.Branches.Count) { return; } @@ -154,26 +154,17 @@ namespace BizHawk.Client.EmuHawk TasBranch branch = CreateBranch(); Movie.NewBranchText = ""; // reset every time it's used Movie.AddBranch(branch); - BranchView.RowCount = Movie.BranchCount; - Movie.CurrentBranch = Movie.BranchCount - 1; + BranchView.RowCount = Movie.Branches.Count; + Movie.CurrentBranch = Movie.Branches.Count - 1; BranchView.ScrollToIndex(Movie.CurrentBranch); Select(Movie.CurrentBranch, true); BranchView.Refresh(); Tastudio.RefreshDialog(); } - public TasBranch SelectedBranch - { - get - { - if (BranchView.AnyRowsSelected) - { - return GetBranch(BranchView.SelectedRows.First()); - } - - return null; - } - } + public TasBranch SelectedBranch => BranchView.AnyRowsSelected + ? GetBranch(BranchView.SelectedRows.First()) + : null; private TasBranch CreateBranch() { @@ -181,7 +172,7 @@ namespace BizHawk.Client.EmuHawk { Frame = Tastudio.Emulator.Frame, CoreData = (byte[])(Tastudio.StatableEmulator.SaveStateBinary().Clone()), - InputLog = Movie.InputLog.Clone(), + InputLog = Movie.CloneInput(), CoreFrameBuffer = GlobalWin.MainForm.MakeScreenshotImage(), OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(), ChangeLog = new TasMovieChangeLog(Movie), @@ -243,7 +234,7 @@ namespace BizHawk.Client.EmuHawk private void AddBranchToolStripMenuItem_Click(object sender, EventArgs e) { Branch(); - CallSavedCallback(Movie.BranchCount - 1); + CallSavedCallback(Movie.Branches.Count - 1); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); } @@ -251,7 +242,7 @@ namespace BizHawk.Client.EmuHawk { Branch(); EditBranchTextPopUp(Movie.CurrentBranch); - CallSavedCallback(Movie.BranchCount - 1); + CallSavedCallback(Movie.Branches.Count - 1); GlobalWin.OSD.AddMessage($"Added branch {Movie.CurrentBranch}"); } @@ -348,12 +339,12 @@ namespace BizHawk.Client.EmuHawk _branchUndo = BranchUndo.Remove; Movie.RemoveBranch(SelectedBranch); - BranchView.RowCount = Movie.BranchCount; + BranchView.RowCount = Movie.Branches.Count; - if (index == Movie.BranchCount) + if (index == Movie.Branches.Count) { BranchView.ClearSelectedRows(); - Select(Movie.BranchCount - 1, true); + Select(Movie.Branches.Count - 1, true); } CallRemovedCallback(index); @@ -384,7 +375,7 @@ namespace BizHawk.Client.EmuHawk else if (_branchUndo == BranchUndo.Remove) { Movie.AddBranch(_backupBranch); - BranchView.RowCount = Movie.BranchCount; + BranchView.RowCount = Movie.Branches.Count; CallSavedCallback(Movie.Branches.IndexOf(_backupBranch)); GlobalWin.OSD.AddMessage("Branch Removal canceled"); } @@ -524,14 +515,14 @@ namespace BizHawk.Client.EmuHawk public void UpdateValues() { - BranchView.RowCount = Movie.BranchCount; + BranchView.RowCount = Movie.Branches.Count; BranchView.Refresh(); } public void Restart() { BranchView.DeselectAll(); - BranchView.RowCount = Movie.BranchCount; + BranchView.RowCount = Movie.Branches.Count; BranchView.Refresh(); } @@ -653,7 +644,7 @@ namespace BizHawk.Client.EmuHawk 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); 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) { - 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 && BranchView.CurrentCell.RowIndex.HasValue && - BranchView.CurrentCell.RowIndex < Movie.BranchCount) + BranchView.CurrentCell.RowIndex < Movie.Branches.Count) { TasBranch branch = GetBranch(BranchView.CurrentCell.RowIndex.Value); Point location = PointToScreen(Location);