move more movie loading logic out of Mainform and into MovieSession and also some extension methods

This commit is contained in:
adelikat 2020-04-18 11:25:37 -05:00
parent 3ec6662dc9
commit 189a47ad3c
4 changed files with 49 additions and 25 deletions

View File

@ -288,6 +288,9 @@ namespace BizHawk.Client.Common
QueuedMovie = null;
MultiTrack.Restart(Global.Emulator.ControllerDefinition.PlayerCount);
Movie.ProcessSavestate(Global.Emulator);
Movie.ProcessSram(Global.Emulator);
if (recordMode)
{
Movie.StartNewRecording();

View File

@ -252,5 +252,45 @@ namespace BizHawk.Client.Common
public static bool IsRecording(this IMovie movie) => movie?.Mode == MovieMode.Record;
public static bool IsFinished(this IMovie movie) => movie.Mode == MovieMode.Finished;
public static bool IsPlayingOrRecording(this IMovie movie) => movie?.Mode == MovieMode.Play || movie?.Mode == MovieMode.Record;
/// <summary>
/// If the given movie contains a savestate it will be loaded if
/// the given core has savestates, and a framebuffer populated
/// if it is contained in the state and the given core supports it
/// </summary>
public static void ProcessSavestate(this IMovie movie, IEmulator emulator)
{
if (emulator.HasSavestates() && movie.StartsFromSavestate)
{
if (movie.TextSavestate != null)
{
emulator.AsStatable().LoadStateText(movie.TextSavestate);
}
else
{
emulator.AsStatable().LoadStateBinary(movie.BinarySavestate);
}
if (movie.SavestateFramebuffer != null && emulator.HasVideoProvider())
{
emulator.AsVideoProvider().PopulateFromBuffer(movie.SavestateFramebuffer);
}
emulator.ResetCounters();
}
}
/// <summary>
/// Sets the given <see cref="emulator"/> save ram if the movie contains save ram
/// and the core supports save ram
/// </summary>
public static void ProcessSram(this IMovie movie, IEmulator emulator)
{
if (movie.StartsFromSaveRam && emulator.HasSaveRam())
{
emulator.AsSaveRam().StoreSaveRam(movie.SaveRam);
}
}
}
}

View File

@ -1,5 +1,4 @@
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
@ -25,29 +24,6 @@ namespace BizHawk.Client.EmuHawk
Config.RecentMovies.Add(movie.Filename);
if (Emulator.HasSavestates() && movie.StartsFromSavestate)
{
if (movie.TextSavestate != null)
{
Emulator.AsStatable().LoadStateText(new StringReader(movie.TextSavestate));
}
else
{
Emulator.AsStatable().LoadStateBinary(movie.BinarySavestate);
}
if (movie.SavestateFramebuffer != null && Emulator.HasVideoProvider())
{
Emulator.AsVideoProvider().PopulateFromBuffer(movie.SavestateFramebuffer);
}
Emulator.ResetCounters();
}
else if (Emulator.HasSaveRam() && movie.StartsFromSaveRam)
{
Emulator.AsSaveRam().StoreSaveRam(movie.SaveRam);
}
MovieSession.RunQueuedMovie(record);
SetMainformMovieInfo();

View File

@ -73,6 +73,11 @@ namespace BizHawk.Emulation.Common
}
}
public static void LoadStateText(this IStatable core, string textState)
{
core.LoadStateText(new StringReader(textState));
}
/// <summary>
/// Loads a state directly from a byte array
/// </summary>