tastudio: add an option for (not) using branch states in tasproj.

clueless about what should go in its description.
fixed new guid being assigned to branches loaded from the project.
This commit is contained in:
feos 2015-10-05 22:11:45 +03:00
parent 31e476a3cd
commit e0c2e43e48
5 changed files with 107 additions and 60 deletions

View File

@ -25,10 +25,13 @@ namespace BizHawk.Client.Common
{
public new void Add(TasBranch item)
{
var currentHashes = this.Select(b => b.UniqueIdentifier.GetHashCode()).ToList();
if (item.UniqueIdentifier == Guid.Empty)
{
var currentHashes = this.Select(b => b.UniqueIdentifier.GetHashCode()).ToList();
do item.UniqueIdentifier = Guid.NewGuid();
while (currentHashes.Contains(item.UniqueIdentifier.GetHashCode()));
do item.UniqueIdentifier = Guid.NewGuid();
while (currentHashes.Contains(item.UniqueIdentifier.GetHashCode()));
}
base.Add(item);
}

View File

@ -503,38 +503,6 @@ namespace BizHawk.Client.Common
MaybeRemoveStates();
}
// TODO: save/load BranchStates
public void Save(BinaryWriter bw)
{
List<int> noSave = ExcludeStates();
bw.Write(States.Count - noSave.Count);
for (int i = 0; i < States.Count; i++)
{
if (noSave.Contains(i))
continue;
StateAccessed(States.ElementAt(i).Key);
KeyValuePair<int, StateManagerState> kvp = States.ElementAt(i);
bw.Write(kvp.Key);
bw.Write(kvp.Value.Length);
bw.Write(kvp.Value.State);
}
bw.Write(currentBranch);
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);
}
}
}
private List<int> ExcludeStates()
{
List<int> ret = new List<int>();
@ -569,6 +537,41 @@ namespace BizHawk.Client.Common
return ret;
}
public void Save(BinaryWriter bw)
{
List<int> noSave = ExcludeStates();
bw.Write(States.Count - noSave.Count);
for (int i = 0; i < States.Count; i++)
{
if (noSave.Contains(i))
continue;
StateAccessed(States.ElementAt(i).Key);
KeyValuePair<int, StateManagerState> kvp = States.ElementAt(i);
bw.Write(kvp.Key);
bw.Write(kvp.Value.Length);
bw.Write(kvp.Value.State);
}
bw.Write(currentBranch);
if (Settings.BranchStatesInTasproj)
{
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 Load(BinaryReader br)
{
States.Clear();
@ -592,22 +595,26 @@ namespace BizHawk.Client.Common
return;
currentBranch = br.ReadInt32();
int c = br.ReadInt32();
BranchStates = new SortedList<int, SortedList<int, StateManagerState>>(c);
while (c > 0)
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--;
}
}

View File

@ -13,6 +13,7 @@ namespace BizHawk.Client.Common
DiskSaveCapacitymb = 512;
Capacitymb = 512;
DiskCapacitymb = 512;
BranchStatesInTasproj = false;
}
public TasStateManagerSettings(TasStateManagerSettings settings)
@ -20,6 +21,7 @@ namespace BizHawk.Client.Common
DiskSaveCapacitymb = settings.DiskSaveCapacitymb;
Capacitymb = settings.Capacitymb;
DiskCapacitymb = settings.DiskCapacitymb;
BranchStatesInTasproj = settings.BranchStatesInTasproj;
}
/// <summary>
@ -50,6 +52,13 @@ namespace BizHawk.Client.Common
[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>
/// Put branch states to .tasproj
/// </summary>
[DisplayName("Put branch states to .tasproj")]
[Description("Put branch states to .tasproj")]
public bool BranchStatesInTasproj { get; set; }
/// <summary>
/// The total state capacity in bytes.
/// </summary>
@ -77,6 +86,7 @@ namespace BizHawk.Client.Common
sb.AppendLine(DiskSaveCapacitymb.ToString());
sb.AppendLine(Capacitymb.ToString());
sb.AppendLine(DiskCapacitymb.ToString());
sb.AppendLine(BranchStatesInTasproj.ToString());
return sb.ToString();
}
@ -88,6 +98,7 @@ namespace BizHawk.Client.Common
string[] lines = settings.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
Capacitymb = int.Parse(lines[1]);
int refCapacity;
if (!int.TryParse(lines[0], out refCapacity))
{
if (bool.Parse(lines[0]))
@ -97,10 +108,16 @@ namespace BizHawk.Client.Common
}
else
DiskSaveCapacitymb = refCapacity;
if (lines.Length > 2)
DiskCapacitymb = int.Parse(lines[2]);
else
DiskCapacitymb = 512;
if (lines.Length > 3)
BranchStatesInTasproj = bool.Parse(lines[3]);
else
BranchStatesInTasproj = false;
}
}
}

View File

