add an IStatable extension method that will return a byte array that's safe to hold on to, but isn't optimized for speed, to be used in basic situations where we are making movies from savestate or getting a savestate length
This commit is contained in:
parent
0154222737
commit
04aab3c41b
|
@ -47,7 +47,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
_decay = new StateManagerDecay(_movie, this);
|
||||
|
||||
_expectedStateSize = (ulong)Core.SaveStateBinary().Length;
|
||||
_expectedStateSize = (ulong)Core.CloneSavestate().Length; // TODO: why do we store this in a ulong?
|
||||
if (_expectedStateSize == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Savestate size can not be zero!");
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
RewindSpeedNumeric.Value = _config.Rewind.SpeedMultiplier;
|
||||
DiskBufferCheckbox.Checked = _config.Rewind.OnDisk;
|
||||
RewindIsThreadedCheckbox.Checked = _config.Rewind.IsThreaded;
|
||||
_stateSize = _statableCore.SaveStateBinary().Length;
|
||||
_stateSize = _statableCore.CloneSavestate().Length;
|
||||
BufferSizeUpDown.Value = Math.Max(_config.Rewind.BufferSize, BufferSizeUpDown.Minimum);
|
||||
|
||||
_mediumStateSize = _config.Rewind.MediumStateSize;
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (_config.SaveStateType == SaveStateTypeE.Binary)
|
||||
{
|
||||
movieToRecord.BinarySavestate = (byte[])core.SaveStateBinary().Clone();
|
||||
movieToRecord.BinarySavestate = core.CloneSavestate();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void MemStateGapDivider_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
int val = (int)(Statable.SaveStateBinary().Length / MemStateGapDividerNumeric.Value / 1024);
|
||||
int val = (int)(Statable.CloneSavestate().Length / MemStateGapDividerNumeric.Value / 1024);
|
||||
|
||||
if (val <= 1)
|
||||
MemStateGapDividerNumeric.Maximum = MemStateGapDividerNumeric.Value;
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.Common.MovieConversionExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -38,10 +39,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (AskSaveChanges())
|
||||
{
|
||||
int index = Emulator.Frame;
|
||||
|
||||
var newProject = CurrentTasMovie.ConvertToSavestateAnchoredMovie(
|
||||
index, (byte[])StatableEmulator.SaveStateBinary().Clone());
|
||||
Emulator.Frame, StatableEmulator.CloneSavestate());
|
||||
|
||||
MainForm.PauseEmulator();
|
||||
LoadFile(new FileInfo(newProject.Filename), true);
|
||||
|
@ -752,7 +751,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (CurrentTasMovie.TasStateManager.HasState(Emulator.Frame))
|
||||
{
|
||||
byte[] state = (byte[])StatableEmulator.SaveStateBinary().Clone();
|
||||
byte[] state = StatableEmulator.CloneSavestate();
|
||||
byte[] greenZone = CurrentTasMovie.TasStateManager[Emulator.Frame];
|
||||
|
||||
if (!state.SequenceEqual(greenZone))
|
||||
|
|
|
@ -87,5 +87,20 @@ namespace BizHawk.Emulation.Common
|
|||
using var br = new BinaryReader(ms);
|
||||
core.LoadStateBinary(br);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a byte array copy of the core's current state
|
||||
/// This creates a new buffer, and should not be used in performance sensitive situations
|
||||
/// </summary>
|
||||
public static byte[] CloneSavestate(this IStatable core)
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
core.SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
var stateBuffer = ms.ToArray();
|
||||
bw.Close();
|
||||
return stateBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue