AsStatable() and also update statusbar saveslots on CloseRom()

This commit is contained in:
adelikat 2014-12-05 00:52:16 +00:00
parent 40416656a2
commit e2033c9d2e
11 changed files with 54 additions and 22 deletions

View File

@ -5,6 +5,7 @@ using BizHawk.Common;
using BizHawk.Common.BufferExtensions;
using BizHawk.Common.IOExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
{
@ -12,7 +13,7 @@ namespace BizHawk.Client.Common
{
public static void SaveStateFile(string filename, string name)
{
var core = Global.Emulator as IStatable;
var core = Global.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 BinaryStateSaver(filename))
@ -77,7 +78,7 @@ namespace BizHawk.Client.Common
public static bool LoadStateFile(string path, string name)
{
var core = Global.Emulator as IStatable;
var core = Global.Emulator.AsStatable();
// try to detect binary first
var bl = BinaryStateLoader.LoadAndDetect(path);

View File

@ -31,7 +31,7 @@ namespace BizHawk.Client.Common
throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable");
}
var core = (IStatable)Global.Emulator;
var core = Global.Emulator.AsStatable();
StateManager = new TasStateManager(this, core);
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
@ -48,7 +48,7 @@ namespace BizHawk.Client.Common
throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable");
}
var core = (IStatable)Global.Emulator;
var core = Global.Emulator.AsStatable();
StateManager = new TasStateManager(this, core);
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";

View File

@ -69,7 +69,7 @@ namespace BizHawk.Client.Common
// log a frame
if (_lastState != null && Global.Emulator.Frame % _rewindFrequency == 0)
{
_rewindThread.Capture(((IStatable)Global.Emulator).SaveStateBinary());
_rewindThread.Capture(Global.Emulator.AsStatable().SaveStateBinary());
}
}
}
@ -79,7 +79,7 @@ namespace BizHawk.Client.Common
if (Global.Emulator.HasSavestates())
{
// This is the first frame. Capture the state, and put it in LastState for future deltas to be compared against.
_lastState = (byte[]) ((IStatable)Global.Emulator).SaveStateBinary().Clone();
_lastState = (byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone();
int state_size;
if (_lastState.Length >= Global.Config.Rewind_LargeStateSize)
@ -365,7 +365,7 @@ namespace BizHawk.Client.Common
var fullstate = reader.ReadBoolean();
if (fullstate)
{
((IStatable)Global.Emulator).LoadStateBinary(reader);
Global.Emulator.AsStatable().LoadStateBinary(reader);
}
else
{
@ -382,7 +382,7 @@ namespace BizHawk.Client.Common
reader.Close();
output.Position = 0;
((IStatable)Global.Emulator).LoadStateBinary(new BinaryReader(output));
Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(output));
}
}
}

View File

@ -51,11 +51,11 @@ namespace BizHawk.Client.EmuHawk
{
if (movie.TextSavestate != null)
{
(Global.Emulator as IStatable).LoadStateText(new StringReader(movie.TextSavestate));
Global.Emulator.AsStatable().LoadStateText(new StringReader(movie.TextSavestate));
}
else
{
(Global.Emulator as IStatable).LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false)));
Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false)));
}
if (movie.SavestateFramebuffer != null)
{

View File

@ -3520,6 +3520,7 @@ namespace BizHawk.Client.EmuHawk
ClearHolds();
PauseOnFrame = null;
ToolHelpers.UpdateCheatRelatedTools(null, null);
UpdateStatusSlots();
}
}

View File

@ -2,8 +2,9 @@
using System.Windows.Forms;
using System.Drawing;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -34,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
DiskBufferCheckbox.Checked = Global.Config.Rewind_OnDisk;
RewindIsThreadedCheckbox.Checked = Global.Config.Rewind_IsThreaded;
_stateSize = ((IStatable)Global.Emulator).SaveStateBinary().Length;
_stateSize = Global.Emulator.AsStatable().SaveStateBinary().Length;
BufferSizeUpDown.Value = Global.Config.Rewind_BufferSize;
_mediumStateSize = Global.Config.Rewind_MediumStateSize;

View File

@ -81,7 +81,7 @@ namespace BizHawk.Client.EmuHawk
if (StartFromCombo.SelectedItem.ToString() == "Now" && Global.Emulator.HasSavestates())
{
var core = Global.Emulator as IStatable;
var core = Global.Emulator.AsStatable();
movieToRecord.StartsFromSavestate = true;

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
@ -24,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
private void GreenzoneSettings_Load(object sender, EventArgs e)
{
_stateSizeMb = ((IStatable)Global.Emulator).SaveStateBinary().Length / (decimal)1024 / (decimal)1024;
_stateSizeMb = Global.Emulator.AsStatable().SaveStateBinary().Length / (decimal)1024 / (decimal)1024;
SaveGreenzoneCheckbox.Checked = Settings.SaveGreenzone;
CapacityNumeric.Value = Settings.Capacitymb == 0 ? 1 : Settings.Capacitymb < CapacityNumeric.Maximum ?

View File

@ -6,11 +6,13 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
@ -508,7 +510,7 @@ namespace BizHawk.Client.EmuHawk
if (CurrentTasMovie.TasStateManager.HasState(frame))
{
var state = (byte[])(((IStatable)Global.Emulator).SaveStateBinary().Clone());
var state = (byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone();
var greenzone = CurrentTasMovie.TasStateManager[frame];
if (!state.SequenceEqual(greenzone.Value))
@ -750,7 +752,7 @@ namespace BizHawk.Client.EmuHawk
var newProject = CurrentTasMovie.ConvertToSavestateAnchoredMovie(
index,
(byte[])((IStatable)Global.Emulator).SaveStateBinary().Clone());
(byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone());
GlobalWin.MainForm.PauseEmulator();
LoadProject(newProject.Filename);

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using System.ComponentModel;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
@ -315,7 +316,7 @@ namespace BizHawk.Client.EmuHawk
private void LoadState(KeyValuePair<int, byte[]> state)
{
((IStatable)Global.Emulator).LoadStateBinary(new BinaryReader(new MemoryStream(state.Value.ToArray())));
Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(state.Value.ToArray())));
if (state.Key == 0 && CurrentTasMovie.StartsFromSavestate)
{

View File

@ -19,7 +19,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool HasMemoryDomains(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<IMemoryDomains>();
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IMemoryDomains>();
}
public static IMemoryDomains AsMemoryDomains(this IEmulator core)
@ -29,7 +34,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool HasSaveRam(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<ISaveRam>();
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<ISaveRam>();
}
public static ISaveRam AsSaveRam(this IEmulator core)
@ -39,7 +49,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool HasSavestates(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<IStatable>();
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IStatable>();
}
public static IStatable AsStatable(this IEmulator core)
@ -49,7 +64,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool CanPollInput(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<IInputPollable>();
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IInputPollable>();
}
public static IInputPollable AsInputPollable(this IEmulator core)
@ -79,6 +99,11 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
public static bool CanDebug(this IEmulator core)
{
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IDebuggable>();
}