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);
|
||||
try
|
||||
{
|
||||
using var ms = new MemoryStream(_memorySavestates[guid]);
|
||||
using var br = new BinaryReader(ms);
|
||||
StatableCore.LoadStateBinary(br);
|
||||
StatableCore.LoadStateBinary(_memorySavestates[guid]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -371,8 +371,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
using var lastStateReader = new BinaryReader(new MemoryStream(_lastState));
|
||||
Global.Emulator.AsStatable().LoadStateBinary(lastStateReader);
|
||||
Global.Emulator.AsStatable().LoadStateBinary(_lastState);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false)));
|
||||
Emulator.AsStatable().LoadStateBinary(movie.BinarySavestate);
|
||||
}
|
||||
|
||||
if (movie.SavestateFramebuffer != null && Emulator.HasVideoProvider())
|
||||
|
|
|
@ -1070,9 +1070,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void LoadState(KeyValuePair<int, byte[]> state)
|
||||
{
|
||||
using var ms = new MemoryStream(state.Value);
|
||||
using var br = new BinaryReader(ms);
|
||||
StatableEmulator.LoadStateBinary(br);
|
||||
StatableEmulator.LoadStateBinary(state.Value);
|
||||
|
||||
if (state.Key == 0 && CurrentTasMovie.StartsFromSavestate)
|
||||
{
|
||||
|
|
|
@ -72,5 +72,15 @@ namespace BizHawk.Emulation.Common
|
|||
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