Pass delegates instead of MainForm to RewindConfig

This commit is contained in:
YoshiRulz 2020-06-29 14:46:20 +10:00
parent e4df38602b
commit 141541bc1f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 19 additions and 12 deletions

View File

@ -1007,7 +1007,7 @@ namespace BizHawk.Client.EmuHawk
{
if (Emulator.HasSavestates())
{
using var form = new RewindConfig(this, Config, Emulator.AsStatable());
using var form = new RewindConfig(Config, CreateRewinder, () => this.Rewinder, Emulator.AsStatable());
AddOnScreenMessage(form.ShowDialog().IsOk()
? "Rewind and State settings saved"
: "Rewind config aborted");

View File

@ -8,16 +8,21 @@ namespace BizHawk.Client.EmuHawk
{
public partial class RewindConfig : Form
{
private readonly MainForm _mainForm;
private readonly Config _config;
private readonly IStatable _statableCore;
private double _avgStateSize;
public RewindConfig(MainForm mainForm, Config config, IStatable statableCore)
private readonly Config _config;
private readonly Action _recreateRewinder;
private readonly Func<IRewinder> _getRewinder;
private readonly IStatable _statableCore;
public RewindConfig(Config config, Action recreateRewinder, Func<IRewinder> getRewinder, IStatable statableCore)
{
_mainForm = mainForm;
_config = config;
_recreateRewinder = recreateRewinder;
_getRewinder = getRewinder;
_statableCore = statableCore;
InitializeComponent();
btnResetCompression.Image = Properties.Resources.reboot;
@ -25,11 +30,13 @@ namespace BizHawk.Client.EmuHawk
private void RewindConfig_Load(object sender, EventArgs e)
{
if (_mainForm.Rewinder?.Active == true)
//TODO can this be moved to the ctor post-InitializeComponent?
var rewinder = _getRewinder();
if (rewinder?.Active == true)
{
FullnessLabel.Text = $"{_mainForm.Rewinder.FullnessRatio * 100:0.00}%";
RewindFramesUsedLabel.Text = _mainForm.Rewinder.Count.ToString();
_avgStateSize = _mainForm.Rewinder.Size * _mainForm.Rewinder.FullnessRatio / _mainForm.Rewinder.Count;
FullnessLabel.Text = $"{rewinder.FullnessRatio * 100:0.00}%";
RewindFramesUsedLabel.Text = rewinder.Count.ToString();
_avgStateSize = rewinder.Size * rewinder.FullnessRatio / rewinder.Count;
}
else
{
@ -117,7 +124,7 @@ namespace BizHawk.Client.EmuHawk
if (TriggerRewindSettingsReload)
{
_mainForm.CreateRewinder();
_recreateRewinder();
}
DialogResult = DialogResult.OK;