tastudio: attempt to make StateGap smarter.

it should rely on frames, not on state indexes. and we can only have states on frame numbers that are powers of 2.
doesn't work right on saving multiple times yet. need to cooperate with ExcludeStates() somehow.
This commit is contained in:
feos 2016-04-24 23:17:17 +03:00
parent bc30e87921
commit 408d0ae4d0
4 changed files with 61 additions and 42 deletions

View File

@ -530,10 +530,14 @@ namespace BizHawk.Client.Common
index++;
if (index >= States.Count)
break;
} while (_movie.Markers.IsMarker(States.ElementAt(index).Key + 1));
if (index >= States.Count) break;
}
while (_movie.Markers.IsMarker(States.ElementAt(index).Key + 1));
if (index >= States.Count)
break;
ret.Add(index);
if (States.ElementAt(index).Value.IsOnDisk)
saveUsed -= _expectedStateSize;
else
@ -559,11 +563,13 @@ namespace BizHawk.Client.Common
public void Save(BinaryWriter bw)
{
List<int> noSave = ExcludeStates();
int stateGap = 1 << Settings.StateGap;
bw.Write(States.Count / Settings.StateGap - noSave.Count);
bw.Write(States.Count / stateGap - noSave.Count);
for (int i = 0; i < States.Count; i++)
{
if (noSave.Contains(i) || i % Settings.StateGap != 0)
if (noSave.Contains(i) ||
States.ElementAt(i).Key % stateGap != 0)
continue;
StateAccessed(States.ElementAt(i).Key);

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
DiskSaveCapacitymb = 512;
Capacitymb = 512;
DiskCapacitymb = 512;
StateGap = 8;
StateGap = 4;
BranchStatesInTasproj = false;
EraseBranchStatesFirst = true;
}
@ -57,10 +57,10 @@ namespace BizHawk.Client.Common
public int DiskCapacitymb { get; set; }
/// <summary>
/// The amount of states to skip during project saving. Use 1 to skip none
/// The amount of states to skip during project saving
/// </summary>
[DisplayName("Save only 1 state out of this number")]
[Description("The amount of states to skip during project saving. Use 1 to skip none")]
[DisplayName("State interval for .tasproj")]
[Description("The actual state gap in frames is calculated as Nth power on 2")]
public int StateGap { get; set; }
/// <summary>
@ -137,7 +137,7 @@ namespace BizHawk.Client.Common
if (lines.Length > 3)
StateGap = int.Parse(lines[3]);
else
StateGap = 8;
StateGap = 4;
if (lines.Length > 4)
BranchStatesInTasproj = bool.Parse(lines[4]);

View File

@ -58,6 +58,7 @@ namespace BizHawk.Client.EmuHawk
this.StateGap = new System.Windows.Forms.NumericUpDown();
this.label10 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.NumFramesLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.MemCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.DiskCapacityNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.SaveCapacityNumeric)).BeginInit();
@ -68,7 +69,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, 213);
this.CancelBtn.Location = new System.Drawing.Point(217, 220);
this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.TabIndex = 0;
@ -79,7 +80,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, 213);
this.OkBtn.Location = new System.Drawing.Point(151, 220);
this.OkBtn.Name = "OkBtn";
this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.TabIndex = 1;
@ -89,7 +90,7 @@ namespace BizHawk.Client.EmuHawk
//
// MemCapacityNumeric
//
this.MemCapacityNumeric.Location = new System.Drawing.Point(12, 26);
this.MemCapacityNumeric.Location = new System.Drawing.Point(15, 49);
this.MemCapacityNumeric.Maximum = new decimal(new int[] {
1024,
0,
@ -113,7 +114,7 @@ namespace BizHawk.Client.EmuHawk
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(67, 29);
this.label1.Location = new System.Drawing.Point(70, 52);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(21, 13);
this.label1.TabIndex = 4;
@ -122,7 +123,7 @@ namespace BizHawk.Client.EmuHawk
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 9);
this.label2.Location = new System.Drawing.Point(12, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 13);
this.label2.TabIndex = 5;
@ -131,7 +132,7 @@ namespace BizHawk.Client.EmuHawk
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(147, 9);
this.label3.Location = new System.Drawing.Point(12, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(79, 13);
this.label3.TabIndex = 6;
@ -140,7 +141,7 @@ namespace BizHawk.Client.EmuHawk
// SavestateSizeLabel
//
this.SavestateSizeLabel.AutoSize = true;
this.SavestateSizeLabel.Location = new System.Drawing.Point(229, 9);
this.SavestateSizeLabel.Location = new System.Drawing.Point(94, 9);
this.SavestateSizeLabel.Name = "SavestateSizeLabel";
this.SavestateSizeLabel.Size = new System.Drawing.Size(25, 13);
this.SavestateSizeLabel.TabIndex = 7;
@ -149,7 +150,7 @@ namespace BizHawk.Client.EmuHawk
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(9, 89);
this.label4.Location = new System.Drawing.Point(12, 136);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(84, 13);
this.label4.TabIndex = 8;
@ -158,7 +159,7 @@ namespace BizHawk.Client.EmuHawk
// NumStatesLabel
//
this.NumStatesLabel.AutoSize = true;
this.NumStatesLabel.Location = new System.Drawing.Point(96, 89);
this.NumStatesLabel.Location = new System.Drawing.Point(99, 136);
this.NumStatesLabel.Name = "NumStatesLabel";
this.NumStatesLabel.Size = new System.Drawing.Size(25, 13);
this.NumStatesLabel.TabIndex = 9;
@ -166,7 +167,7 @@ namespace BizHawk.Client.EmuHawk
//
// DiskCapacityNumeric
//
this.DiskCapacityNumeric.Location = new System.Drawing.Point(12, 66);
this.DiskCapacityNumeric.Location = new System.Drawing.Point(15, 113);
this.DiskCapacityNumeric.Maximum = new decimal(new int[] {
65536,
0,
@ -185,7 +186,7 @@ namespace BizHawk.Client.EmuHawk
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(67, 69);
this.label5.Location = new System.Drawing.Point(70, 116);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(21, 13);
this.label5.TabIndex = 4;
@ -194,7 +195,7 @@ namespace BizHawk.Client.EmuHawk
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(9, 49);
this.label6.Location = new System.Drawing.Point(12, 96);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 13);
this.label6.TabIndex = 5;
@ -202,7 +203,7 @@ namespace BizHawk.Client.EmuHawk
//
// SaveCapacityNumeric
//
this.SaveCapacityNumeric.Location = new System.Drawing.Point(150, 66);
this.SaveCapacityNumeric.Location = new System.Drawing.Point(150, 49);
this.SaveCapacityNumeric.Maximum = new decimal(new int[] {
65536,
0,
@ -221,7 +222,7 @@ namespace BizHawk.Client.EmuHawk
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(205, 69);
this.label7.Location = new System.Drawing.Point(205, 52);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(21, 13);
this.label7.TabIndex = 4;
@ -230,7 +231,7 @@ namespace BizHawk.Client.EmuHawk
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(147, 49);
this.label8.Location = new System.Drawing.Point(147, 32);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(112, 13);
this.label8.TabIndex = 5;
@ -239,7 +240,7 @@ namespace BizHawk.Client.EmuHawk
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(147, 89);
this.label9.Location = new System.Drawing.Point(147, 72);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(84, 13);
this.label9.TabIndex = 8;
@ -248,7 +249,7 @@ namespace BizHawk.Client.EmuHawk
// NumSaveStatesLabel
//
this.NumSaveStatesLabel.AutoSize = true;
this.NumSaveStatesLabel.Location = new System.Drawing.Point(234, 89);
this.NumSaveStatesLabel.Location = new System.Drawing.Point(234, 72);
this.NumSaveStatesLabel.Name = "NumSaveStatesLabel";
this.NumSaveStatesLabel.Size = new System.Drawing.Size(25, 13);
this.NumSaveStatesLabel.TabIndex = 9;
@ -258,7 +259,7 @@ namespace BizHawk.Client.EmuHawk
//
this.BranchStatesInTasproj.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.BranchStatesInTasproj.AutoSize = true;
this.BranchStatesInTasproj.Location = new System.Drawing.Point(12, 165);
this.BranchStatesInTasproj.Location = new System.Drawing.Point(15, 165);
this.BranchStatesInTasproj.Name = "BranchStatesInTasproj";
this.BranchStatesInTasproj.Size = new System.Drawing.Size(158, 17);
this.BranchStatesInTasproj.TabIndex = 10;
@ -272,7 +273,7 @@ namespace BizHawk.Client.EmuHawk
this.EraseBranchStatesFirst.AutoSize = true;
this.EraseBranchStatesFirst.Checked = true;
this.EraseBranchStatesFirst.CheckState = System.Windows.Forms.CheckState.Checked;
this.EraseBranchStatesFirst.Location = new System.Drawing.Point(12, 190);
this.EraseBranchStatesFirst.Location = new System.Drawing.Point(15, 190);
this.EraseBranchStatesFirst.Name = "EraseBranchStatesFirst";
this.EraseBranchStatesFirst.Size = new System.Drawing.Size(139, 17);
this.EraseBranchStatesFirst.TabIndex = 11;
@ -282,14 +283,9 @@ namespace BizHawk.Client.EmuHawk
//
// StateGap
//
this.StateGap.Location = new System.Drawing.Point(183, 123);
this.StateGap.Location = new System.Drawing.Point(151, 112);
this.StateGap.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.StateGap.Minimum = new decimal(new int[] {
1,
8,
0,
0,
0});
@ -301,24 +297,34 @@ namespace BizHawk.Client.EmuHawk
0,
0,
0});
this.StateGap.ValueChanged += new System.EventHandler(this.StateGap_ValueChanged);
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(9, 125);
this.label10.Location = new System.Drawing.Point(148, 96);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(168, 13);
this.label10.Size = new System.Drawing.Size(91, 13);
this.label10.TabIndex = 13;
this.label10.Text = "Save to .tasproj only 1 state out of";
this.label10.Text = "Project State Gap";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(9, 138);
this.label11.Location = new System.Drawing.Point(147, 135);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(103, 13);
this.label11.Size = new System.Drawing.Size(61, 13);
this.label11.TabIndex = 14;
this.label11.Text = "Setting 1 skips none";
this.label11.Text = "State every";
//
// NumFramesLabel
//
this.NumFramesLabel.AutoSize = true;
this.NumFramesLabel.Location = new System.Drawing.Point(204, 135);
this.NumFramesLabel.Name = "NumFramesLabel";
this.NumFramesLabel.Size = new System.Drawing.Size(47, 13);
this.NumFramesLabel.TabIndex = 15;
this.NumFramesLabel.Text = "0 frames";
//
// StateHistorySettingsForm
//
@ -326,7 +332,8 @@ namespace BizHawk.Client.EmuHawk
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, 248);
this.ClientSize = new System.Drawing.Size(289, 255);
this.Controls.Add(this.NumFramesLabel);
this.Controls.Add(this.label11);
this.Controls.Add(this.label10);
this.Controls.Add(this.StateGap);
@ -386,5 +393,6 @@ namespace BizHawk.Client.EmuHawk
private NumericUpDown StateGap;
private Label label10;
private Label label11;
private Label NumFramesLabel;
}
}

View File

@ -93,5 +93,10 @@ namespace BizHawk.Client.EmuHawk
{
Settings.EraseBranchStatesFirst = EraseBranchStatesFirst.Checked;
}
private void StateGap_ValueChanged(object sender, EventArgs e)
{
NumFramesLabel.Text = ((StateGap.Value == 0) ? "frame" : (1 << (int)StateGap.Value).ToString() + " frames");
}
}
}