Skip to content

Commit

Permalink
smart state gap for greenzone. fix #915
Browse files Browse the repository at this point in the history
disable disk capacity setting
  • Loading branch information
vadosnaprimer committed Jan 2, 2018
1 parent 103fb34 commit 8e9b5af
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 120 deletions.
14 changes: 6 additions & 8 deletions BizHawk.Client.Common/movie/tasproj/TasStateManager.cs
Expand Up @@ -44,14 +44,16 @@ private string StatePath
private readonly TasMovie _movie;
private ulong _expectedStateSize;

private readonly int _minFrequency = VersionInfo.DeveloperBuild ? 2 : 1;
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 int StateFrequency
{
get
{
int freq = (int)(_expectedStateSize / 65536);
int freq = (int)_expectedStateSize / Settings.MemStateGapDivider / 1024;

if (freq < _minFrequency)
{
Expand All @@ -66,11 +68,7 @@ private int StateFrequency
return freq;
}
}

private int MaxStates => (int)(Settings.Cap / _expectedStateSize) + (int)((ulong)Settings.DiskCapacitymb * 1024 * 1024 / _expectedStateSize);

private int StateGap => 1 << Settings.StateGap;


public TasStateManager(TasMovie movie)
{
_movie = movie;
Expand Down Expand Up @@ -585,7 +583,7 @@ private List<int> ExcludeStates()
for (int i = 1; i < _states.Count; i++)
{
if (_movie.Markers.IsMarker(_states.ElementAt(i).Key + 1)
|| _states.ElementAt(i).Key % StateGap == 0)
|| _states.ElementAt(i).Key % FileStateGap == 0)
{
continue;
}
Expand Down
32 changes: 21 additions & 11 deletions BizHawk.Client.Common/movie/tasproj/TasStateManagerSettings.cs
Expand Up @@ -11,8 +11,9 @@ public TasStateManagerSettings()
{
DiskSaveCapacitymb = 512;
Capacitymb = 512;
DiskCapacitymb = 512;
StateGap = 4;
DiskCapacitymb = 1; // not working yet
MemStateGapDivider = 64;
FileStateGap = 4;
BranchStatesInTasproj = false;
EraseBranchStatesFirst = true;
}
Expand All @@ -22,7 +23,8 @@ public TasStateManagerSettings(TasStateManagerSettings settings)
DiskSaveCapacitymb = settings.DiskSaveCapacitymb;
Capacitymb = settings.Capacitymb;
DiskCapacitymb = settings.DiskCapacitymb;
StateGap = settings.StateGap;
MemStateGapDivider = settings.MemStateGapDivider;
FileStateGap = settings.FileStateGap;
BranchStatesInTasproj = settings.BranchStatesInTasproj;
EraseBranchStatesFirst = settings.EraseBranchStatesFirst;
}
Expand Down Expand Up @@ -55,12 +57,19 @@ public TasStateManagerSettings(TasStateManagerSettings settings)
[Description("The size limit of the state history buffer on the disk. When this limit is reached it will start removing previous savestates")]
public int DiskCapacitymb { get; set; }

/// <summary>
/// Gets or sets the divider that determines memory state gap
/// </summary>
[DisplayName("Divider for memory state interval")]
[Description("The actual state gap in frames is calculated as ExpectedStateSize / div / 1024")]
public int MemStateGapDivider { get; set; }

/// <summary>
/// Gets or sets the amount of states to skip during project saving
/// </summary>
[DisplayName("State interval for .tasproj")]
[Description("The actual state gap in frames is calculated as Nth power on 2")]
public int StateGap { get; set; }
public int FileStateGap { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to save branch states into the movie file
Expand Down Expand Up @@ -99,7 +108,8 @@ public override string ToString()
sb.AppendLine(DiskCapacitymb.ToString());
sb.AppendLine(BranchStatesInTasproj.ToString());
sb.AppendLine(EraseBranchStatesFirst.ToString());
sb.AppendLine(StateGap.ToString());
sb.AppendLine(FileStateGap.ToString());
sb.AppendLine(MemStateGapDivider.ToString());

return sb.ToString();
}
Expand All @@ -123,13 +133,13 @@ public void PopulateFromString(string settings)
DiskSaveCapacitymb = refCapacity;
}

DiskCapacitymb = lines.Length > 2 ? int.Parse(lines[2]) : 512;

BranchStatesInTasproj = lines.Length > 3 && bool.Parse(lines[3]);

EraseBranchStatesFirst = lines.Length <= 4 || bool.Parse(lines[4]);
int i = 2;

StateGap = lines.Length > 5 ? int.Parse(lines[5]) : 4;
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;
}
catch (Exception) // TODO: this is bad
{
Expand Down

0 comments on commit 8e9b5af

Please sign in to comment.