move EnsureCoreIsAccurate() out of EmuUtil and back into mainform since it has so many dependencies, including mainform itself, and 50% of its use is in mainform anyway

This commit is contained in:
adelikat 2020-06-12 13:57:28 -05:00
parent ac54318cfb
commit f21132a2ac
4 changed files with 41 additions and 47 deletions

View File

@ -1,57 +1,12 @@
using System;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.NEC.PCE;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Emulation.Cores.Nintendo.SNES9X;
using BizHawk.Emulation.Cores;
namespace BizHawk.Client.EmuHawk
{
public static class EmuHawkUtil
{
public static bool EnsureCoreIsAccurate(IEmulator emulator)
{
static bool PromptToSwitchCore(string currentCore, string recommendedCore, Action disableCurrentCore)
{
using var box = new MsgBox(
$"While the {currentCore} core is faster, it is not nearly as accurate as {recommendedCore}.{Environment.NewLine}It is recommended that you switch to the {recommendedCore} core for movie recording.{Environment.NewLine}Switch to {recommendedCore}?",
"Accuracy Warning",
MessageBoxIcon.Warning);
box.SetButtons(
new[] { "Switch", "Continue" },
new[] { DialogResult.Yes, DialogResult.Cancel });
box.MaximumSize = UIHelper.Scale(new Size(575, 175));
box.SetMessageToAutoSize();
var result = box.ShowDialog();
if (result != DialogResult.Yes)
{
return false;
}
disableCurrentCore();
GlobalWin.MainForm.RebootCore();
return true;
}
return emulator switch
{
Snes9x _ => PromptToSwitchCore(CoreNames.Snes9X, CoreNames.Bsnes, () => GlobalWin.Config.PreferredCores["SNES"] = CoreNames.Bsnes),
QuickNES _ => PromptToSwitchCore(CoreNames.QuickNes, CoreNames.NesHawk, () => GlobalWin.Config.PreferredCores["NES"] = CoreNames.NesHawk),
HyperNyma _ => PromptToSwitchCore(CoreNames.HyperNyma, CoreNames.TurboNyma, () => GlobalWin.Config.PreferredCores["PCE"] = CoreNames.TurboNyma),
_ => true
};
}
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>
public static string ResolveShortcut(string filename)
{

View File

@ -491,7 +491,7 @@ namespace BizHawk.Client.EmuHawk
}
}
if (!EmuHawkUtil.EnsureCoreIsAccurate(Emulator))
if (!EnsureCoreIsAccurate())
{
// Inaccurate core but allow the user to continue anyway
}

View File

@ -26,8 +26,10 @@ using BizHawk.Emulation.Cores.Nintendo.GBHawkLink;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Client.EmuHawk.CoreExtensions;
using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common.Base_Implementations;
using BizHawk.Emulation.Cores.Consoles.NEC.PCE;
using BizHawk.Emulation.Cores.Nintendo.SNES9X;
using BizHawk.Emulation.Cores.Consoles.SNK;
using BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy;
@ -4190,6 +4192,43 @@ namespace BizHawk.Client.EmuHawk
}
}
public bool EnsureCoreIsAccurate()
{
bool PromptToSwitchCore(string currentCore, string recommendedCore, Action disableCurrentCore)
{
using var box = new MsgBox(
$"While the {currentCore} core is faster, it is not nearly as accurate as {recommendedCore}.{Environment.NewLine}It is recommended that you switch to the {recommendedCore} core for movie recording.{Environment.NewLine}Switch to {recommendedCore}?",
"Accuracy Warning",
MessageBoxIcon.Warning);
box.SetButtons(
new[] { "Switch", "Continue" },
new[] { DialogResult.Yes, DialogResult.Cancel });
box.MaximumSize = UIHelper.Scale(new Size(575, 175));
box.SetMessageToAutoSize();
var result = box.ShowDialog();
if (result != DialogResult.Yes)
{
return false;
}
disableCurrentCore();
RebootCore();
return true;
}
return Emulator switch
{
Snes9x _ => PromptToSwitchCore(CoreNames.Snes9X, CoreNames.Bsnes, () => Config.PreferredCores["SNES"] = CoreNames.Bsnes),
QuickNES _ => PromptToSwitchCore(CoreNames.QuickNes, CoreNames.NesHawk, () => Config.PreferredCores["NES"] = CoreNames.NesHawk),
HyperNyma _ => PromptToSwitchCore(CoreNames.HyperNyma, CoreNames.TurboNyma, () => Config.PreferredCores["PCE"] = CoreNames.TurboNyma),
_ => true
};
}
private void SaveStateAs()
{
if (!Emulator.HasSavestates())

View File

@ -217,7 +217,7 @@ namespace BizHawk.Client.EmuHawk
if (!CanAutoload && MovieSession.Movie.NotActive())
{
// Nag but allow the user to continue anyway, so ignore the return value
EmuHawkUtil.EnsureCoreIsAccurate(Emulator);
MainForm.EnsureCoreIsAccurate();
}
// Start Scenario 1: A regular movie is active