Break off rewind config variables into their own class

This commit is contained in:
adelikat 2020-01-21 17:38:12 -06:00
parent 263fdfebc3
commit 548ff15e33
6 changed files with 81 additions and 71 deletions

View File

@ -140,20 +140,7 @@ namespace BizHawk.Client.Common
public bool AutoMinimizeSkipping = true;
public bool VSyncThrottle = false;
// Rewind settings
public bool Rewind_UseDelta = true;
public bool RewindEnabledSmall = true;
public bool RewindEnabledMedium = false;
public bool RewindEnabledLarge = false;
public int RewindFrequencySmall = 1;
public int RewindFrequencyMedium = 4;
public int RewindFrequencyLarge = 60;
public int Rewind_MediumStateSize = 262144; // 256kb
public int Rewind_LargeStateSize = 1048576; // 1mb
public int Rewind_BufferSize = 128; // in mb
public bool Rewind_OnDisk = false;
public bool Rewind_IsThreaded = Environment.ProcessorCount > 1;
public int RewindSpeedMultiplier = 1;
public RewindConfig Rewind { get; set; } = new RewindConfig();
// Savestate settings
public SaveStateTypeE SaveStateType = SaveStateTypeE.Default;

View File

@ -0,0 +1,23 @@
using System;
namespace BizHawk.Client.Common
{
public class RewindConfig
{
public bool UseDelta { get; set; } = true;
public bool EnabledSmall { get; set; } = true;
public bool EnabledMedium { get; set; }
public bool EnabledLarge { get; set; }
public int FrequencySmall { get; set; } = 1;
public int FrequencyMedium { get; set; } = 4;
public int FrequencyLarge { get; set; } = 60;
public int MediumStateSize { get; set; } = 262144; // 256kb
public int LargeStateSize { get; set; } = 1048576; // 1mb
public int BufferSize { get; set; } = 128; // in mb
public bool OnDisk { get; set; }
public bool IsThreaded { get; set; } = Environment.ProcessorCount > 1;
public int SpeedMultiplier { get; set; } = 1;
}
}

View File

@ -44,20 +44,20 @@ namespace BizHawk.Client.Common
{
int stateSize = Global.Emulator.AsStatable().SaveStateBinary().Length;
if (stateSize >= Global.Config.Rewind_LargeStateSize)
if (stateSize >= Global.Config.Rewind.LargeStateSize)
{
RewindEnabled = Global.Config.RewindEnabledLarge;
RewindFrequency = Global.Config.RewindFrequencyLarge;
RewindEnabled = Global.Config.Rewind.EnabledLarge;
RewindFrequency = Global.Config.Rewind.FrequencyLarge;
}
else if (stateSize >= Global.Config.Rewind_MediumStateSize)
else if (stateSize >= Global.Config.Rewind.MediumStateSize)
{
RewindEnabled = Global.Config.RewindEnabledMedium;
RewindFrequency = Global.Config.RewindFrequencyMedium;
RewindEnabled = Global.Config.Rewind.EnabledMedium;
RewindFrequency = Global.Config.Rewind.FrequencyMedium;
}
else
{
RewindEnabled = Global.Config.RewindEnabledSmall;
RewindFrequency = Global.Config.RewindFrequencySmall;
RewindEnabled = Global.Config.Rewind.EnabledSmall;
RewindFrequency = Global.Config.Rewind.FrequencySmall;
}
}
@ -65,15 +65,14 @@ namespace BizHawk.Client.Common
$"Rewind enabled, frequency: {RewindFrequency}" :
"Rewind disabled");
_rewindDeltaEnable = Global.Config.Rewind_UseDelta;
_rewindDeltaEnable = Global.Config.Rewind.UseDelta;
if (RewindActive)
{
var capacity = Global.Config.Rewind_BufferSize * 1048576L;
var capacity = Global.Config.Rewind.BufferSize * 1048576L;
_rewindBuffer = new StreamBlobDatabase(Global.Config.Rewind.OnDisk, capacity, BufferManage);
_rewindBuffer = new StreamBlobDatabase(Global.Config.Rewind_OnDisk, capacity, BufferManage);
_rewindThread = new RewindThreader(CaptureInternal, RewindInternal, Global.Config.Rewind_IsThreaded);
_rewindThread = new RewindThreader(CaptureInternal, RewindInternal, Global.Config.Rewind.IsThreaded);
}
}

View File

@ -2070,7 +2070,7 @@ namespace BizHawk.Client.EmuHawk
if (rewind)
{
speedPercent = Math.Max(speedPercent * Config.RewindSpeedMultiplier / Rewinder.RewindFrequency, 5);
speedPercent = Math.Max(speedPercent * Config.Rewind.SpeedMultiplier / Rewinder.RewindFrequency, 5);
}
Global.DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind;

