add an IStatable extension method that can load a state directly from a byte array, reduces the stream creation boiler plate in a number of palces
This commit is contained in:
parent
a460846ff8
commit
9494243eef
|
@ -34,9 +34,7 @@ namespace BizHawk.Client.Common
|
||||||
var guid = new Guid(identifier);
|
var guid = new Guid(identifier);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var ms = new MemoryStream(_memorySavestates[guid]);
|
StatableCore.LoadStateBinary(_memorySavestates[guid]);
|
||||||
using var br = new BinaryReader(ms);
|
|
||||||
StatableCore.LoadStateBinary(br);
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
@ -371,8 +371,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using var lastStateReader = new BinaryReader(new MemoryStream(_lastState));
|
Global.Emulator.AsStatable().LoadStateBinary(_lastState);
|
||||||
Global.Emulator.AsStatable().LoadStateBinary(lastStateReader);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false)));
|
Emulator.AsStatable().LoadStateBinary(movie.BinarySavestate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (movie.SavestateFramebuffer != null && Emulator.HasVideoProvider())
|
if (movie.SavestateFramebuffer != null && Emulator.HasVideoProvider())
|
||||||
|
|
|
@ -1070,9 +1070,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void LoadState(KeyValuePair<int, byte[]> state)
|
public void LoadState(KeyValuePair<int, byte[]> state)
|
||||||
{
|
{
|
||||||
using var ms = new MemoryStream(state.Value);
|
StatableEmulator.LoadStateBinary(state.Value);
|
||||||
using var br = new BinaryReader(ms);
|
|
||||||
StatableEmulator.LoadStateBinary(br);
|
|
||||||
|
|
||||||
if (state.Key == 0 && CurrentTasMovie.StartsFromSavestate)
|
if (state.Key == 0 && CurrentTasMovie.StartsFromSavestate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,5 +72,15 @@ namespace BizHawk.Emulation.Common
|
||||||
core.LoadStateBinary(br);
|
core.LoadStateBinary(br);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a state directly from a byte array
|
||||||
|
/// </summary>
|
||||||
|
public static void LoadStateBinary(this IStatable core, byte[] state)
|
||||||
|
{
|
||||||
|
using var ms = new MemoryStream(state, false);
|
||||||
|
using var br = new BinaryReader(ms);
|
||||||
|
core.LoadStateBinary(br);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue