diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index 06a69adcc6..d00b0bd09a 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -47,9 +47,10 @@ namespace BizHawk.Client.Common public static BinaryStateLump ClientSettings { get; private set; } [Name("VerificationLog", "txt")] public static BinaryStateLump VerificationLog { get; private set; } - [Name("UserData", "txt")] public static BinaryStateLump UserData { get; private set; } + [Name("Session", "txt")] + public static BinaryStateLump Session { get; private set; } // branchstuff [Name("Branches\\CoreData", "bin")] diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 6ca260c29c..6c0d64b248 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -209,6 +209,7 @@ </Compile> <Compile Include="movie\tasproj\TasMovie.cs" /> <Compile Include="movie\tasproj\TasMovieMarker.cs" /> + <Compile Include="movie\tasproj\TasSession.cs" /> <Compile Include="movie\tasproj\TasStateManager.cs" /> <Compile Include="movie\tasproj\TasMovieRecord.cs" /> <Compile Include="movie\tasproj\TasStateManagerSettings.cs" /> diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 411c6c3325..58ce372164 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -105,6 +105,8 @@ namespace BizHawk.Client.Common } } ReportProgress(PROGRESS_STEP); + + bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString())); } Changes = false; @@ -298,6 +300,11 @@ namespace BizHawk.Client.Common StateManager.LoadBranchStates(br); }); } + + bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) + { + Session.PopulateFromString(tr.ReadToEnd()); + }); } Changes = false; diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index d56f2425bc..b78016fdf1 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -18,10 +18,10 @@ namespace BizHawk.Client.Common private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants(); private readonly TasStateManager StateManager; + public readonly TasSession Session; private readonly TasLagLog LagLog = new TasLagLog(); private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>(); public readonly List<string> VerificationLog = new List<string>(); // 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(); private BackgroundWorker _progressReportWorker = null; @@ -48,12 +48,14 @@ namespace BizHawk.Client.Common ChangeLog = new TasMovieChangeLog(this); StateManager = new TasStateManager(this); + Session = new TasSession(this); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; Markers = new TasMovieMarkerList(this); Markers.CollectionChanged += Markers_CollectionChanged; Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on"); BindMarkersToInput = true; + CurrentBranch = -1; } public TasMovie(bool startsFromSavestate = false, BackgroundWorker progressReportWorker = null) @@ -68,12 +70,14 @@ namespace BizHawk.Client.Common ChangeLog = new TasMovieChangeLog(this); StateManager = new TasStateManager(this); + Session = new TasSession(this); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; Markers = new TasMovieMarkerList(this); Markers.CollectionChanged += Markers_CollectionChanged; Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on"); - + BindMarkersToInput = true; + CurrentBranch = -1; } public TasLagLog TasLagLog { get { return LagLog; } } @@ -81,6 +85,7 @@ namespace BizHawk.Client.Common public TasMovieMarkerList Markers { get; set; } public bool BindMarkersToInput { get; set; } public bool UseInputCache { get; set; } + public int CurrentBranch { get; set; } public int BranchCount { get { return Branches.Count; } } public TasBranch GetBranch(int index) { diff --git a/BizHawk.Client.Common/movie/tasproj/TasSession.cs b/BizHawk.Client.Common/movie/tasproj/TasSession.cs new file mode 100644 index 0000000000..c7cd5c1830 --- /dev/null +++ b/BizHawk.Client.Common/movie/tasproj/TasSession.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Client.Common +{ + public class TasSession + { + private TasMovie _movie; + public int CurrentFrame { get; set; } + public int CurrentBranch { get; set; } + + public TasSession(TasMovie movie) + { + _movie = movie; + CurrentFrame = 0; + CurrentBranch = -1; + } + + public void UpdateValues() + { + CurrentFrame = Global.Emulator.Frame; + CurrentBranch = _movie.CurrentBranch; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + + UpdateValues(); + sb.AppendLine(CurrentFrame.ToString()); + sb.AppendLine(CurrentBranch.ToString()); + + return sb.ToString(); + } + + public void PopulateFromString(string session) + { + if (!string.IsNullOrWhiteSpace(session)) + { + string[] lines = session.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); + + if (lines.Length > 0) + CurrentFrame = int.Parse(lines[0]); + else + CurrentFrame = 0; + + if (lines.Length > 1) + CurrentBranch = int.Parse(lines[1]); + else + CurrentBranch = -1; + } + } + } +} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index f7692ea626..5734ec4357 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -71,8 +71,6 @@ namespace BizHawk.Client.EmuHawk } } - private int CurrentBranch = -1; - private void QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY) { text = string.Empty; @@ -102,7 +100,7 @@ namespace BizHawk.Client.EmuHawk if (branch != null) { var record = Tastudio.CurrentTasMovie[branch.Frame]; - if (index == CurrentBranch) + if (index == Movie.CurrentBranch) color = TAStudio.CurrentFrame_InputLog; // SystemColors.HotTrack; else if (record.Lagged.HasValue) { @@ -147,9 +145,9 @@ namespace BizHawk.Client.EmuHawk if (SelectedBranch != null) { int index = BranchView.SelectedRows.First(); - //if (CurrentBranch == index) // if the current branch was edited, we should allow loading it. some day there might be a proper check + //if (Movie.CurrentBranchCurrentBranch == index) // if the current branch was edited, we should allow loading it. some day there might be a proper check // return; - CurrentBranch = index; + Movie.CurrentBranch = index; LoadBranch(SelectedBranch); BranchView.Refresh(); } @@ -168,13 +166,13 @@ namespace BizHawk.Client.EmuHawk if (SelectedBranch != null) { int index = BranchView.SelectedRows.First(); - if (index == CurrentBranch) + if (index == Movie.CurrentBranch) { - CurrentBranch = -1; + Movie.CurrentBranch = -1; } - else if (index < CurrentBranch) + else if (index < Movie.CurrentBranch) { - CurrentBranch--; + Movie.CurrentBranch--; } Movie.RemoveBranch(SelectedBranch); @@ -220,7 +218,7 @@ namespace BizHawk.Client.EmuHawk TasBranch branch = CreateBranch(); Movie.AddBranch(branch); BranchView.RowCount = Movie.BranchCount; - CurrentBranch = Movie.BranchCount - 1; + Movie.CurrentBranch = Movie.BranchCount - 1; BranchView.Refresh(); Tastudio.RefreshDialog(); } @@ -302,7 +300,7 @@ namespace BizHawk.Client.EmuHawk if (SelectedBranch != null) { UpdateBranch(SelectedBranch); - CurrentBranch = BranchView.SelectedRows.First(); + Movie.CurrentBranch = BranchView.SelectedRows.First(); } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index c0267b7ee1..1e5f174bb5 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -237,6 +237,9 @@ namespace BizHawk.Client.EmuHawk BranchesMarkersSplit.SplitterDistance = Settings.BranchMarkerSplitDistance; } + GoToFrame(CurrentTasMovie.Session.CurrentFrame); + CurrentTasMovie.CurrentBranch = CurrentTasMovie.Session.CurrentBranch; + //////////////// RefreshDialog();