AsVideoProviderOrDefault() extension method

This commit is contained in:
adelikat 2016-12-12 13:47:11 -06:00
parent 5caae72682
commit dd48864058
2 changed files with 12 additions and 9 deletions

View File

@ -726,15 +726,7 @@ namespace BizHawk.Client.EmuHawk
set set
{ {
Global.Emulator = value; Global.Emulator = value;
if (Global.Emulator.HasVideoProvider()) _currentVideoProvider = Global.Emulator.AsVideoProviderOrDefault();
{
_currentVideoProvider = Global.Emulator.AsVideoProvider();
}
else
{
_currentVideoProvider = NullVideo.Instance;
}
_currentSoundProvider = Global.Emulator.AsSoundProviderOrDefault(); _currentSoundProvider = Global.Emulator.AsSoundProviderOrDefault();
} }
} }

View File

@ -34,6 +34,17 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core.ServiceProvider.GetService<IVideoProvider>(); return core.ServiceProvider.GetService<IVideoProvider>();
} }
/// <summary>
/// Returns the core's VideoProvider, or a suitable dummy provider
/// </summary>
/// <param name="core"></param>
/// <returns></returns>
public static IVideoProvider AsVideoProviderOrDefault(this IEmulator core)
{
return core.ServiceProvider.GetService<IVideoProvider>()
?? NullVideo.Instance;
}
public static bool HasSoundProvider(this IEmulator core) public static bool HasSoundProvider(this IEmulator core)
{ {
if (core == null) if (core == null)