From ca39eca22cfcebcf44f721233a9c3d75dc91cef3 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 30 May 2020 16:10:01 -0500 Subject: [PATCH] Pass the instance of MovieSession into movies, instead of referencing them from a global --- src/BizHawk.Client.Common/movie/MovieSession.cs | 2 +- .../movie/bk2/Bk2Movie.InputLog.cs | 2 +- src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs | 10 ++++++---- src/BizHawk.Client.Common/movie/interfaces/IMovie.cs | 2 +- .../movie/interfaces/ITasMovie.cs | 2 +- .../movie/tasproj/TasMovie.Editing.cs | 4 ++-- src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs | 4 ++-- src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs | 10 +++++----- .../tools/TAStudio/BookmarksBranchesBox.cs | 2 +- .../tools/TAStudio/TAStudio.IToolForm.cs | 2 +- src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs | 4 ++-- 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index 53beb1d1ab..86a7c3608f 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -289,7 +289,7 @@ namespace BizHawk.Client.Common public void RunQueuedMovie(bool recordMode, IEmulator emulator) { - _queuedMovie.Attach(emulator); + _queuedMovie.Attach(this, emulator); foreach (var previousPref in _preferredCores) { Global.Config.PreferredCores[previousPref.Key] = previousPref.Value; diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs index f397612050..68273c1dbf 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs @@ -39,7 +39,7 @@ namespace BizHawk.Client.Common int? stateFrame = null; // We are in record mode so replace the movie log with the one from the savestate - if (!Global.MovieSession.MultiTrack.IsActive) + if (!Session.MultiTrack.IsActive) { if (Global.Config.EnableBackupMovies && MakeBackup && Log.Count != 0) { diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 9bbaf05a1c..4c3bd26200 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -19,7 +19,7 @@ namespace BizHawk.Client.Common Header[HeaderKeys.MovieVersion] = "BizHawk v2.0.0"; } - public virtual void Attach(IEmulator emulator) + public virtual void Attach(IMovieSession session, IEmulator emulator) { if (!Emulator.IsNull()) { @@ -27,9 +27,11 @@ namespace BizHawk.Client.Common } Emulator = emulator; + Session = session; } public IEmulator Emulator { get; private set; } + public IMovieSession Session { get; private set; } protected bool MakeBackup { get; set; } = true; @@ -113,7 +115,7 @@ namespace BizHawk.Client.Common { // This is a bad way to do multitrack logic, pass the info in instead of going to the global // and it is weird for Truncate to possibly not truncate - if (!Global.MovieSession.MultiTrack.IsActive) + if (!Session.MultiTrack.IsActive) { if (frame < Log.Count) { @@ -127,7 +129,7 @@ namespace BizHawk.Client.Common { if (frame < FrameCount && frame >= 0) { - _adapter ??= new Bk2Controller(Global.MovieSession.MovieController.Definition); + _adapter ??= new Bk2Controller(Session.MovieController.Definition); _adapter.SetFromMnemonic(Log[frame]); return _adapter; } @@ -144,7 +146,7 @@ namespace BizHawk.Client.Common public virtual void ClearFrame(int frame) { - var lg = LogGeneratorInstance(Global.MovieSession.MovieController); + var lg = LogGeneratorInstance(Session.MovieController); SetFrameAt(frame, lg.EmptyEntry); Changes = true; } diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs index 4f0af1bbce..60c735473a 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -234,7 +234,7 @@ namespace BizHawk.Client.Common /// Thrown if attempting to attach a core when one is already attached /// or if the given core does not meet all required dependencies /// - void Attach(IEmulator emulator); + void Attach(IMovieSession session, IEmulator emulator); /// /// The currently attached core or null if not yet attached diff --git a/src/BizHawk.Client.Common/movie/interfaces/ITasMovie.cs b/src/BizHawk.Client.Common/movie/interfaces/ITasMovie.cs index 757abb1a77..f0a9b60704 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/ITasMovie.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/ITasMovie.cs @@ -16,7 +16,7 @@ namespace BizHawk.Client.Common Func ClientSettingsForSave { set; } Action GetClientSettingsOnLoad { set; } ITasMovieRecord this[int index] { get; } - ITasSession Session { get; } + ITasSession TasSession { get; } TasMovieMarkerList Markers { get; } ITasBranchCollection Branches { get; } TasLagLog LagLog { get; } diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 4b5c3ec471..cb51d01206 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -256,7 +256,7 @@ namespace BizHawk.Client.Common frame = Log.Count(); } - var lg = LogGeneratorInstance(Global.MovieSession.MovieController); + var lg = LogGeneratorInstance(Session.MovieController); Log.InsertRange(frame, Enumerable.Repeat(lg.EmptyEntry, count).ToList()); ShiftBindedMarkers(frame, count); @@ -273,7 +273,7 @@ namespace BizHawk.Client.Common int oldLength = InputLogLength; ChangeLog.AddGeneralUndo(oldLength, oldLength + numFrames - 1); - Global.MovieSession.MovieController.SetFromSticky(Global.InputManager.AutofireStickyXorAdapter); + Session.MovieController.SetFromSticky(Global.InputManager.AutofireStickyXorAdapter); // account for autohold. needs autohold pattern to be already recorded in the current frame var lg = LogGeneratorInstance(Global.InputManager.MovieOutputHardpoint); diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 9d9540371e..5c36156039 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -64,7 +64,7 @@ namespace BizHawk.Client.Common Branches.Save(bs); } - bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(Session))); + bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(TasSession))); if (TasStateManager.Settings.SaveStateHistory && !backup) { @@ -253,7 +253,7 @@ namespace BizHawk.Client.Common var json = tr.ReadToEnd(); try { - Session = JsonConvert.DeserializeObject(json); + TasSession = JsonConvert.DeserializeObject(json); } catch { diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 873e626591..512dc3e5dd 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -25,7 +25,7 @@ namespace BizHawk.Client.Common Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on"); } - public override void Attach(IEmulator emulator) + public override void Attach(IMovieSession session, IEmulator emulator) { if (!emulator.HasSavestates()) { @@ -39,12 +39,12 @@ namespace BizHawk.Client.Common _inputPollable = emulator.AsInputPollable(); TasStateManager.Attach(emulator); - base.Attach(emulator); + base.Attach(session, emulator); } 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 ITasBranchCollection Branches { get; } - public ITasSession Session { get; private set; } = new TasSession(); + public ITasSession TasSession { get; private set; } = new TasSession(); public int LastEditedFrame { get; private set; } = -1; public bool LastPositionStable { get; set; } = true; @@ -97,7 +97,7 @@ namespace BizHawk.Client.Common } LastEditedFrame = frame; - if (anyInvalidated && Global.MovieSession.Movie.IsCountingRerecords) + if (anyInvalidated && IsCountingRerecords) { Rerecords++; } @@ -185,7 +185,7 @@ namespace BizHawk.Client.Common var newLog = new List(); // We are in record mode so replace the movie log with the one from the savestate - if (!Global.MovieSession.MultiTrack.IsActive) + if (!Session.MultiTrack.IsActive) { _timelineBranchFrame = null; diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 0bc666b7ff..e869bd2621 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -130,7 +130,7 @@ namespace BizHawk.Client.EmuHawk Branches.Add(branch); BranchView.RowCount = Branches.Count; Branches.Current = Branches.Count - 1; - Movie.Session.UpdateValues(Tastudio.Emulator.Frame, Branches.Current); + Movie.TasSession.UpdateValues(Tastudio.Emulator.Frame, Branches.Current); BranchView.ScrollToIndex(Branches.Current); Select(Branches.Current, true); BranchView.Refresh(); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index f1924fe8c4..445597192d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk refreshNeeded = AutoAdjustInput(); } - CurrentTasMovie.Session.UpdateValues(Emulator.Frame, CurrentTasMovie.Branches.Current); + CurrentTasMovie.TasSession.UpdateValues(Emulator.Frame, CurrentTasMovie.Branches.Current); MaybeFollowCursor(); if (TasView.IsPartiallyVisible(Emulator.Frame) || TasView.IsPartiallyVisible(_lastRefresh)) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 024be66eb7..3e4f017f73 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -644,7 +644,7 @@ namespace BizHawk.Client.EmuHawk } else { - GoToFrame(CurrentTasMovie.Session.CurrentFrame); + GoToFrame(CurrentTasMovie.TasSession.CurrentFrame); } // If we are loading an existing non-default movie, we will already have columns generated @@ -657,7 +657,7 @@ namespace BizHawk.Client.EmuHawk SetUpToolStripColumns(); CurrentTasMovie.PropertyChanged += TasMovie_OnPropertyChanged; - CurrentTasMovie.Branches.Current = CurrentTasMovie.Session.CurrentBranch; + CurrentTasMovie.Branches.Current = CurrentTasMovie.TasSession.CurrentBranch; BookMarkControl.UpdateTextColumnWidth(); MarkerControl.UpdateTextColumnWidth(); // clear all selections