From 229d7f42e5f3e7dadfa687599c9608df5d5382fb Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 31 May 2020 13:11:14 -0500 Subject: [PATCH] break savestate config variables into a dedicated config class, simplify the names, and pass it into SavestateManager.SaveStateFile(), note that this is a soft config breaking change, any of these settings from old configs will be "reset" to defaults --- src/BizHawk.Client.Common/config/Config.cs | 12 +------- .../config/ConfigEnums.cs | 2 +- .../config/SaveStateConfig.cs | 17 +++++++++++ .../movie/bk2/Bk2Movie.IO.cs | 2 +- .../movie/tasproj/TasMovie.IO.cs | 2 +- .../savestates/SavestateManager.cs | 10 +++---- src/BizHawk.Client.EmuHawk/MainForm.cs | 4 +-- .../config/ProfileConfig.cs | 20 ++++++------- .../config/RewindConfig.cs | 30 +++++++++---------- .../movie/RecordMovie.cs | 2 +- 10 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 src/BizHawk.Client.Common/config/SaveStateConfig.cs diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 573ead9388..17a2a174a2 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -84,10 +84,6 @@ namespace BizHawk.Client.Common public bool HotkeyConfigAutoTab { get; set; } = true; public bool InputConfigAutoTab { get; set; } = true; public bool SkipWaterboxIntegrityChecks { get; set; } = false; - public bool BackupSavestates { get; set; } = true; - public bool SaveScreenshotWithStates { get; set; } = true; - public int BigScreenshotSize { get; set; } = 128 * 1024; - public bool NoLowResLargeScreenshotWithStates { get; set; } public int AutofireOn { get; set; } = 1; public int AutofireOff { get; set; } = 1; public bool AutofireLagFrames { get; set; } = true; @@ -142,13 +138,7 @@ namespace BizHawk.Client.Common public RewindConfig Rewind { get; set; } = new RewindConfig(); - // Savestate settings - public SaveStateTypeE SaveStateType { get; set; } = SaveStateTypeE.Binary; - public const int DefaultSaveStateCompressionLevelNormal = 1; - public int SaveStateCompressionLevelNormal { get; set; } = DefaultSaveStateCompressionLevelNormal; - public const int DefaultSaveStateCompressionLevelRewind = 0; // this isn't actually used yet - public int SaveStateCompressionLevelRewind { get; set; } = DefaultSaveStateCompressionLevelRewind; // this isn't actually used yet - public int MovieCompressionLevel { get; set; } = 2; + public SaveStateConfig Savestates { get; set; } = new SaveStateConfig(); /// /// Use vsync when presenting all 3d accelerated windows. diff --git a/src/BizHawk.Client.Common/config/ConfigEnums.cs b/src/BizHawk.Client.Common/config/ConfigEnums.cs index 48c40971c5..070de52122 100644 --- a/src/BizHawk.Client.Common/config/ConfigEnums.cs +++ b/src/BizHawk.Client.Common/config/ConfigEnums.cs @@ -27,7 +27,7 @@ CustomRatio } - public enum SaveStateTypeE + public enum SaveStateType { Binary, Text } diff --git a/src/BizHawk.Client.Common/config/SaveStateConfig.cs b/src/BizHawk.Client.Common/config/SaveStateConfig.cs new file mode 100644 index 0000000000..619de20352 --- /dev/null +++ b/src/BizHawk.Client.Common/config/SaveStateConfig.cs @@ -0,0 +1,17 @@ +namespace BizHawk.Client.Common +{ + public class SaveStateConfig + { + public const int DefaultCompressionLevelNormal = 1; + public SaveStateType Type { get; set; } = SaveStateType.Binary; + public int CompressionLevelNormal { get; set; } = DefaultCompressionLevelNormal; + public const int DefaultCompressionLevelRewind = 0; // this isn't actually used yet + public int CompressionLevelRewind { get; set; } = DefaultCompressionLevelRewind; // this isn't actually used yet + public int MovieCompressionLevel { get; set; } = 2; + + public bool MakeBackups { get; set; } = true; + public bool SaveScreenshot { get; set; } = true; + public int BigScreenshotSize { get; set; } = 128 * 1024; + public bool NoLowResLargeScreenshots { get; set; } + } +} diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index 4e32e2b8a6..7dae3709bf 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -184,7 +184,7 @@ namespace BizHawk.Client.Common Directory.CreateDirectory(file.Directory.ToString()); } - using var bs = new ZipStateSaver(fn, Global.Config.MovieCompressionLevel); + using var bs = new ZipStateSaver(fn, Global.Config.Savestates.MovieCompressionLevel); bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString())); bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString())); bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString())); diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 0045b7b3fd..925255e8e2 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -18,7 +18,7 @@ namespace BizHawk.Client.Common Directory.CreateDirectory(file.Directory.ToString()); } - using var bs = new ZipStateSaver(fn, Global.Config.MovieCompressionLevel); + using var bs = new ZipStateSaver(fn, Global.Config.Savestates.MovieCompressionLevel); bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString())); bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString())); bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString())); diff --git a/src/BizHawk.Client.Common/savestates/SavestateManager.cs b/src/BizHawk.Client.Common/savestates/SavestateManager.cs index e999ce2e10..91dc5cbf41 100644 --- a/src/BizHawk.Client.Common/savestates/SavestateManager.cs +++ b/src/BizHawk.Client.Common/savestates/SavestateManager.cs @@ -9,15 +9,15 @@ namespace BizHawk.Client.Common { public static class SavestateManager { - public static void SaveStateFile(IEmulator emulator, string filename) + public static void SaveStateFile(IEmulator emulator, string filename, SaveStateConfig config) { var core = emulator.AsStatable(); // the old method of text savestate save is now gone. // a text savestate is just like a binary savestate, but with a different core lump - using var bs = new ZipStateSaver(filename, Global.Config.SaveStateCompressionLevelNormal); + using var bs = new ZipStateSaver(filename, config.CompressionLevelNormal); bs.PutVersionLumps(); - if (Global.Config.SaveStateType == SaveStateTypeE.Text) + if (config.Type == SaveStateType.Text) { // text savestate format using (new SimpleTime("Save Core")) @@ -34,7 +34,7 @@ namespace BizHawk.Client.Common } } - if (Global.Config.SaveScreenshotWithStates && emulator.HasVideoProvider()) + if (config.SaveScreenshot && emulator.HasVideoProvider()) { var vp = emulator.AsVideoProvider(); var buff = vp.GetVideoBuffer(); @@ -52,7 +52,7 @@ namespace BizHawk.Client.Common int outHeight = vp.BufferHeight; // if buffer is too big, scale down screenshot - if (!Global.Config.NoLowResLargeScreenshotWithStates && buff.Length >= Global.Config.BigScreenshotSize) + if (!config.NoLowResLargeScreenshots && buff.Length >= config.BigScreenshotSize) { outWidth /= 2; outHeight /= 2; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index eeca5d626e..1256ebf7d0 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -4060,7 +4060,7 @@ namespace BizHawk.Client.EmuHawk try { - SavestateManager.SaveStateFile(Emulator, path); + SavestateManager.SaveStateFile(Emulator, path, Config.Savestates); ClientApi.OnStateSaved(this, userFriendlyStateName); @@ -4109,7 +4109,7 @@ namespace BizHawk.Client.EmuHawk } // Make backup first - if (Config.BackupSavestates) + if (Config.Savestates.MakeBackups) { Util.TryMoveBackupFile(path, $"{path}.bak"); } diff --git a/src/BizHawk.Client.EmuHawk/config/ProfileConfig.cs b/src/BizHawk.Client.EmuHawk/config/ProfileConfig.cs index 0b160c6646..acf3925c17 100644 --- a/src/BizHawk.Client.EmuHawk/config/ProfileConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/ProfileConfig.cs @@ -95,12 +95,12 @@ namespace BizHawk.Client.EmuHawk private void SetCasual() { - _config.NoLowResLargeScreenshotWithStates = false; - _config.SaveScreenshotWithStates = false; + _config.Savestates.NoLowResLargeScreenshots = false; + _config.Savestates.SaveScreenshot = false; _config.AllowUdlr = false; - _config.BackupSavestates = false; + _config.Savestates.MakeBackups = false; - _config.SaveStateCompressionLevelNormal = 0; + _config.Savestates.CompressionLevelNormal = 0; _config.Rewind.EnabledLarge = false; _config.Rewind.EnabledMedium = false; _config.Rewind.EnabledSmall = true; @@ -152,7 +152,7 @@ namespace BizHawk.Client.EmuHawk private void SetLongPlay() { - _config.SaveStateCompressionLevelNormal = 5; + _config.Savestates.CompressionLevelNormal = 5; // SNES _config.PreferredCores["SNES"] = CoreNames.Bsnes; @@ -176,11 +176,11 @@ namespace BizHawk.Client.EmuHawk private void SetTas() { // General - _config.SaveScreenshotWithStates = true; + _config.Savestates.SaveScreenshot = true; _config.AllowUdlr = true; - _config.BackupSavestates = true; + _config.Savestates.MakeBackups = true; _config.SkipLagFrame = false; - _config.SaveStateCompressionLevelNormal = 5; + _config.Savestates.CompressionLevelNormal = 5; // Rewind _config.Rewind.EnabledLarge = false; @@ -228,9 +228,9 @@ namespace BizHawk.Client.EmuHawk private void SetN64Tas() { // General - _config.BackupSavestates = false; + _config.Savestates.MakeBackups = false; _config.SkipLagFrame = true; - _config.SaveStateCompressionLevelNormal = 0; + _config.Savestates.CompressionLevelNormal = 0; } private TSetting GetSyncSettings() diff --git a/src/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/src/BizHawk.Client.EmuHawk/config/RewindConfig.cs index 339e49fda2..30a2303266 100644 --- a/src/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -72,15 +72,15 @@ namespace BizHawk.Client.EmuHawk LargeStateTrackbar.Value = largeStateSizeKb; LargeStateUpDown.Value = largeStateSizeKb; - nudCompression.Value = _config.SaveStateCompressionLevelNormal; + nudCompression.Value = _config.Savestates.CompressionLevelNormal; - rbStatesBinary.Checked = _config.SaveStateType == SaveStateTypeE.Binary; - rbStatesText.Checked = _config.SaveStateType == SaveStateTypeE.Text; + rbStatesBinary.Checked = _config.Savestates.Type == SaveStateType.Binary; + rbStatesText.Checked = _config.Savestates.Type == SaveStateType.Text; - BackupSavestatesCheckbox.Checked = _config.BackupSavestates; - ScreenshotInStatesCheckbox.Checked = _config.SaveScreenshotWithStates; - LowResLargeScreenshotsCheckbox.Checked = !_config.NoLowResLargeScreenshotWithStates; - BigScreenshotNumeric.Value = _config.BigScreenshotSize / 1024; + BackupSavestatesCheckbox.Checked = _config.Savestates.MakeBackups; + ScreenshotInStatesCheckbox.Checked = _config.Savestates.SaveScreenshot; + LowResLargeScreenshotsCheckbox.Checked = !_config.Savestates.NoLowResLargeScreenshots; + BigScreenshotNumeric.Value = _config.Savestates.BigScreenshotSize / 1024; ScreenshotInStatesCheckbox_CheckedChanged(null, null); } @@ -180,13 +180,13 @@ namespace BizHawk.Client.EmuHawk // These settings are not used by DoRewindSettings _config.Rewind.SpeedMultiplier = (int)RewindSpeedNumeric.Value; - _config.SaveStateCompressionLevelNormal = (int)nudCompression.Value; - if (rbStatesBinary.Checked) _config.SaveStateType = SaveStateTypeE.Binary; - if (rbStatesText.Checked) _config.SaveStateType = SaveStateTypeE.Text; - _config.BackupSavestates = BackupSavestatesCheckbox.Checked; - _config.SaveScreenshotWithStates = ScreenshotInStatesCheckbox.Checked; - _config.NoLowResLargeScreenshotWithStates = !LowResLargeScreenshotsCheckbox.Checked; - _config.BigScreenshotSize = (int)BigScreenshotNumeric.Value * 1024; + _config.Savestates.CompressionLevelNormal = (int)nudCompression.Value; + if (rbStatesBinary.Checked) _config.Savestates.Type = SaveStateType.Binary; + if (rbStatesText.Checked) _config.Savestates.Type = SaveStateType.Text; + _config.Savestates.MakeBackups = BackupSavestatesCheckbox.Checked; + _config.Savestates.SaveScreenshot = ScreenshotInStatesCheckbox.Checked; + _config.Savestates.NoLowResLargeScreenshots = !LowResLargeScreenshotsCheckbox.Checked; + _config.Savestates.BigScreenshotSize = (int)BigScreenshotNumeric.Value * 1024; DialogResult = DialogResult.OK; Close(); @@ -389,7 +389,7 @@ namespace BizHawk.Client.EmuHawk private void BtnResetCompression_Click(object sender, EventArgs e) { - nudCompression.Value = Config.DefaultSaveStateCompressionLevelNormal; + nudCompression.Value = SaveStateConfig.DefaultCompressionLevelNormal; } } } diff --git a/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index 2fde4dd76d..15b7733e1c 100644 --- a/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -106,7 +106,7 @@ namespace BizHawk.Client.EmuHawk movieToRecord.StartsFromSavestate = true; - if (_config.SaveStateType == SaveStateTypeE.Binary) + if (_config.Savestates.Type == SaveStateType.Binary) { movieToRecord.BinarySavestate = core.CloneSavestate(); }