diff --git a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs index bc52d1ded07..ca8492c3e7d 100644 --- a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs +++ b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs @@ -157,7 +157,7 @@ public static TasMovie ConvertToSavestateAnchoredMovie(this TasMovie old, int fr // 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(); + old.TasStateManager.ClearStateHistory(); // Lag Log tas.TasLagLog.FromLagLog(old.TasLagLog); @@ -221,7 +221,7 @@ public static TasMovie ConvertToSaveRamAnchoredMovie(this TasMovie old, byte[] s } var tas = new TasMovie(newFilename, true) { SaveRam = saveRam }; - tas.TasStateManager.Clear(); + tas.TasStateManager.ClearStateHistory(); tas.ClearLagLog(); var entries = old.GetLogEntries(); diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 5c52afb7c8e..29900983f19 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -62,10 +62,6 @@ protected override void Write(string fn, bool backup = false) if (Branches.Any()) { Branches.Save(bs); - if (_stateManager.Settings.BranchStatesInTasproj) - { - bs.PutLump(BinaryStateLump.BranchStateHistory, (BinaryWriter bw) => _stateManager.SaveBranchStates(bw)); - } } bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString())); @@ -245,13 +241,6 @@ public override bool Load(bool preload) }); Branches.Load(bl, this); - if (_stateManager.Settings.BranchStatesInTasproj) - { - bl.GetLump(BinaryStateLump.BranchStateHistory, false, delegate(BinaryReader br, long length) - { - _stateManager.LoadBranchStates(br); - }); - } bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) { @@ -283,7 +272,7 @@ public override bool Load(bool preload) private void ClearTasprojExtras() { _lagLog.Clear(); - _stateManager.Clear(); + _stateManager.ClearStateHistory(); Markers.Clear(); ChangeLog.ClearLog(); } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 4b5c27aa04c..7c81db6b9ea 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -497,13 +497,11 @@ public int BranchIndexByFrame(int frame) public void AddBranch(TasBranch branch) { Branches.Add(branch); - TasStateManager.AddBranch(); Changes = true; } public void RemoveBranch(TasBranch branch) { - TasStateManager.RemoveBranch(Branches.IndexOf(branch)); Branches.Remove(branch); Changes = true; } @@ -527,9 +525,6 @@ public void LoadBranch(TasBranch branch) { _stateManager.Invalidate(branch.InputLog.Count); } - - _stateManager.LoadBranch(Branches.IndexOf(branch)); - _stateManager.SetState(branch.Frame, branch.CoreData); if (BindMarkersToInput) // pretty critical not to erase them { @@ -549,7 +544,6 @@ public void UpdateBranch(TasBranch old, TasBranch newBranch) } Branches[index] = newBranch; - TasStateManager.UpdateBranch(index); Changes = true; } diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 2e195a9cf85..ae8fc8d0649 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -5,6 +5,7 @@ using System.Drawing; using BizHawk.Common; +using BizHawk.Common.NumberExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; @@ -25,8 +26,7 @@ private void CallInvalidateCallback(int index) { InvalidateCallback?.Invoke(index); } - - private readonly List _lowPriorityStates = new List(); + internal NDBDatabase NdbDatabase { get; set; } private Guid _guid = Guid.NewGuid(); private SortedList _states = new SortedList(); @@ -40,47 +40,40 @@ private string StatePath } } + private long _stateCleanupTime; + private readonly long _stateCleanupPeriod = 10000; + private bool _isMountedForWrite; private readonly TasMovie _movie; - private ulong _expectedStateSize; + private ulong _expectedStateSize; private readonly int _minFrequency = 1; - private const int MaxFrequency = 16; - private int MaxStates => (int)(Settings.Cap / _expectedStateSize) + (int)((ulong)Settings.DiskCapacitymb * 1024 * 1024 / _expectedStateSize); - private int FileStateGap => 1 << Settings.FileStateGap; + private readonly int _maxFrequency = 16; + private int _maxStates => (int)(Settings.Cap / _expectedStateSize) + + (int)((ulong)Settings.DiskCapacitymb * 1024 * 1024 / _expectedStateSize); + private int _fileStateGap => 1 << Settings.FileStateGap; private int StateFrequency { get { - int freq = (int)_expectedStateSize / Settings.MemStateGapDivider / 1024; - - if (freq < _minFrequency) - { - return _minFrequency; - } - - if (freq > MaxFrequency) - { - return MaxFrequency; - } - - return freq; + return NumberExtensions.Clamp( + ((int)_expectedStateSize / Settings.MemStateGapDivider / 1024), + _minFrequency, _maxFrequency); } } - + public TasStateManager(TasMovie movie) { _movie = movie; - Settings = new TasStateManagerSettings(Global.Config.DefaultTasProjSettings); - _accessed = new List(); - if (_movie.StartsFromSavestate) { SetState(0, _movie.BinarySavestate); } + + _stateCleanupTime = DateTime.Now.Ticks + _stateCleanupPeriod; } public void Dispose() @@ -99,15 +92,13 @@ public void MountWriteAccess() return; } - _isMountedForWrite = true; - int limit = 0; - + _isMountedForWrite = true; _expectedStateSize = (ulong)Core.SaveStateBinary().Length; if (_expectedStateSize > 0) { - limit = MaxStates; + limit = _maxStates; } _states = new SortedList(limit); @@ -138,7 +129,6 @@ public KeyValuePair this[int frame] if (_states.ContainsKey(frame)) { - StateAccessed(frame); return new KeyValuePair(frame, _states[frame].State); } @@ -146,8 +136,6 @@ public KeyValuePair this[int frame] } } - private readonly List _accessed; - public byte[] InitialState { get @@ -197,159 +185,6 @@ public void Capture(bool force = false) } } - private void MaybeRemoveStates() - { - // Loop, because removing a state that has a duplicate won't save any space - while (Used + _expectedStateSize > Settings.Cap || DiskUsed > (ulong)Settings.DiskCapacitymb * 1024 * 1024) - { - Point shouldRemove = StateToRemove(); - RemoveState(shouldRemove.X, shouldRemove.Y); - } - - if (Used > Settings.Cap) - { - int lastMemState = -1; - do - { - lastMemState++; - } - while (_states[_accessed[lastMemState].Frame] == null); - MoveStateToDisk(_accessed[lastMemState].Frame); - } - } - - /// - /// X is the frame of the state, Y is the branch (-1 for current). - /// - private Point StateToRemove() - { - // X is frame, Y is branch - Point shouldRemove = new Point(-1, -1); - - if (_branchStates.Any() && Settings.EraseBranchStatesFirst) - { - var kvp = _branchStates.Count > 1 ? _branchStates.ElementAt(1) : _branchStates.ElementAt(0); - shouldRemove.X = kvp.Key; - shouldRemove.Y = kvp.Value.Keys[0]; - - return shouldRemove; - } - - int i = 0; - int markerSkips = MaxStates / 2; - - // lowPrioritySates (e.g. states with only lag frames between them) - do - { - if (_lowPriorityStates.Count > i) - { - shouldRemove = FindState(_lowPriorityStates[i]); - } - else - { - break; - } - - // Keep marker states - markerSkips--; - if (markerSkips < 0) - { - shouldRemove.X = -1; - } - - i++; - } - while ((StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1) || shouldRemove.X == 0); - - // by last accessed - markerSkips = MaxStates / 2; - if (shouldRemove.X < 1) - { - i = 0; - do - { - if (_accessed.Count > i) - { - shouldRemove = FindState(_accessed[i]); - } - else - { - break; - } - - // Keep marker states - markerSkips--; - if (markerSkips < 0) - { - shouldRemove.X = -1; - } - - i++; - } - while ((StateIsMarker(shouldRemove.X, shouldRemove.Y) && markerSkips > -1) || shouldRemove.X == 0); - } - - if (shouldRemove.X < 1) // only found marker states above - { - if (_branchStates.Any() && !Settings.EraseBranchStatesFirst) - { - var kvp = _branchStates.Count > 1 ? _branchStates.ElementAt(1) : _branchStates.ElementAt(0); - shouldRemove.X = kvp.Key; - shouldRemove.Y = kvp.Value.Keys[0]; - } - else - { - StateManagerState s = _states.Values[1]; - shouldRemove.X = s.Frame; - shouldRemove.Y = -1; - } - } - - return shouldRemove; - } - - private bool StateIsMarker(int frame, int branch) - { - if (frame == -1) - { - return false; - } - - if (branch == -1) - { - return _movie.Markers.IsMarker(_states[frame].Frame + 1); - } - - if (_movie.GetBranch(_movie.BranchIndexByHash(branch)).Markers == null) - { - return _movie.Markers.IsMarker(_states[frame].Frame + 1); - } - - return _movie.GetBranch(branch).Markers.Any(m => m.Frame + 1 == frame); - } - - private bool AllLag(int from, int upTo) - { - if (upTo >= Global.Emulator.Frame) - { - upTo = Global.Emulator.Frame - 1; - if (!Global.Emulator.AsInputPollable().IsLagFrame) - { - return false; - } - } - - for (int i = from; i < upTo; i++) - { - if (_movie[i].Lagged == false) - { - return false; - } - } - - return true; - } - private void MoveStateToDisk(int index) { Used -= (ulong)_states[index].Length; @@ -366,16 +201,11 @@ internal void SetState(int frame, byte[] state, bool skipRemoval = true) { if (!skipRemoval) // skipRemoval: false only when capturing new states { - MaybeRemoveStates(); // Remove before adding so this state won't be removed. + LimitStateCount(); // Remove before adding so this state won't be removed. } if (_states.ContainsKey(frame)) { - if (StateHasDuplicate(frame, -1) != -2) - { - Used += (ulong)state.Length; - } - _states[frame].State = state; } else @@ -383,91 +213,6 @@ internal void SetState(int frame, byte[] state, bool skipRemoval = true) Used += (ulong)state.Length; _states.Add(frame, new StateManagerState(this, state, frame)); } - - StateAccessed(frame); - - int i = _states.IndexOfKey(frame); - if (i > 0 && AllLag(_states.Keys[i - 1], _states.Keys[i])) - { - _lowPriorityStates.Add(_states[frame]); - } - } - - private void RemoveState(int frame, int branch = -1) - { - if (branch == -1) - { - _accessed.Remove(_states[frame]); - } - else if (_accessed.Contains(_branchStates[frame][branch]) && !Settings.EraseBranchStatesFirst) - { - _accessed.Remove(_branchStates[frame][branch]); - } - - StateManagerState state; - bool hasDuplicate = StateHasDuplicate(frame, branch) != -2; - if (branch == -1) - { - state = _states[frame]; - if (_states[frame].IsOnDisk) - { - _states[frame].Dispose(); - } - else - { - Used -= (ulong)_states[frame].Length; - } - - _states.RemoveAt(_states.IndexOfKey(frame)); - } - else - { - state = _branchStates[frame][branch]; - - if (_branchStates[frame][branch].IsOnDisk) - { - _branchStates[frame][branch].Dispose(); - } - - _branchStates[frame].RemoveAt(_branchStates[frame].IndexOfKey(branch)); - - if (_branchStates[frame].Count == 0) - { - _branchStates.Remove(frame); - } - } - - if (!hasDuplicate) - { - _lowPriorityStates.Remove(state); - } - } - - private void StateAccessed(int frame) - { - if (frame == 0 && _movie.StartsFromSavestate) - { - return; - } - - StateManagerState state = _states[frame]; - bool removed = _accessed.Remove(state); - _accessed.Add(state); - - if (_states[frame].IsOnDisk) - { - if (!_states[_accessed[0].Frame].IsOnDisk) - { - MoveStateToDisk(_accessed[0].Frame); - } - - MoveStateToMemory(frame); - } - - if (!removed && _accessed.Count > MaxStates) - { - _accessed.RemoveAt(0); - } } public bool HasState(int frame) @@ -489,14 +234,12 @@ public bool Invalidate(int frame) if (Any()) { - if (!_movie.StartsFromSavestate && frame == 0) // Never invalidate frame 0 on a non-savestate-anchored movie + if (frame == 0) // Never invalidate frame 0 { frame = 1; } - List> statesToRemove = - _states.Where(s => s.Key >= frame).ToList(); - + List> statesToRemove = _states.Where(s => s.Key >= frame).ToList(); anyInvalidated = statesToRemove.Any(); foreach (var state in statesToRemove) @@ -510,66 +253,91 @@ public bool Invalidate(int frame) return anyInvalidated; } - /// - /// Clears all state information - /// - public void Clear() + private bool StateIsMarker(int frame) { - _states.Clear(); - _accessed.Clear(); - Used = 0; - ClearDiskStates(); + if (frame == -1) + { + return false; + } + + return _movie.Markers.IsMarker(frame + 1); } - public void ClearStateHistory() - { - if (_states.Any()) - { - StateManagerState power = _states.Values.First(s => s.Frame == 0); - StateAccessed(power.Frame); + private void RemoveState(int frame) + { + int index = _states.IndexOfKey(frame); - _states.Clear(); - _accessed.Clear(); + if (frame < 1 || index < 1) + { + return; + } - SetState(0, power.State); - Used = (ulong)power.State.Length; + StateManagerState state = _states.ElementAt(index).Value; - ClearDiskStates(); + if (state.IsOnDisk) + { + state.Dispose(); + } + else + { + Used -= (ulong)state.Length; } - } - private void ClearDiskStates() - { - NdbDatabase?.Clear(); + _states.RemoveAt(index); } /// /// Deletes/moves states to follow the state storage size limits. - /// Used after changing the settings. + /// Used after changing the settings too. /// public void LimitStateCount() { - while (Used + DiskUsed > Settings.CapTotal) + if (Used + _expectedStateSize > Settings.Cap + || DiskUsed > (ulong)Settings.DiskCapacitymb * 1024 * 1024 + || DateTime.Now.Ticks > _stateCleanupTime) { - Point s = StateToRemove(); - RemoveState(s.X, s.Y); - } + // rely on frames, because relying on indexes while changing the collection is ugly + List framesToClear = new List(); - int index = -1; - while (DiskUsed > (ulong)Settings.DiskCapacitymb * 1024uL * 1024uL) - { - do + // we have 5 greenzone regions, the last one we do not touch + int regionSize = _maxStates / 5; + + // drop states from previous regions, increasing the gap for each one, make sure to ignore state 0 + for (int gap = 2, last = _states.ToList().Count; gap <= 16; gap <<= 1) { - index++; + // last egion index + last -= regionSize; + if (last < 1) + { + return; + } + + // first region index + int first = last - regionSize; + if (first < 1) + { + first = 1; + } + + // iterate through the region and record states' frames + for (int i = last; i >= first; i--) + { + if ((i & (gap - 1)) > 0) + { + framesToClear.Add(_states.ElementAt(i).Key); + } + } } - while (!_accessed[index].IsOnDisk); - _accessed[index].MoveToRAM(); - } + if (framesToClear.Any()) + { + foreach (var frame in framesToClear) + { + RemoveState(frame); + } + } - if (Used > Settings.Cap) - { - MaybeRemoveStates(); + _stateCleanupTime = DateTime.Now.Ticks + _stateCleanupPeriod; } } @@ -583,7 +351,7 @@ private List ExcludeStates() for (int i = 1; i < _states.Count; i++) { if (_movie.Markers.IsMarker(_states.ElementAt(i).Key + 1) - || _states.ElementAt(i).Key % FileStateGap == 0) + || _states.ElementAt(i).Key % _fileStateGap == 0) { continue; } @@ -655,6 +423,18 @@ private List ExcludeStates() return ret; } + public void ClearStateHistory() + { + if (_states.Any()) + { + StateManagerState power = _states.Values.First(s => s.Frame == 0); + _states.Clear(); + SetState(0, power.State); + Used = (ulong)power.State.Length; + NdbDatabase?.Clear(); + } + } + public void Save(BinaryWriter bw) { List noSave = ExcludeStates(); @@ -666,16 +446,20 @@ public void Save(BinaryWriter bw) { continue; } - - StateAccessed(_states.ElementAt(i).Key); + KeyValuePair kvp = _states.ElementAt(i); bw.Write(kvp.Key); bw.Write(kvp.Value.Length); bw.Write(kvp.Value.State); - ////_movie.ReportProgress(100d / States.Count * i); } } + // Map: + // 4 bytes - total savestate count + // [Foreach state] + // 4 bytes - frame + // 4 bytes - length of savestate + // 0 - n savestate public void Load(BinaryReader br) { _states.Clear(); @@ -691,8 +475,6 @@ public void Load(BinaryReader br) // whether we should allow state removal check here is an interesting question // nothing was edited yet, so it might make sense to show the project untouched first SetState(frame, data); - ////States.Add(frame, data); - ////Used += len; } } catch (EndOfStreamException) @@ -700,50 +482,6 @@ public void Load(BinaryReader br) } } - public void SaveBranchStates(BinaryWriter bw) - { - bw.Write(_branchStates.Count); - foreach (var s in _branchStates) - { - bw.Write(s.Key); - bw.Write(s.Value.Count); - foreach (var t in s.Value) - { - bw.Write(t.Key); - t.Value.Write(bw); - } - } - } - - public void LoadBranchStates(BinaryReader br) - { - try - { - int c = br.ReadInt32(); - _branchStates = new SortedList>(c); - while (c > 0) - { - int key = br.ReadInt32(); - int c2 = br.ReadInt32(); - var list = new SortedList(c2); - while (c2 > 0) - { - int key2 = br.ReadInt32(); - var state = StateManagerState.Read(br, this); - list.Add(key2, state); - c2--; - } - - _branchStates.Add(key, list); - c--; - } - } - catch (EndOfStreamException) - { - // Bad! - } - } - public KeyValuePair GetStateClosestToFrame(int frame) { var s = _states.LastOrDefault(state => state.Key < frame); @@ -751,12 +489,6 @@ public KeyValuePair GetStateClosestToFrame(int frame) return this[s.Key]; } - // Map: - // 4 bytes - total savestate count - // [Foreach state] - // 4 bytes - frame - // 4 bytes - length of savestate - // 0 - n savestate private ulong _used; private ulong Used { @@ -830,219 +562,14 @@ public int LastEmulatedFrame } } - #region Branches - - private SortedList> _branchStates = new SortedList>(); - - /// - /// Checks if the state at frame in the given branch (-1 for current) has any duplicates. - /// - /// Index of the branch (-1 for current) of the first match. If no match, returns -2. - private int StateHasDuplicate(int frame, int branchHash) + private int FindState(StateManagerState s) { - StateManagerState stateToMatch; - - // Get the state instance - if (branchHash == -1) - { - stateToMatch = _states[frame]; - } - else - { - if (!_branchStates[frame].ContainsKey(branchHash)) - { - return -2; - } - - stateToMatch = _branchStates[frame][branchHash]; - - // Check the current branch for duplicate. - if (_states.ContainsKey(frame) && _states[frame] == stateToMatch) - { - return -1; - } - } - - // Check if there are any branch states for the given frame. - if (!_branchStates.ContainsKey(frame) || _branchStates[frame] == null || branchHash == -1) - { - return -2; - } - - // Loop through branch states for the given frame. - SortedList stateList = _branchStates[frame]; - for (int i = 0; i < stateList.Count; i++) - { - // Don't check the branch containing the state to match. - if (i == _movie.BranchIndexByHash(branchHash)) - { - continue; - } - - if (stateList.Values[i] == stateToMatch) - { - return i; - } - } - - return -2; // No match. - } - - private Point FindState(StateManagerState s) - { - Point ret = new Point(0, -1); - ret.X = s.Frame; if (!_states.ContainsValue(s)) { - if (_branchStates.ContainsKey(s.Frame)) - { - int index = _branchStates[s.Frame].Values.IndexOf(s); - ret.Y = _branchStates[s.Frame].Keys.ElementAt(index); - } - - if (ret.Y == -1) - { - return new Point(-1, -2); - } - } - - return ret; - } - - public void AddBranch() - { - int branchHash = _movie.BranchHashByIndex(_movie.BranchCount - 1); - - foreach (KeyValuePair kvp in _states) - { - if (!_branchStates.ContainsKey(kvp.Key)) - { - _branchStates.Add(kvp.Key, new SortedList()); - } - - SortedList stateList = _branchStates[kvp.Key]; - - if (stateList == null) // when does this happen? - { - stateList = new SortedList(); - _branchStates[kvp.Key] = stateList; - } - - // We aren't creating any new states, just adding a reference to an already-existing one; so Used doesn't need to be updated. - stateList.Add(branchHash, kvp.Value); - } - } - - public void RemoveBranch(int index) - { - int branchHash = _movie.BranchHashByIndex(index); - - foreach (KeyValuePair> kvp in _branchStates.ToList()) - { - SortedList stateList = kvp.Value; - if (stateList == null) - { - continue; - } - - /* - if (stateList.ContainsKey(branchHash)) - { - if (stateHasDuplicate(kvp.Key, branchHash) == -2) - { - if (!stateList[branchHash].IsOnDisk) - Used -= (ulong)stateList[branchHash].Length; - } - } - */ - stateList.Remove(branchHash); - if (stateList.Count == 0) - { - _branchStates.Remove(kvp.Key); - } - } - } - - public void UpdateBranch(int index) - { - if (index == -1) // backup branch is outsider - { - return; + return -1; } - int branchHash = _movie.BranchHashByIndex(index); - - // RemoveBranch - foreach (KeyValuePair> kvp in _branchStates.ToList()) - { - SortedList stateList = kvp.Value; - if (stateList == null) - { - continue; - } - - /* - if (stateList.ContainsKey(branchHash)) - { - if (stateHasDuplicate(kvp.Key, branchHash) == -2) - { - if (!stateList[branchHash].IsOnDisk) - Used -= (ulong)stateList[branchHash].Length; - } - } - */ - stateList.Remove(branchHash); - if (stateList.Count == 0) - { - _branchStates.Remove(kvp.Key); - } - } - - // AddBranch - foreach (KeyValuePair kvp in _states) - { - if (!_branchStates.ContainsKey(kvp.Key)) - { - _branchStates.Add(kvp.Key, new SortedList()); - } - - SortedList stateList = _branchStates[kvp.Key]; - - if (stateList == null) - { - stateList = new SortedList(); - _branchStates[kvp.Key] = stateList; - } - - stateList.Add(branchHash, kvp.Value); - } - } - - public void LoadBranch(int index) - { - if (index == -1) // backup branch is outsider - { - return; - } - - int branchHash = _movie.BranchHashByIndex(index); - - ////Invalidate(0); // Not a good way of doing it? - - foreach (KeyValuePair> kvp in _branchStates) - { - if (kvp.Key == 0 && _states.ContainsKey(0)) - { - continue; // TODO: It might be a better idea to just not put state 0 in BranchStates. - } - - if (kvp.Value.ContainsKey(branchHash)) - { - SetState(kvp.Key, kvp.Value[branchHash].State); - } - } + return s.Frame; } - - #endregion } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManagerSettings.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManagerSettings.cs index 24aff44e13d..0bd6f4f26ea 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManagerSettings.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManagerSettings.cs @@ -14,8 +14,6 @@ public TasStateManagerSettings() DiskCapacitymb = 1; // not working yet MemStateGapDivider = 64; FileStateGap = 4; - BranchStatesInTasproj = false; - EraseBranchStatesFirst = true; } public TasStateManagerSettings(TasStateManagerSettings settings) @@ -25,8 +23,6 @@ public TasStateManagerSettings(TasStateManagerSettings settings) DiskCapacitymb = settings.DiskCapacitymb; MemStateGapDivider = settings.MemStateGapDivider; FileStateGap = settings.FileStateGap; - BranchStatesInTasproj = settings.BranchStatesInTasproj; - EraseBranchStatesFirst = settings.EraseBranchStatesFirst; } /// @@ -71,20 +67,6 @@ public TasStateManagerSettings(TasStateManagerSettings settings) [Description("The actual state gap in frames is calculated as Nth power on 2")] public int FileStateGap { get; set; } - /// - /// Gets or sets a value indicating whether or not to save branch states into the movie file - /// - [DisplayName("Put branch states to .tasproj")] - [Description("Put branch states to .tasproj")] - public bool BranchStatesInTasproj { get; set; } - - /// - /// Gets or sets a value indicating whether or not to erase branch states before greenzone states when capacity is met - /// - [DisplayName("Erase branch states first")] - [Description("Erase branch states before greenzone states when capacity is met")] - public bool EraseBranchStatesFirst { get; set; } - /// /// The total state capacity in bytes. /// @@ -106,8 +88,6 @@ public override string ToString() sb.AppendLine(DiskSaveCapacitymb.ToString()); sb.AppendLine(Capacitymb.ToString()); sb.AppendLine(DiskCapacitymb.ToString()); - sb.AppendLine(BranchStatesInTasproj.ToString()); - sb.AppendLine(EraseBranchStatesFirst.ToString()); sb.AppendLine(FileStateGap.ToString()); sb.AppendLine(MemStateGapDivider.ToString()); @@ -136,8 +116,6 @@ public void PopulateFromString(string settings) int i = 2; DiskCapacitymb = lines.Length > i ? int.Parse(lines[i++]) : 1; - BranchStatesInTasproj = lines.Length > i && bool.Parse(lines[i++]); - EraseBranchStatesFirst = lines.Length <= i || bool.Parse(lines[i++]); FileStateGap = lines.Length > i ? int.Parse(lines[i++]) : 4; FileStateGap = lines.Length > i ? int.Parse(lines[i++]) : 64; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs index ba490ada908..7c77f6670bf 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs @@ -53,8 +53,6 @@ private void InitializeComponent() this.label8 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.NumSaveStatesLabel = new System.Windows.Forms.Label(); - this.BranchStatesInTasproj = new System.Windows.Forms.CheckBox(); - this.EraseBranchStatesFirst = new System.Windows.Forms.CheckBox(); this.FileStateGapNumeric = new System.Windows.Forms.NumericUpDown(); this.label10 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); @@ -79,7 +77,7 @@ private void InitializeComponent() // this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.CancelBtn.Location = new System.Drawing.Point(242, 259); + this.CancelBtn.Location = new System.Drawing.Point(242, 225); this.CancelBtn.Name = "CancelBtn"; this.CancelBtn.Size = new System.Drawing.Size(60, 23); this.CancelBtn.TabIndex = 0; @@ -90,7 +88,7 @@ private void InitializeComponent() // OkBtn // this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.OkBtn.Location = new System.Drawing.Point(176, 259); + this.OkBtn.Location = new System.Drawing.Point(176, 225); this.OkBtn.Name = "OkBtn"; this.OkBtn.Size = new System.Drawing.Size(60, 23); this.OkBtn.TabIndex = 1; @@ -177,8 +175,9 @@ private void InitializeComponent() // // DiskCapacityNumeric // + this.DiskCapacityNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.DiskCapacityNumeric.Enabled = false; - this.DiskCapacityNumeric.Location = new System.Drawing.Point(24, 241); + this.DiskCapacityNumeric.Location = new System.Drawing.Point(24, 215); this.DiskCapacityNumeric.Maximum = new decimal(new int[] { 16384, 0, @@ -201,9 +200,10 @@ private void InitializeComponent() // // label5 // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label5.AutoSize = true; this.label5.Enabled = false; - this.label5.Location = new System.Drawing.Point(79, 244); + this.label5.Location = new System.Drawing.Point(79, 218); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(23, 13); this.label5.TabIndex = 4; @@ -211,9 +211,10 @@ private void InitializeComponent() // // label6 // + this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label6.AutoSize = true; this.label6.Enabled = false; - this.label6.Location = new System.Drawing.Point(21, 224); + this.label6.Location = new System.Drawing.Point(21, 198); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(72, 13); this.label6.TabIndex = 5; @@ -273,32 +274,6 @@ private void InitializeComponent() this.NumSaveStatesLabel.TabIndex = 9; this.NumSaveStatesLabel.Text = "1"; // - // BranchStatesInTasproj - // - this.BranchStatesInTasproj.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.BranchStatesInTasproj.AutoSize = true; - this.BranchStatesInTasproj.Location = new System.Drawing.Point(12, 153); - this.BranchStatesInTasproj.Name = "BranchStatesInTasproj"; - this.BranchStatesInTasproj.Size = new System.Drawing.Size(118, 17); - this.BranchStatesInTasproj.TabIndex = 10; - this.BranchStatesInTasproj.Text = "Save branch states"; - this.BranchStatesInTasproj.UseVisualStyleBackColor = true; - this.BranchStatesInTasproj.CheckedChanged += new System.EventHandler(this.BranchStatesInTasproj_CheckedChanged); - // - // EraseBranchStatesFirst - // - this.EraseBranchStatesFirst.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.EraseBranchStatesFirst.AutoSize = true; - this.EraseBranchStatesFirst.Checked = true; - this.EraseBranchStatesFirst.CheckState = System.Windows.Forms.CheckState.Checked; - this.EraseBranchStatesFirst.Location = new System.Drawing.Point(6, 153); - this.EraseBranchStatesFirst.Name = "EraseBranchStatesFirst"; - this.EraseBranchStatesFirst.Size = new System.Drawing.Size(139, 17); - this.EraseBranchStatesFirst.TabIndex = 11; - this.EraseBranchStatesFirst.Text = "Erase branch states first"; - this.EraseBranchStatesFirst.UseVisualStyleBackColor = true; - this.EraseBranchStatesFirst.CheckedChanged += new System.EventHandler(this.EraseBranchStatesFIrst_CheckedChanged); - // // FileStateGapNumeric // this.FileStateGapNumeric.Location = new System.Drawing.Point(12, 100); @@ -351,13 +326,12 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.label13); this.groupBox1.Controls.Add(this.MemStateGapDividerNumeric); this.groupBox1.Controls.Add(this.label12); - this.groupBox1.Controls.Add(this.EraseBranchStatesFirst); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.MemCapacityNumeric); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Location = new System.Drawing.Point(12, 34); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(143, 176); + this.groupBox1.Size = new System.Drawing.Size(143, 147); this.groupBox1.TabIndex = 16; this.groupBox1.TabStop = false; this.groupBox1.Text = "Memory Usage"; @@ -427,7 +401,6 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.FileCapacityNumeric); this.groupBox2.Controls.Add(this.FileNumFramesLabel); this.groupBox2.Controls.Add(this.label7); - this.groupBox2.Controls.Add(this.BranchStatesInTasproj); this.groupBox2.Controls.Add(this.label11); this.groupBox2.Controls.Add(this.label9); this.groupBox2.Controls.Add(this.label10); @@ -435,7 +408,7 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.FileStateGapNumeric); this.groupBox2.Location = new System.Drawing.Point(163, 34); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(138, 176); + this.groupBox2.Size = new System.Drawing.Size(138, 147); this.groupBox2.TabIndex = 17; this.groupBox2.TabStop = false; this.groupBox2.Text = "Project File"; @@ -446,7 +419,7 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.CancelBtn; - this.ClientSize = new System.Drawing.Size(315, 294); + this.ClientSize = new System.Drawing.Size(315, 260); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.DiskCapacityNumeric); @@ -495,8 +468,6 @@ private void InitializeComponent() private Label label8; private Label label9; private Label NumSaveStatesLabel; - private CheckBox BranchStatesInTasproj; - private CheckBox EraseBranchStatesFirst; private NumericUpDown FileStateGapNumeric; private Label label10; private Label label11; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs index 772f8cec7a4..3dcc360e309 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs @@ -42,8 +42,6 @@ private void StateHistorySettings_Load(object sender, EventArgs e) SavestateSizeLabel.Text = Math.Round(_stateSizeMb, 2).ToString() + " MB"; CapacityNumeric_ValueChanged(null, null); SaveCapacityNumeric_ValueChanged(null, null); - BranchStatesInTasproj.Checked = _settings.BranchStatesInTasproj; - EraseBranchStatesFirst.Checked = _settings.EraseBranchStatesFirst; } private int MaxStatesInCapacity => (int)Math.Floor(MemCapacityNumeric.Value / _stateSizeMb) @@ -78,16 +76,6 @@ private void SaveCapacityNumeric_ValueChanged(object sender, EventArgs e) NumSaveStatesLabel.Text = ((int)Math.Floor(FileCapacityNumeric.Value / _stateSizeMb)).ToString(); } - private void BranchStatesInTasproj_CheckedChanged(object sender, EventArgs e) - { - _settings.BranchStatesInTasproj = BranchStatesInTasproj.Checked; - } - - private void EraseBranchStatesFIrst_CheckedChanged(object sender, EventArgs e) - { - _settings.EraseBranchStatesFirst = EraseBranchStatesFirst.Checked; - } - private void FileStateGap_ValueChanged(object sender, EventArgs e) { FileNumFramesLabel.Text = FileStateGapNumeric.Value == 0