View File

@ -87,9 +87,9 @@ namespace BizHawk.Client.EmuHawk
_config.BackupSavestates = false;
_config.SaveStateCompressionLevelNormal = 0;
_config.RewindEnabledLarge = false;
_config.RewindEnabledMedium = false;
_config.RewindEnabledSmall = true;
_config.Rewind.EnabledLarge = false;
_config.Rewind.EnabledMedium = false;
_config.Rewind.EnabledSmall = true;
_config.SkipLagFrame = false;
// N64
@ -137,9 +137,9 @@ namespace BizHawk.Client.EmuHawk
_config.SkipLagFrame = false;
_config.SaveStateCompressionLevelNormal = 5;
_config.RewindEnabledLarge = false;
_config.RewindEnabledMedium = false;
_config.RewindEnabledSmall = true;
_config.Rewind.EnabledLarge = false;
_config.Rewind.EnabledMedium = false;
_config.Rewind.EnabledSmall = true;
// N64
var n64Settings = GetSyncSettings<N64, N64SyncSettings>();
@ -188,9 +188,9 @@ namespace BizHawk.Client.EmuHawk
_config.SaveStateCompressionLevelNormal = 5;
// Rewind
_config.RewindEnabledLarge = false;
_config.RewindEnabledMedium = false;
_config.RewindEnabledSmall = false;
_config.Rewind.EnabledLarge = false;
_config.Rewind.EnabledMedium = false;
_config.Rewind.EnabledSmall = false;
// N64
var n64Settings = GetSyncSettings<N64, N64SyncSettings>();
@ -239,9 +239,9 @@ namespace BizHawk.Client.EmuHawk
_config.SaveStateCompressionLevelNormal = 0;
// Rewind
_config.RewindEnabledLarge = false;
_config.RewindEnabledMedium = false;
_config.RewindEnabledSmall = false;
_config.Rewind.EnabledLarge = false;
_config.Rewind.EnabledMedium = false;
_config.Rewind.EnabledSmall = false;
// N64
var n64Settings = GetSyncSettings<N64, N64SyncSettings>();

View File

