Add an IsNull() extension method to IEmulator (checks for null and if NullEmulator) and replace EmuHawk NullEmulator checks with this method instead

This commit is contained in:
adelikat 2014-11-30 14:18:44 +00:00
parent 8c4e0f1203
commit 4681fef0c2
7 changed files with 39 additions and 42 deletions

View File

@ -1,7 +1,7 @@
using System.IO;
using System.Linq;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
{
@ -52,7 +52,7 @@ namespace BizHawk.Client.Common
public bool HasSlot(int slot)
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
return false;
}

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk
AVSubMenu.Enabled =
ScreenshotSubMenu.Enabled =
CloseRomMenuItem.Enabled =
!(Global.Emulator is NullEmulator);
!Global.Emulator.IsNull();
}
private void RecentRomMenuItem_DropDownOpened(object sender, EventArgs e)
@ -131,7 +131,7 @@ namespace BizHawk.Client.EmuHawk
SaveState8MenuItem.Enabled =
SaveState9MenuItem.Enabled =
SaveState0MenuItem.Enabled =
!(Global.Emulator is NullEmulator);
!Global.Emulator.IsNull();
}
private void LoadStateSubMenu_DropDownOpened(object sender, EventArgs e)
@ -150,7 +150,7 @@ namespace BizHawk.Client.EmuHawk
AutoloadLastSlotMenuItem.Checked = Global.Config.AutoLoadLastSaveSlot;
LoadNamedStateMenuItem.Enabled = !(Global.Emulator is NullEmulator);
LoadNamedStateMenuItem.Enabled = !Global.Emulator.IsNull();
LoadState1MenuItem.Enabled = _stateSlots.HasSlot(1);
LoadState2MenuItem.Enabled = _stateSlots.HasSlot(2);
LoadState3MenuItem.Enabled = _stateSlots.HasSlot(3);
@ -180,7 +180,7 @@ namespace BizHawk.Client.EmuHawk
SaveToCurrentSlotMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Quick Save"].Bindings;
LoadCurrentSlotMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Quick Load"].Bindings;
SaveToCurrentSlotMenuItem.Enabled = LoadCurrentSlotMenuItem.Enabled = !(Global.Emulator is NullEmulator);
SaveToCurrentSlotMenuItem.Enabled = LoadCurrentSlotMenuItem.Enabled = !Global.Emulator.IsNull();
SelectSlot0MenuItem.Checked = false;
SelectSlot1MenuItem.Checked = false;
@ -617,7 +617,7 @@ namespace BizHawk.Client.EmuHawk
private void emulationToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
RebootCoreMenuItem.Enabled = !(Global.Emulator is NullEmulator);
RebootCoreMenuItem.Enabled = !Global.Emulator.IsNull();
PauseMenuItem.Checked = _didMenuPause ? _wasPaused : EmulatorPaused;
@ -791,7 +791,7 @@ namespace BizHawk.Client.EmuHawk
private void ConfigSubMenu_DropDownOpened(object sender, EventArgs e)
{
ControllersMenuItem.Enabled = !(Global.Emulator is NullEmulator);
ControllersMenuItem.Enabled = !Global.Emulator.IsNull();
}
private void FrameSkipMenuItem_DropDownOpened(object sender, EventArgs e)
@ -1053,7 +1053,7 @@ namespace BizHawk.Client.EmuHawk
{
Global.Config.GB_AsSGB ^= true;
if (!(Global.Emulator is NullEmulator))
if (!Global.Emulator.IsNull())
{
FlagNeedsReboot();
}
@ -1063,7 +1063,7 @@ namespace BizHawk.Client.EmuHawk
{
Global.Config.NES_InQuickNES ^= true;
if (!(Global.Emulator is NullEmulator))
if (!Global.Emulator.IsNull())
{
FlagNeedsReboot();
}
@ -1073,7 +1073,7 @@ namespace BizHawk.Client.EmuHawk
{
Global.Config.SNES_InSnes9x ^= true;
if (!(Global.Emulator is NullEmulator))
if (!Global.Emulator.IsNull())
{
FlagNeedsReboot();
}
@ -1116,7 +1116,7 @@ namespace BizHawk.Client.EmuHawk
TAStudioMenuItem.Enabled =
VirtualPadMenuItem.Enabled =
!(Global.Emulator is NullEmulator);
!Global.Emulator.IsNull();
CheatsMenuItem.Enabled =
HexEditorMenuItem.Enabled =
@ -1823,7 +1823,7 @@ namespace BizHawk.Client.EmuHawk
{
if (new N64VideoPluginconfig().ShowDialog() == DialogResult.OK)
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
GlobalWin.OSD.AddMessage("Plugin settings saved");
}
@ -1956,14 +1956,13 @@ namespace BizHawk.Client.EmuHawk
_didMenuPause = true;
PauseEmulator();
OpenRomContextMenuItem.Visible = (Global.Emulator is NullEmulator) || _inFullscreen;
OpenRomContextMenuItem.Visible = Global.Emulator.IsNull() || _inFullscreen;
ShowMenuContextMenuItem.Visible =
ShowMenuContextMenuSeparator.Visible =
_inFullscreen;
LoadLastRomContextMenuItem.Visible =
(Global.Emulator is NullEmulator);
LoadLastRomContextMenuItem.Visible = Global.Emulator.IsNull();
StopAVContextMenuItem.Visible = _currAviWriter != null;
@ -1972,12 +1971,12 @@ namespace BizHawk.Client.EmuHawk
ScreenshotContextMenuItem.Visible =
CloseRomContextMenuItem.Visible =
UndoSavestateContextMenuItem.Visible =
!(Global.Emulator is NullEmulator);
!Global.Emulator.IsNull();
RecordMovieContextMenuItem.Visible =
PlayMovieContextMenuItem.Visible =
LoadLastMovieContextMenuItem.Visible =
!(Global.Emulator is NullEmulator) && !Global.MovieSession.Movie.IsActive;
!Global.Emulator.IsNull() && !Global.MovieSession.Movie.IsActive;
RestartMovieContextMenuItem.Visible =
StopMovieContextMenuItem.Visible =
@ -1990,7 +1989,7 @@ namespace BizHawk.Client.EmuHawk
StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && !Global.MovieSession.ReadOnly;
AddSubtitleContextMenuItem.Visible = !Global.Emulator.IsNull() && Global.MovieSession.Movie.IsActive && !Global.MovieSession.ReadOnly;
ConfigContextMenuItem.Visible = _inFullscreen;

View File

@ -1290,15 +1290,7 @@ namespace BizHawk.Client.EmuHawk
private void SetWindowText()
{
string str = "";
if (Global.Emulator == null)
{
// in some weird cirumstances, this can get called too early before any emulator exists
// just ignore it
Text = "BizHawk";
return;
}
string str = string.Empty;
if (_inResizeLoop)
{
@ -1306,7 +1298,7 @@ namespace BizHawk.Client.EmuHawk
str = str + string.Format("({0}x{1}) - ", size.Width, size.Height);
}
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
str = str + "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty);
}
@ -1707,7 +1699,7 @@ namespace BizHawk.Client.EmuHawk
// realtime throttle is never going to be so exact that using a double here is wrong
_throttle.SetCoreFps(Global.Emulator.CoreComm.VsyncRate);
_throttle.signal_paused = EmulatorPaused || Global.Emulator is NullEmulator;
_throttle.signal_paused = EmulatorPaused || Global.Emulator.IsNull();
_throttle.signal_unthrottle = _unthrottled || superfastforward;
_throttle.SetSpeedPercent(fastforward ? Global.Config.SpeedPercentAlternate : Global.Config.SpeedPercent);
}
@ -1751,7 +1743,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveStateAs()
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
return;
}
@ -1778,7 +1770,7 @@ namespace BizHawk.Client.EmuHawk
private void LoadStateAs()
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
return;
}
@ -2523,7 +2515,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadQuickSave(string quickSlotName, bool fromLua = false)
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
return;
}
@ -2579,7 +2571,7 @@ namespace BizHawk.Client.EmuHawk
private void UpdateCoreStatusBarButton()
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
CoreNameStatusBarButton.Visible = false;
return;
@ -2940,7 +2932,7 @@ namespace BizHawk.Client.EmuHawk
else
{
var sfd = new SaveFileDialog();
if (!(Global.Emulator is NullEmulator))
if (!Global.Emulator.IsNull())
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "." + ext; //dont use Path.ChangeExtension, it might wreck game names with dots in them
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.AvPathFragment, null);
@ -3360,7 +3352,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: should backup logic be stuffed in into Client.Common.SaveStateManager?
public void SaveQuickSave(string quickSlotName)
{
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
return;
}

