Cleanup disabling of DirectX options when it isn't installed

This commit is contained in:
YoshiRulz 2021-09-21 06:15:19 +10:00
parent c112f0b036
commit 2ec0c7d733
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 29 additions and 20 deletions

View File

@ -0,0 +1,22 @@
using System;
using BizHawk.Common;
namespace BizHawk.Client.Common
{
public static class HostCapabilityDetector
{
private static bool? _hasDirectX = null;
public static bool HasDirectX => _hasDirectX ??= DetectDirectX();
private static bool DetectDirectX()
{
if (OSTailoredCode.IsUnixHost) return false;
var p = OSTailoredCode.LinkedLibManager.LoadOrZero("d3dx9_43.dll");
if (p == IntPtr.Zero) return false;
OSTailoredCode.LinkedLibManager.FreeByPtr(p);
return true;
}
}
}

View File

@ -211,16 +211,7 @@ namespace BizHawk.Client.Common
public int DispPrescale { get; set; } = 1;
private static bool DetectDirectX()
{
if (OSTailoredCode.IsUnixHost) return false;
var p = OSTailoredCode.LinkedLibManager.LoadOrZero("d3dx9_43.dll");
if (p == IntPtr.Zero) return false;
OSTailoredCode.LinkedLibManager.FreeByPtr(p);
return true;
}
public EDispMethod DispMethod { get; set; } = DetectDirectX() ? EDispMethod.SlimDX9 : EDispMethod.OpenGL;
public EDispMethod DispMethod { get; set; } = HostCapabilityDetector.HasDirectX ? EDispMethod.SlimDX9 : EDispMethod.OpenGL;
public int DispChromeFrameWindowed { get; set; } = 2;
public bool DispChromeStatusBarWindowed { get; set; } = true;
@ -248,7 +239,7 @@ namespace BizHawk.Client.Common
public int DispCropBottom { get; set; } = 0;
// Sound options
public ESoundOutputMethod SoundOutputMethod { get; set; } = DetectDirectX() ? ESoundOutputMethod.DirectSound : ESoundOutputMethod.OpenAL;
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasDirectX ? ESoundOutputMethod.DirectSound : ESoundOutputMethod.OpenAL;
public bool SoundEnabled { get; set; } = true;
public bool SoundEnabledNormal { get; set; } = true;
public bool SoundEnabledRWFF { get; set; } = true;
@ -345,7 +336,7 @@ namespace BizHawk.Client.Common
// ReSharper disable once UnusedMember.Global
public string LastWrittenFromDetailed { get; set; } = VersionInfo.GetEmuVersion();
public EHostInputMethod HostInputMethod { get; set; } = OSTailoredCode.IsUnixHost ? EHostInputMethod.OpenTK : EHostInputMethod.DirectInput;
public EHostInputMethod HostInputMethod { get; set; } = HostCapabilityDetector.HasDirectX ? EHostInputMethod.DirectInput : EHostInputMethod.OpenTK;
public bool UseStaticWindowTitles { get; set; }
}

View File

@ -94,9 +94,8 @@ namespace BizHawk.Client.EmuHawk
RefreshAspectRatioOptions();
if (OSTailoredCode.IsUnixHost)
if (!HostCapabilityDetector.HasDirectX)
{
// Disable SlimDX on Unix
rbD3D9.Enabled = false;
rbD3D9.AutoCheck = false;
cbAlternateVsync.Enabled = false;

View File

@ -61,6 +61,8 @@ namespace BizHawk.Client.EmuHawk
private void GuiOptions_Load(object sender, EventArgs e)
{
rbInputMethodDirectInput.Enabled = HostCapabilityDetector.HasDirectX;
StartFullScreenCheckbox.Checked = _config.StartFullscreen;
StartPausedCheckbox.Checked = _config.StartPaused;
PauseWhenMenuActivatedCheckbox.Checked = _config.PauseWhenMenuActivated;

View File

@ -36,12 +36,7 @@ namespace BizHawk.Client.EmuHawk
cbEnableRWFF.Checked = _config.SoundEnabledRWFF;
cbMuteFrameAdvance.Checked = _config.MuteFrameAdvance;
if (OSTailoredCode.IsUnixHost)
{
// Disable DirectSound and XAudio2 on Mono
rbOutputMethodDirectSound.Enabled = false;
rbOutputMethodXAudio2.Enabled = false;
}
rbOutputMethodDirectSound.Enabled = rbOutputMethodXAudio2.Enabled = HostCapabilityDetector.HasDirectX;
rbOutputMethodDirectSound.Checked = _config.SoundOutputMethod == ESoundOutputMethod.DirectSound;
rbOutputMethodXAudio2.Checked = _config.SoundOutputMethod == ESoundOutputMethod.XAudio2;