From 548ff15e33fdbba1810fb1b46bd2ef618b8ba140 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 21 Jan 2020 17:38:12 -0600 Subject: [PATCH] Break off rewind config variables into their own class --- BizHawk.Client.Common/config/Config.cs | 15 +---- BizHawk.Client.Common/config/RewindConfig.cs | 23 +++++++ BizHawk.Client.Common/rewind/Rewinder.cs | 25 ++++---- BizHawk.Client.EmuHawk/MainForm.cs | 2 +- .../config/ProfileConfig.cs | 24 +++---- BizHawk.Client.EmuHawk/config/RewindConfig.cs | 63 ++++++++++--------- 6 files changed, 81 insertions(+), 71 deletions(-) create mode 100644 BizHawk.Client.Common/config/RewindConfig.cs diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 5a40a931c7..6ac37fc7d4 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -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; diff --git a/BizHawk.Client.Common/config/RewindConfig.cs b/BizHawk.Client.Common/config/RewindConfig.cs new file mode 100644 index 0000000000..0e45a3adde --- /dev/null +++ b/BizHawk.Client.Common/config/RewindConfig.cs @@ -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; + } +} diff --git a/BizHawk.Client.Common/rewind/Rewinder.cs b/BizHawk.Client.Common/rewind/Rewinder.cs index 534b62656a..0370e35f61 100644 --- a/BizHawk.Client.Common/rewind/Rewinder.cs +++ b/BizHawk.Client.Common/rewind/Rewinder.cs @@ -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); } } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 30f117ed3d..83de3f5ca8 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -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; diff --git a/BizHawk.Client.EmuHawk/config/ProfileConfig.cs b/BizHawk.Client.EmuHawk/config/ProfileConfig.cs index 90cb8bc253..27c884a9ea 100644 --- a/BizHawk.Client.EmuHawk/config/ProfileConfig.cs +++ b/BizHawk.Client.EmuHawk/config/ProfileConfig.cs @@ -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(); @@ -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(); @@ -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(); diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.cs index ddd53fd29f..48ea75c55d 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -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(ref T setting, T value) where T : IEquatable + private T PutRewindSetting(T setting, T value) where T : IEquatable { 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;