tastudio: "Erase branch states before all the rest" option.

fixed branch info loading.
This commit is contained in:
feos 2015-10-06 21:51:03 +03:00
parent e0c2e43e48
commit ef5369a443
4 changed files with 73 additions and 27 deletions

View File

@ -221,11 +221,20 @@ namespace BizHawk.Client.Common
/// </summary>
private Point StateToRemove()
{
int markerSkips = maxStates / 2;
// 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
{
@ -263,7 +272,7 @@ namespace BizHawk.Client.Common
if (shouldRemove.X < 1) // only found marker states above
{
if (BranchStates.Any())
if (BranchStates.Any() && !Settings.EraseBranchStatesFirst)
{
var kvp = BranchStates.Count() > 1 ? BranchStates.ElementAt(1) : BranchStates.ElementAt(0);
shouldRemove.X = kvp.Key;
@ -356,7 +365,7 @@ namespace BizHawk.Client.Common
{
if (branch == -1)
accessed.Remove(States[frame]);
else if (accessed.Contains(BranchStates[frame][branch]))
else if (accessed.Contains(BranchStates[frame][branch]) && !Settings.EraseBranchStatesFirst)
accessed.Remove(BranchStates[frame][branch]);
StateManagerState state;
@ -591,31 +600,31 @@ namespace BizHawk.Client.Common
}
//}
if (br.PeekChar() == -1) // at least don't crash when loading an old project
return;
currentBranch = br.ReadInt32();
if (Settings.BranchStatesInTasproj)
try
{
int c = br.ReadInt32();
BranchStates = new SortedList<int, SortedList<int, StateManagerState>>(c);
while (c > 0)
currentBranch = br.ReadInt32();
if (Settings.BranchStatesInTasproj)
{
int key = br.ReadInt32();
int c2 = br.ReadInt32();
var list = new SortedList<int, StateManagerState>(c2);
while (c2 > 0)
int c = br.ReadInt32();
BranchStates = new SortedList<int, SortedList<int, StateManagerState>>(c);
while (c > 0)
{
int key2 = br.ReadInt32();
var state = StateManagerState.Read(br, this);
list.Add(key2, state);
c2--;
int key = br.ReadInt32();
int c2 = br.ReadInt32();
var list = new SortedList<int, StateManagerState>(c2);
while (c2 > 0)
{
int key2 = br.ReadInt32();
var state = StateManagerState.Read(br, this);
list.Add(key2, state);
c2--;
}
BranchStates.Add(key, list);
c--;
}
BranchStates.Add(key, list);
c--;
}
}
catch (EndOfStreamException) { }
}
public KeyValuePair<int, byte[]> GetStateClosestToFrame(int frame)

View File

@ -14,6 +14,7 @@ namespace BizHawk.Client.Common
Capacitymb = 512;
DiskCapacitymb = 512;
BranchStatesInTasproj = false;
EraseBranchStatesFirst = true;
}
public TasStateManagerSettings(TasStateManagerSettings settings)
@ -22,6 +23,7 @@ namespace BizHawk.Client.Common
Capacitymb = settings.Capacitymb;
DiskCapacitymb = settings.DiskCapacitymb;
BranchStatesInTasproj = settings.BranchStatesInTasproj;
EraseBranchStatesFirst = settings.EraseBranchStatesFirst;
}
/// <summary>
@ -59,6 +61,13 @@ namespace BizHawk.Client.Common
[Description("Put branch states to .tasproj")]
public bool BranchStatesInTasproj { get; set; }
/// <summary>
/// Erase branch states before greenzone states when capacity is met
/// </summary>
[DisplayName("Erase branch states first")]
[Description("Erase branch states before greenzone states when capacity is met")]
public bool EraseBranchStatesFirst { get; set; }
/// <summary>
/// The total state capacity in bytes.
/// </summary>
@ -87,6 +96,7 @@ namespace BizHawk.Client.Common
sb.AppendLine(Capacitymb.ToString());
sb.AppendLine(DiskCapacitymb.ToString());
sb.AppendLine(BranchStatesInTasproj.ToString());
sb.AppendLine(EraseBranchStatesFirst.ToString());
return sb.ToString();
}
@ -118,6 +128,11 @@ namespace BizHawk.Client.Common
BranchStatesInTasproj = bool.Parse(lines[3]);
else
BranchStatesInTasproj = false;
if (lines.Length > 4)
EraseBranchStatesFirst = bool.Parse(lines[4]);
else
EraseBranchStatesFirst = true;
}
}
}

