BizHawk/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs

110 lines
3.9 KiB
C#
Raw Normal View History

2014-07-11 15:43:47 +00:00
using System;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
2014-07-11 15:43:47 +00:00
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class StateHistorySettingsForm : Form
2014-07-11 15:43:47 +00:00
{
2014-12-21 18:25:04 +00:00
public IStatable Statable { get; set; }
2017-05-24 15:49:35 +00:00
private readonly TasStateManagerSettings _settings;
2014-07-11 15:43:47 +00:00
private decimal _stateSizeMb;
2017-05-24 15:49:35 +00:00
public StateHistorySettingsForm(TasStateManagerSettings settings)
2014-07-11 15:43:47 +00:00
{
2017-05-24 15:49:35 +00:00
_settings = settings;
2014-07-11 15:43:47 +00:00
InitializeComponent();
}
private void StateHistorySettings_Load(object sender, EventArgs e)
2014-07-11 15:43:47 +00:00
{
2014-12-21 18:25:04 +00:00
_stateSizeMb = Statable.SaveStateBinary().Length / (decimal)1024 / (decimal)1024;
2014-07-11 15:43:47 +00:00
MemCapacityNumeric.Maximum = 1024 * 8;
2017-05-24 15:49:35 +00:00
MemCapacityNumeric.Value = _settings.Capacitymb < MemCapacityNumeric.Maximum ?
_settings.Capacitymb : MemCapacityNumeric.Maximum;
DiskCapacityNumeric.Value = _settings.DiskCapacitymb < MemCapacityNumeric.Maximum ?
_settings.DiskCapacitymb : MemCapacityNumeric.Maximum;
FileCapacityNumeric.Value = _settings.DiskSaveCapacitymb < MemCapacityNumeric.Maximum ?
2017-05-24 15:49:35 +00:00
_settings.DiskSaveCapacitymb : MemCapacityNumeric.Maximum;
2014-07-11 15:43:47 +00:00
MemStateGapDividerNumeric.Maximum = Statable.SaveStateBinary().Length / 1024 / 2 + 1;
MemStateGapDividerNumeric.Minimum = Statable.SaveStateBinary().Length / 1024 / 16;
MemStateGapDividerNumeric.Value = _settings.MemStateGapDivider < MemStateGapDividerNumeric.Minimum ?
MemStateGapDividerNumeric.Minimum : _settings.MemStateGapDivider;
FileStateGapNumeric.Value = _settings.FileStateGap;
SavestateSizeLabel.Text = Math.Round(_stateSizeMb, 2).ToString() + " MB";
CapacityNumeric_ValueChanged(null, null);
SaveCapacityNumeric_ValueChanged(null, null);
2017-05-24 15:49:35 +00:00
BranchStatesInTasproj.Checked = _settings.BranchStatesInTasproj;
EraseBranchStatesFirst.Checked = _settings.EraseBranchStatesFirst;
2014-07-11 15:43:47 +00:00
}
2017-05-24 15:49:35 +00:00
private int MaxStatesInCapacity => (int)Math.Floor(MemCapacityNumeric.Value / _stateSizeMb)
+ (int)Math.Floor(DiskCapacityNumeric.Value / _stateSizeMb);
2014-07-11 15:43:47 +00:00
private void OkBtn_Click(object sender, EventArgs e)
{
2017-05-24 15:49:35 +00:00
_settings.Capacitymb = (int)MemCapacityNumeric.Value;
_settings.DiskCapacitymb = (int)DiskCapacityNumeric.Value;
_settings.DiskSaveCapacitymb = (int)FileCapacityNumeric.Value;
_settings.MemStateGapDivider = (int)MemStateGapDividerNumeric.Value;
_settings.FileStateGap = (int)FileStateGapNumeric.Value;
2014-07-11 15:43:47 +00:00
DialogResult = DialogResult.OK;
Close();
}
private void CancelBtn_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void CapacityNumeric_ValueChanged(object sender, EventArgs e)
{
// TODO: Setting space for 2.6 (2) states in memory and 2.6 (2) on disk results in 5 total.
// Easy to fix the display, but the way TasStateManager works the total used actually is 5.
NumStatesLabel.Text = MaxStatesInCapacity.ToString();
2014-07-11 15:43:47 +00:00
}
private void SaveCapacityNumeric_ValueChanged(object sender, EventArgs e)
{
NumSaveStatesLabel.Text = ((int)Math.Floor(FileCapacityNumeric.Value / _stateSizeMb)).ToString();
}
private void BranchStatesInTasproj_CheckedChanged(object sender, EventArgs e)
{
2017-05-24 15:49:35 +00:00
_settings.BranchStatesInTasproj = BranchStatesInTasproj.Checked;
}
private void EraseBranchStatesFIrst_CheckedChanged(object sender, EventArgs e)
{
2017-05-24 15:49:35 +00:00
_settings.EraseBranchStatesFirst = EraseBranchStatesFirst.Checked;
}
private void FileStateGap_ValueChanged(object sender, EventArgs e)
{
FileNumFramesLabel.Text = FileStateGapNumeric.Value == 0
? "frame"
: $"{1 << (int)FileStateGapNumeric.Value} frames";
}
private void MemStateGapDivider_ValueChanged(object sender, EventArgs e)
{
int val = (int)(Statable.SaveStateBinary().Length / MemStateGapDividerNumeric.Value / 1024);
if (val <= 1)
MemStateGapDividerNumeric.Maximum = MemStateGapDividerNumeric.Value;
MemFramesLabel.Text = val <= 1
2017-05-24 15:49:35 +00:00
? "frame"
: $"{val} frames";
}
2014-07-11 15:43:47 +00:00
}
}