View File

@ -425,7 +425,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
sfd.FileName = "MemoryDump";
sfd.InitialDirectory = PathManager.GetBasePathAbsolute();
@ -926,7 +926,7 @@ namespace BizHawk.Client.EmuHawk
RestoreDirectory = true
};
if (Global.Emulator is NullEmulator)
if (Global.Emulator.IsNull())
{
sfd.FileName = "MemoryDump";
sfd.InitialDirectory = PathManager.GetBasePathAbsolute();

View File

@ -11,6 +11,7 @@ using LuaInterface;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Client.EmuHawk.ToolExtensions;
@ -464,7 +465,7 @@ namespace BizHawk.Client.EmuHawk
sfd.FileName = Path.GetFileNameWithoutExtension(_luaList.Filename);
sfd.InitialDirectory = Path.GetDirectoryName(_luaList.Filename);
}
else if (!(Global.Emulator is NullEmulator))
else if (!Global.Emulator.IsNull())
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = PathManager.GetLuaPath();

View File

@ -43,7 +43,7 @@ namespace BizHawk.Client.EmuHawk
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
}
else if (!(Global.Emulator is NullEmulator))
else if (!Global.Emulator.IsNull())
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
}
else if (!(Global.Emulator is NullEmulator))
else if (!Global.Emulator.IsNull())
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
@ -144,7 +144,7 @@ namespace BizHawk.Client.EmuHawk
{
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
}
else if (!(Global.Emulator is NullEmulator))
else if (!Global.Emulator.IsNull())
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
}

View File

@ -16,6 +16,11 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core is IMemoryDomains;
}
public static bool IsNull(this IEmulator core)
{
return core == null || core is NullEmulator;
}
// TODO: a better place for these
public static bool IsImplemented(this MethodInfo info)
{