@ -39,24 +39,24 @@ namespace BizHawk.Client.EmuHawk
RewindFramesUsedLabel.Text = "N/A";
}
RewindSpeedNumeric.Value = _config.RewindSpeedMultiplier;
DiskBufferCheckbox.Checked = _config.Rewind_OnDisk;
RewindIsThreadedCheckbox.Checked = _config.Rewind_IsThreaded;
RewindSpeedNumeric.Value = _config.Rewind.SpeedMultiplier;
DiskBufferCheckbox.Checked = _config.Rewind.OnDisk;
RewindIsThreadedCheckbox.Checked = _config.Rewind.IsThreaded;
_stateSize = _statableCore.SaveStateBinary().Length;
BufferSizeUpDown.Value = Math.Max(_config.Rewind_BufferSize, BufferSizeUpDown.Minimum);
BufferSizeUpDown.Value = Math.Max(_config.Rewind.BufferSize, BufferSizeUpDown.Minimum);
_mediumStateSize = _config.Rewind_MediumStateSize;
_largeStateSize = _config.Rewind_LargeStateSize;
_mediumStateSize = _config.Rewind.MediumStateSize;
_largeStateSize = _config.Rewind.LargeStateSize;
UseDeltaCompression.Checked = _config.Rewind_UseDelta;
UseDeltaCompression.Checked = _config.Rewind.UseDelta;
SmallSavestateNumeric.Value = _config.RewindFrequencySmall;
MediumSavestateNumeric.Value = _config.RewindFrequencyMedium;
LargeSavestateNumeric.Value = _config.RewindFrequencyLarge;
SmallSavestateNumeric.Value = _config.Rewind.FrequencySmall;
MediumSavestateNumeric.Value = _config.Rewind.FrequencyMedium;
LargeSavestateNumeric.Value = _config.Rewind.FrequencyLarge;
SmallStateEnabledBox.Checked = _config.RewindEnabledSmall;
MediumStateEnabledBox.Checked = _config.RewindEnabledMedium;
LargeStateEnabledBox.Checked = _config.RewindEnabledLarge;
SmallStateEnabledBox.Checked = _config.Rewind.EnabledSmall;
MediumStateEnabledBox.Checked = _config.Rewind.EnabledMedium;
LargeStateEnabledBox.Checked = _config.Rewind.EnabledLarge;
SetSmallEnabled();
SetMediumEnabled();
@ -64,8 +64,8 @@ namespace BizHawk.Client.EmuHawk
SetStateSize();
var mediumStateSizeKb = _config.Rewind_MediumStateSize / 1024;
var largeStateSizeKb = _config.Rewind_LargeStateSize / 1024;
var mediumStateSizeKb = _config.Rewind.MediumStateSize / 1024;
var largeStateSizeKb = _config.Rewind.LargeStateSize / 1024;
MediumStateTrackbar.Value = mediumStateSizeKb;
MediumStateUpDown.Value = mediumStateSizeKb;
@ -147,39 +147,40 @@ namespace BizHawk.Client.EmuHawk
private bool TriggerRewindSettingsReload { get; set; }
private void PutRewindSetting<T>(ref T setting, T value) where T : IEquatable<T>
private T PutRewindSetting<T>(T setting, T value) where T : IEquatable<T>
{
if (setting.Equals(value))
{
return;
return setting;
}
setting = value;
TriggerRewindSettingsReload = true;
return value;
}
private void Ok_Click(object sender, EventArgs e)
{
// These settings are used by DoRewindSettings, which we'll only call if anything actually changed (i.e. preserve rewind history if possible)
PutRewindSetting(ref _config.RewindEnabledSmall, SmallStateEnabledBox.Checked);
PutRewindSetting(ref _config.RewindEnabledMedium, MediumStateEnabledBox.Checked);
PutRewindSetting(ref _config.RewindEnabledLarge, LargeStateEnabledBox.Checked);
PutRewindSetting(ref _config.RewindFrequencySmall, (int)SmallSavestateNumeric.Value);
PutRewindSetting(ref _config.RewindFrequencyMedium, (int)MediumSavestateNumeric.Value);
PutRewindSetting(ref _config.RewindFrequencyLarge, (int)LargeSavestateNumeric.Value);
PutRewindSetting(ref _config.Rewind_OnDisk, DiskBufferCheckbox.Checked);
PutRewindSetting(ref _config.Rewind_UseDelta, UseDeltaCompression.Checked);
PutRewindSetting(ref _config.Rewind_IsThreaded, RewindIsThreadedCheckbox.Checked);
PutRewindSetting(ref _config.Rewind_BufferSize, (int)BufferSizeUpDown.Value);
PutRewindSetting(ref _config.Rewind_MediumStateSize, (int)MediumStateUpDown.Value * 1024);
PutRewindSetting(ref _config.Rewind_LargeStateSize, (int)LargeStateUpDown.Value * 1024);
_config.Rewind.UseDelta = PutRewindSetting(_config.Rewind.UseDelta, UseDeltaCompression.Checked);
_config.Rewind.EnabledSmall = PutRewindSetting(_config.Rewind.EnabledSmall, SmallStateEnabledBox.Checked);
_config.Rewind.EnabledMedium = PutRewindSetting(_config.Rewind.EnabledMedium, MediumStateEnabledBox.Checked);
_config.Rewind.EnabledLarge = PutRewindSetting(_config.Rewind.EnabledLarge, LargeStateEnabledBox.Checked);
_config.Rewind.FrequencySmall = PutRewindSetting(_config.Rewind.FrequencySmall, (int)SmallSavestateNumeric.Value);
_config.Rewind.FrequencyMedium = PutRewindSetting(_config.Rewind.FrequencyMedium, (int)MediumSavestateNumeric.Value);
_config.Rewind.FrequencyLarge = PutRewindSetting(_config.Rewind.FrequencyLarge, (int)LargeSavestateNumeric.Value);
_config.Rewind.MediumStateSize = PutRewindSetting(_config.Rewind.MediumStateSize, (int)MediumStateUpDown.Value * 1024);
_config.Rewind.LargeStateSize = PutRewindSetting(_config.Rewind.LargeStateSize, (int)LargeStateUpDown.Value * 1024);
_config.Rewind.BufferSize = PutRewindSetting(_config.Rewind.BufferSize, (int)BufferSizeUpDown.Value);
_config.Rewind.OnDisk = PutRewindSetting(_config.Rewind.OnDisk, DiskBufferCheckbox.Checked);
_config.Rewind.IsThreaded = PutRewindSetting(_config.Rewind.IsThreaded, RewindIsThreadedCheckbox.Checked);
if (TriggerRewindSettingsReload)
{
_rewinder.Initialize();
}
// These settings are not used by DoRewindSettings
_config.RewindSpeedMultiplier = (int)RewindSpeedNumeric.Value;
_config.Rewind.SpeedMultiplier = (int)RewindSpeedNumeric.Value;
_config.SaveStateCompressionLevelNormal = (int)nudCompression.Value;
if (rbStatesDefault.Checked) _config.SaveStateType = SaveStateTypeE.Default;
if (rbStatesBinary.Checked) _config.SaveStateType = SaveStateTypeE.Binary;