From eaef33649289639811631f67da54bab7d04dc353 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 15 Jun 2019 16:06:35 -0500 Subject: [PATCH] rip out IStateManager.MountForWriteAccess() and simplify --- .../conversions/MovieConversionExtensions.cs | 2 - .../movie/tasproj/IStateManager.cs | 10 +--- .../movie/tasproj/TasStateManager.cs | 50 ++++++------------- BizHawk.Client.EmuHawk/MainForm.Movie.cs | 7 --- .../tools/TAStudio/TAStudio.cs | 1 - 5 files changed, 17 insertions(+), 53 deletions(-) diff --git a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs index a15f250e0e..a1450bf56a 100644 --- a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs +++ b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs @@ -37,7 +37,6 @@ namespace BizHawk.Client.Common.MovieConversionExtensions } var tas = new TasMovie(newFilename, old.StartsFromSavestate); - tas.TasStateManager.MountWriteAccess(); for (var i = 0; i < old.InputLogLength; i++) { @@ -167,7 +166,6 @@ namespace BizHawk.Client.Common.MovieConversionExtensions // States can't be easily moved over, because they contain the frame number. // TODO? I'm not sure how this would be done. - tas.TasStateManager.MountWriteAccess(); old.TasStateManager.Clear(); // Lag Log diff --git a/BizHawk.Client.Common/movie/tasproj/IStateManager.cs b/BizHawk.Client.Common/movie/tasproj/IStateManager.cs index 1aa258bbe5..06ca643f8f 100644 --- a/BizHawk.Client.Common/movie/tasproj/IStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/IStateManager.cs @@ -1,12 +1,9 @@ using System; +using System.Collections.Generic; +using System.IO; namespace BizHawk.Client.Common { - using System.Collections.Generic; - using System.IO; - - using BizHawk.Common; - public interface IStateManager { // byte[] this[int frame] { get; } // TODO: I had it refactored to this back in the day @@ -45,8 +42,5 @@ namespace BizHawk.Client.Common int GetStateFrameByIndex(int index); bool Remove(int frame); - - // ********* Delete these ********** - void MountWriteAccess(); } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 84353f2d24..b4fcd3daf0 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -18,15 +18,11 @@ namespace BizHawk.Client.Common // TODO: pass this in, and find a solution to a stale reference (this is instantiated BEFORE a new core instance is made, making this one stale if it is simply set in the constructor private IStatable Core => Global.Emulator.AsStatable(); private readonly StateManagerDecay _decay; - - public Action InvalidateCallback { get; set; } - - private SortedList _states = new SortedList(); - - private bool _isMountedForWrite; private readonly TasMovie _movie; - private ulong _expectedStateSize; + private readonly SortedList _states; + private readonly ulong _expectedStateSize; + private int _stateFrequency; private readonly int _minFrequency = 1; private readonly int _maxFrequency = 16; @@ -45,8 +41,20 @@ namespace BizHawk.Client.Common } _decay = new StateManagerDecay(_movie, this); + + _expectedStateSize = (ulong)Core.SaveStateBinary().Length; + if (_expectedStateSize == 0) + { + throw new InvalidOperationException("Savestate size can not be zero!"); + } + + _states = new SortedList(MaxStates); + + UpdateStateFrequency(); } + public Action InvalidateCallback { get; set; } + public void UpdateStateFrequency() { _stateFrequency = ((int)_expectedStateSize / Settings.MemStateGapDivider / 1024) @@ -56,34 +64,6 @@ namespace BizHawk.Client.Common LimitStateCount(); } - /// - /// Mounts this instance for write access. Prior to that it's read-only - /// - public void MountWriteAccess() - { - if (_isMountedForWrite) - { - return; - } - - int limit = 0; - _isMountedForWrite = true; - _expectedStateSize = (ulong)Core.SaveStateBinary().Length; - UpdateStateFrequency(); - - if (_expectedStateSize > 0) - { - limit = MaxStates; - } - - _states = new SortedList(limit); - - if (_expectedStateSize > int.MaxValue) - { - throw new InvalidOperationException(); - } - } - public TasStateManagerSettings Settings { get; set; } /// diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index b9bc4db335..d7094c8893 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -5,10 +5,6 @@ using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; -using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; -using BizHawk.Emulation.Cores.Nintendo.NES; -using BizHawk.Emulation.Cores.Nintendo.SNES9X; -using BizHawk.Emulation.Cores.Nintendo.SNES; namespace BizHawk.Client.EmuHawk { @@ -30,9 +26,6 @@ namespace BizHawk.Client.EmuHawk try { - var tasmovie = (movie as TasMovie); - if (tasmovie != null) - tasmovie.TasStateManager.MountWriteAccess(); Global.MovieSession.QueueNewMovie(movie, record, Emulator); } catch (MoviePlatformMismatchException ex) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 6f9a438201..6a48406b51 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -642,7 +642,6 @@ namespace BizHawk.Client.EmuHawk Global.MovieSession.Movie = new TasMovie(false, _seekBackgroundWorker); var stateManager = ((TasMovie)Global.MovieSession.Movie).TasStateManager; - stateManager.MountWriteAccess(); stateManager.InvalidateCallback = GreenzoneInvalidated; BookMarkControl.LoadedCallback = BranchLoaded;