From 661a15dc2cfe08901c22d5667ed74c0920ba6d3b Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 11 Mar 2018 17:57:03 +0300 Subject: [PATCH] tsm decay: remove states within internal state gap states settings: clamp things harder --- .../movie/tasproj/StateManagerDecay.cs | 34 ++++++++++++++++++- .../tools/TAStudio/GreenzoneSettings.cs | 15 ++++---- .../tools/TAStudio/TAStudio.cs | 2 +- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/StateManagerDecay.cs b/BizHawk.Client.Common/movie/tasproj/StateManagerDecay.cs index 10695e8a94..7cf5fbdccd 100644 --- a/BizHawk.Client.Common/movie/tasproj/StateManagerDecay.cs +++ b/BizHawk.Client.Common/movie/tasproj/StateManagerDecay.cs @@ -53,6 +53,7 @@ namespace BizHawk.Client.Common _align = false; } + // todo: go through all states once, remove as many as we need. refactor to not need goto public void Trigger(int decayStates) { for (; decayStates > 0 && _tsm.StateCount > 1;) @@ -72,6 +73,15 @@ namespace BizHawk.Client.Common { continue; } + else if (currentFrame % _step > 0) + { + // ignore the pattern if the state doesn't belong already, drop it blindly and skip everything + _tsm.RemoveState(currentFrame); + decayStates--; + + // this is the kind of highly complex loops that might justify goto + goto next_state; + } else { currentFrame /= _step; @@ -96,10 +106,23 @@ namespace BizHawk.Client.Common { int currentFrame = _tsm.GetStateFrameByIndex(currentStateIndex) / _step; - if (_tsm.StateIsMarker(currentFrame * _step)) + if (_tsm.StateIsMarker(currentFrame)) { continue; } + else if (currentFrame % _step > 0) + { + // ignore the pattern if the state doesn't belong already, drop it blindly and skip everything + _tsm.RemoveState(currentFrame); + decayStates--; + + // this is the kind of highly complex loops that might justify goto + goto next_state; + } + else + { + currentFrame /= _step; + } int zeroCount = _zeros[currentFrame & _mask]; int priority = ((currentFrame - baseStateFrame) >> zeroCount); @@ -139,6 +162,15 @@ namespace BizHawk.Client.Common _tsm.RemoveState(backwardFrame * _step); decayStates--; } + else + { + // we're very sorry about failing to find states to remove, but we can't go beyond capacity, so remove at least something + // this shouldn't happen, but if we don't do it here, nothing good will happen either + _tsm.RemoveState(_tsm.GetStateFrameByIndex(1)); + } + + // this is the kind of highly complex loops that might justify goto + next_state:; } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs index b579cba631..612f788cce 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs @@ -25,18 +25,15 @@ namespace BizHawk.Client.EmuHawk _stateSizeMb = Statable.SaveStateBinary().Length / (decimal)1024 / (decimal)1024; MemCapacityNumeric.Maximum = 1024 * 8; - - MemCapacityNumeric.Value = _settings.Capacitymb < MemCapacityNumeric.Maximum ? - _settings.Capacitymb : MemCapacityNumeric.Maximum; - DiskCapacityNumeric.Value = _settings.DiskCapacitymb < MemCapacityNumeric.Maximum ? - _settings.DiskCapacitymb : MemCapacityNumeric.Maximum; - FileCapacityNumeric.Value = _settings.DiskSaveCapacitymb < MemCapacityNumeric.Maximum ? - _settings.DiskSaveCapacitymb : MemCapacityNumeric.Maximum; + MemCapacityNumeric.Minimum = _stateSizeMb + 1; MemStateGapDividerNumeric.Maximum = Statable.SaveStateBinary().Length / 1024 / 2 + 1; MemStateGapDividerNumeric.Minimum = Math.Max(Statable.SaveStateBinary().Length / 1024 / 16, 1); - MemStateGapDividerNumeric.Value = NumberExtensions.Clamp(_settings.MemStateGapDivider, - MemStateGapDividerNumeric.Minimum, MemStateGapDividerNumeric.Maximum); + + MemCapacityNumeric.Value = NumberExtensions.Clamp(_settings.Capacitymb, MemCapacityNumeric.Minimum, MemCapacityNumeric.Maximum); + DiskCapacityNumeric.Value = NumberExtensions.Clamp(_settings.DiskCapacitymb, MemCapacityNumeric.Minimum, MemCapacityNumeric.Maximum); + FileCapacityNumeric.Value = NumberExtensions.Clamp(_settings.DiskSaveCapacitymb, MemCapacityNumeric.Minimum, MemCapacityNumeric.Maximum); + MemStateGapDividerNumeric.Value = NumberExtensions.Clamp(_settings.MemStateGapDivider, MemStateGapDividerNumeric.Minimum, MemStateGapDividerNumeric.Maximum); FileStateGapNumeric.Value = _settings.FileStateGap; SavestateSizeLabel.Text = Math.Round(_stateSizeMb, 2).ToString() + " MB"; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 4798152a59..f4c55250d8 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -940,7 +940,7 @@ namespace BizHawk.Client.EmuHawk SplicerStatusLabel.Text = "Selected: " + TasView.SelectedRows.Count() + " frame" + (TasView.SelectedRows.Count() == 1 ? "" : "s") + - ", State count: " + CurrentTasMovie.TasStateManager.StateCount.ToString() + + ", States: " + CurrentTasMovie.TasStateManager.StateCount.ToString() + ", Clipboard: " + (_tasClipboard.Any() ? _tasClipboard.Count + " frame" + (_tasClipboard.Count == 1 ? "" : "s") : "empty"); }