View File

@ -54,6 +54,7 @@ namespace BizHawk.Client.EmuHawk
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();
((System.ComponentModel.ISupportInitialize)(this.MemCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.DiskCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.SaveCapacityNumeric)).BeginInit();
@ -63,7 +64,7 @@ namespace BizHawk.Client.EmuHawk
//
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(216, 143);
this.CancelBtn.Location = new System.Drawing.Point(216, 163);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.TabIndex = 0;
@ -74,7 +75,7 @@ namespace BizHawk.Client.EmuHawk
// 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(150, 143);
this.OkBtn.Location = new System.Drawing.Point(150, 163);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.TabIndex = 1;
@ -252,7 +253,7 @@ namespace BizHawk.Client.EmuHawk
// BranchStatesInTasproj
//
this.BranchStatesInTasproj.AutoSize = true;
this.BranchStatesInTasproj.Location = new System.Drawing.Point(12, 118);
this.BranchStatesInTasproj.Location = new System.Drawing.Point(12, 115);
this.BranchStatesInTasproj.Name = "BranchStatesInTasproj";
this.BranchStatesInTasproj.Size = new System.Drawing.Size(158, 17);
this.BranchStatesInTasproj.TabIndex = 10;
@ -260,13 +261,27 @@ namespace BizHawk.Client.EmuHawk
this.BranchStatesInTasproj.UseVisualStyleBackColor = true;
this.BranchStatesInTasproj.CheckedChanged += new System.EventHandler(this.BranchStatesInTasproj_CheckedChanged);
//
// EraseBranchStatesFirst
//
this.EraseBranchStatesFirst.AutoSize = true;
this.EraseBranchStatesFirst.Checked = true;
this.EraseBranchStatesFirst.CheckState = System.Windows.Forms.CheckState.Checked;
this.EraseBranchStatesFirst.Location = new System.Drawing.Point(12, 140);
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);
//
// StateHistorySettingsForm
//
this.AcceptButton = this.OkBtn;
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(288, 178);
this.ClientSize = new System.Drawing.Size(288, 198);
this.Controls.Add(this.EraseBranchStatesFirst);
this.Controls.Add(this.BranchStatesInTasproj);
this.Controls.Add(this.NumSaveStatesLabel);
this.Controls.Add(this.NumStatesLabel);
@ -317,5 +332,6 @@ namespace BizHawk.Client.EmuHawk
private Label label9;
private Label NumSaveStatesLabel;
private CheckBox BranchStatesInTasproj;
private CheckBox EraseBranchStatesFirst;
}
}

View File

@ -45,6 +45,7 @@ namespace BizHawk.Client.EmuHawk
CapacityNumeric_ValueChanged(null, null);
SaveCapacityNumeric_ValueChanged(null, null);
BranchStatesInTasproj.Checked = Settings.BranchStatesInTasproj;
EraseBranchStatesFirst.Checked = Settings.EraseBranchStatesFirst;
}
private int MaxStatesInCapacity
@ -85,5 +86,10 @@ namespace BizHawk.Client.EmuHawk
{
Settings.BranchStatesInTasproj = BranchStatesInTasproj.Checked;
}
private void EraseBranchStatesFIrst_CheckedChanged(object sender, EventArgs e)
{
Settings.EraseBranchStatesFirst = EraseBranchStatesFirst.Checked;
}
}
}