@ -53,6 +53,7 @@ namespace BizHawk.Client.EmuHawk
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();
((System.ComponentModel.ISupportInitialize)(this.MemCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.DiskCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.SaveCapacityNumeric)).BeginInit();
@ -62,7 +63,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, 113);
this.CancelBtn.Location = new System.Drawing.Point(216, 143);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.TabIndex = 0;
@ -73,7 +74,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, 113);
this.OkBtn.Location = new System.Drawing.Point(150, 143);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.TabIndex = 1;
@ -116,7 +117,7 @@ namespace BizHawk.Client.EmuHawk
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 9);
this.label2.Location = new System.Drawing.Point(9, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 13);
this.label2.TabIndex = 5;
@ -125,7 +126,7 @@ namespace BizHawk.Client.EmuHawk
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(126, 9);
this.label3.Location = new System.Drawing.Point(147, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(79, 13);
this.label3.TabIndex = 6;
@ -134,7 +135,7 @@ namespace BizHawk.Client.EmuHawk
// SavestateSizeLabel
//
this.SavestateSizeLabel.AutoSize = true;
this.SavestateSizeLabel.Location = new System.Drawing.Point(208, 9);
this.SavestateSizeLabel.Location = new System.Drawing.Point(229, 9);
this.SavestateSizeLabel.Name = "SavestateSizeLabel";
this.SavestateSizeLabel.Size = new System.Drawing.Size(25, 13);
this.SavestateSizeLabel.TabIndex = 7;
@ -188,7 +189,7 @@ namespace BizHawk.Client.EmuHawk
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(12, 49);
this.label6.Location = new System.Drawing.Point(9, 49);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 13);
this.label6.TabIndex = 5;
@ -196,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
//
// SaveCapacityNumeric
//
this.SaveCapacityNumeric.Location = new System.Drawing.Point(158, 66);
this.SaveCapacityNumeric.Location = new System.Drawing.Point(150, 66);
this.SaveCapacityNumeric.Maximum = new decimal(new int[] {
65536,
0,
@ -215,7 +216,7 @@ namespace BizHawk.Client.EmuHawk
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(213, 69);
this.label7.Location = new System.Drawing.Point(205, 69);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(21, 13);
this.label7.TabIndex = 4;
@ -224,7 +225,7 @@ namespace BizHawk.Client.EmuHawk
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(158, 49);
this.label8.Location = new System.Drawing.Point(147, 49);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(112, 13);
this.label8.TabIndex = 5;
@ -233,7 +234,7 @@ namespace BizHawk.Client.EmuHawk
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(155, 89);
this.label9.Location = new System.Drawing.Point(147, 89);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(84, 13);
this.label9.TabIndex = 8;
@ -242,19 +243,31 @@ namespace BizHawk.Client.EmuHawk
// NumSaveStatesLabel
//
this.NumSaveStatesLabel.AutoSize = true;
this.NumSaveStatesLabel.Location = new System.Drawing.Point(242, 89);
this.NumSaveStatesLabel.Location = new System.Drawing.Point(234, 89);
this.NumSaveStatesLabel.Name = "NumSaveStatesLabel";
this.NumSaveStatesLabel.Size = new System.Drawing.Size(25, 13);
this.NumSaveStatesLabel.TabIndex = 9;
this.NumSaveStatesLabel.Text = "1kb";
//
// BranchStatesInTasproj
//
this.BranchStatesInTasproj.AutoSize = true;
this.BranchStatesInTasproj.Location = new System.Drawing.Point(12, 118);
this.BranchStatesInTasproj.Name = "BranchStatesInTasproj";
this.BranchStatesInTasproj.Size = new System.Drawing.Size(158, 17);
this.BranchStatesInTasproj.TabIndex = 10;
this.BranchStatesInTasproj.Text = "Put branch states to .tasproj";
this.BranchStatesInTasproj.UseVisualStyleBackColor = true;
this.BranchStatesInTasproj.CheckedChanged += new System.EventHandler(this.BranchStatesInTasproj_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, 148);
this.ClientSize = new System.Drawing.Size(288, 178);
this.Controls.Add(this.BranchStatesInTasproj);
this.Controls.Add(this.NumSaveStatesLabel);
this.Controls.Add(this.NumStatesLabel);
this.Controls.Add(this.label9);
@ -303,5 +316,6 @@ namespace BizHawk.Client.EmuHawk
private Label label8;
private Label label9;
private Label NumSaveStatesLabel;
private CheckBox BranchStatesInTasproj;
}
}

View File

@ -44,6 +44,7 @@ namespace BizHawk.Client.EmuHawk
SavestateSizeLabel.Text = Math.Round(_stateSizeMb, 2).ToString() + " mb";
CapacityNumeric_ValueChanged(null, null);
SaveCapacityNumeric_ValueChanged(null, null);
BranchStatesInTasproj.Checked = Settings.BranchStatesInTasproj;
}
private int MaxStatesInCapacity
@ -79,5 +80,10 @@ namespace BizHawk.Client.EmuHawk
{
NumSaveStatesLabel.Text = ((int)Math.Floor(SaveCapacityNumeric.Value / _stateSizeMb)).ToString();
}
private void BranchStatesInTasproj_CheckedChanged(object sender, EventArgs e)
{
Settings.BranchStatesInTasproj = BranchStatesInTasproj.Checked;
}
}
}