TasStateManager - simplify MaxState logic and actually fix the math so it isn't 2x of what is intended
This commit is contained in:
parent
45fd7ee81e
commit
604f4ce833
|
@ -25,13 +25,12 @@ namespace BizHawk.Client.Common
|
|||
private readonly ITasMovie _movie;
|
||||
|
||||
private readonly SortedList<int, byte[]> _states;
|
||||
private readonly ulong _expectedStateSize;
|
||||
private readonly double _expectedStateSizeInMb;
|
||||
|
||||
private ulong _used;
|
||||
private int _stateFrequency;
|
||||
|
||||
private int MaxStates => (int)(Settings.Cap / _expectedStateSize) +
|
||||
(int)((ulong)Settings.DiskCapacityMb * 1024 * 1024 / _expectedStateSize);
|
||||
private int MaxStates => (int)(Settings.CapacityMb / _expectedStateSizeInMb + 1);
|
||||
private int FileStateGap => 1 << Settings.FileStateGap;
|
||||
|
||||
/// <exception cref="InvalidOperationException">loaded core expects savestate size of <c>0 B</c></exception>
|
||||
|
@ -47,8 +46,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
_decay = new StateManagerDecay(_movie, this);
|
||||
|
||||
_expectedStateSize = (ulong)Core.CloneSavestate().Length; // TODO: why do we store this in a ulong?
|
||||
if (_expectedStateSize == 0)
|
||||
_expectedStateSizeInMb = Core.CloneSavestate().Length / (double)(1024 * 1024);
|
||||
if (_expectedStateSizeInMb.HawkFloatEquality(0))
|
||||
{
|
||||
throw new InvalidOperationException("Savestate size can not be zero!");
|
||||
}
|
||||
|
@ -103,7 +102,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void UpdateStateFrequency()
|
||||
{
|
||||
_stateFrequency = ((int)_expectedStateSize / Settings.MemStateGapDivider / 1024)
|
||||
_stateFrequency = ((int)_expectedStateSizeInMb / Settings.MemStateGapDivider / 1024)
|
||||
.Clamp(MinFrequency, MaxFrequency);
|
||||
|
||||
_decay.UpdateSettings(MaxStates, _stateFrequency, 4);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -64,12 +63,5 @@ namespace BizHawk.Client.Common
|
|||
[DisplayName("State interval for .tasproj")]
|
||||
[Description("The actual state gap in frames is calculated as Nth power on 2")]
|
||||
public int FileStateGap { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The memory state capacity in bytes.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
[Browsable(false)]
|
||||
public ulong Cap => (ulong)CapacityMb * 1024UL * 1024UL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue