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

This commit is contained in:
adelikat 2020-05-31 13:11:14 -05:00
parent 8f3caf384d
commit 229d7f42e5
10 changed files with 54 additions and 47 deletions

View File

@ -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();
/// <summary>
/// Use vsync when presenting all 3d accelerated windows.

View File

@ -27,7 +27,7 @@
CustomRatio
}
public enum SaveStateTypeE
public enum SaveStateType
{
Binary, Text
}

View File

@ -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; }
}
}

View File

@ -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()));

View File

@ -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()));

View File

@ -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;

View File

@ -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");
}

View File

@ -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<TEmulator, TSetting>()

View File

@ -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;
}
}
}

View File

@ -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();
}