From b736d489117235e7a66fd4e465a3cbb2ab3df32e Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 17 Apr 2020 14:36:41 -0500 Subject: [PATCH] use constants for core string names and simplify core core name getting logic --- BizHawk.Client.Common/movie/MovieSession.cs | 113 ++++++++---------- BizHawk.Emulation.Common/Extensions.cs | 12 -- .../Consoles/Nintendo/GBA/MGBAHawk.cs | 2 +- .../Consoles/Nintendo/GBHawk/GBHawk.cs | 2 +- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 2 +- .../Consoles/Nintendo/NES/NES.cs | 2 +- .../Consoles/Nintendo/QuickNES/QuickNES.cs | 2 +- .../Consoles/Nintendo/SNES/LibsnesCore.cs | 2 +- .../Consoles/Nintendo/SNES9X/Snes9x.cs | 2 +- .../Nintendo/SubNESHawk/SubNESHawk.cs | 2 +- BizHawk.Emulation.Cores/CoreNames.cs | 22 ++++ 11 files changed, 82 insertions(+), 81 deletions(-) create mode 100644 BizHawk.Emulation.Cores/CoreNames.cs diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 9c3c86a91e..1b8782b9b0 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -2,6 +2,7 @@ using System.IO; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.NES; @@ -252,69 +253,59 @@ namespace BizHawk.Client.Common // Don't set it to a movie instance of the adapter or you will lose the definition! Global.InputManager.RewireInputChain(); - if (!record && emulator.SystemId == "NES") // For NES we need special logic since the movie will drive which core to load + if (!record) { - var quicknesName = typeof(QuickNES).CoreName(); - var neshawkName = typeof(NES).CoreName(); - - // If either is specified use that, else use whatever is currently set - if (movie.Core == quicknesName) + switch (emulator.SystemId) { - PreviousNesInQuickNES = Global.Config.NesInQuickNes; - Global.Config.NesInQuickNes = true; - } - else if (movie.Core == neshawkName) - { - PreviousNesInQuickNES = Global.Config.NesInQuickNes; - Global.Config.NesInQuickNes = false; - } - } - else if (!record && emulator.SystemId == "SNES") // ditto with snes9x vs bsnes - { - var snes9XName = typeof(Snes9x).CoreName(); - var bsnesName = typeof(LibsnesCore).CoreName(); - - if (movie.Core == snes9XName) - { - PreviousSnesInSnes9x = Global.Config.SnesInSnes9x; - Global.Config.SnesInSnes9x = true; - } - else if (movie.Core == bsnesName) - { - PreviousSnesInSnes9x = Global.Config.SnesInSnes9x; - Global.Config.SnesInSnes9x = false; - } - } - else if (!record && emulator.SystemId == "GBA") // ditto with GBA, we should probably architect this at some point, this isn't sustainable - { - var mGBAName = typeof(MGBAHawk).CoreName(); - var vbaNextName = typeof(VBANext).CoreName(); - - if (movie.Core == mGBAName) - { - PreviousGbaUsemGba = Global.Config.GbaUsemGba; - Global.Config.GbaUsemGba = true; - } - else if (movie.Core == vbaNextName) - { - PreviousGbaUsemGba = Global.Config.GbaUsemGba; - Global.Config.GbaUsemGba = false; - } - } - else if (!record && (emulator.SystemId == "GB" || emulator.SystemId == "GBC")) - { - var gbHawkName = typeof(GBHawk).CoreName(); - var gambatteName = typeof(Gameboy).CoreName(); - - if (movie.Core == gbHawkName) - { - PreviousGbUseGbHawk = Global.Config.GbUseGbHawk; - Global.Config.GbUseGbHawk = true; - } - else if (movie.Core == gambatteName) - { - PreviousGbUseGbHawk = Global.Config.GbUseGbHawk; - Global.Config.GbUseGbHawk = false; + case "NES": + if (movie.Core == CoreNames.QuickNes) + { + PreviousNesInQuickNES = Global.Config.NesInQuickNes; + Global.Config.NesInQuickNes = true; + } + else if (movie.Core == CoreNames.NesHawk) + { + PreviousNesInQuickNES = Global.Config.NesInQuickNes; + Global.Config.NesInQuickNes = false; + } + break; + case "SNES": + if (movie.Core == CoreNames.Snes9X) + { + PreviousSnesInSnes9x = Global.Config.SnesInSnes9x; + Global.Config.SnesInSnes9x = true; + } + else if (movie.Core == CoreNames.Bsnes) + { + PreviousSnesInSnes9x = Global.Config.SnesInSnes9x; + Global.Config.SnesInSnes9x = false; + } + break; + case "GBA": + if (movie.Core == CoreNames.Mgba) + { + PreviousGbaUsemGba = Global.Config.GbaUsemGba; + Global.Config.GbaUsemGba = true; + } + else if (movie.Core == CoreNames.VbaNext) + { + PreviousGbaUsemGba = Global.Config.GbaUsemGba; + Global.Config.GbaUsemGba = false; + } + break; + case "GB": + case "GBC": + if (movie.Core == CoreNames.GbHawk) + { + PreviousGbUseGbHawk = Global.Config.GbUseGbHawk; + Global.Config.GbUseGbHawk = true; + } + else if (movie.Core == CoreNames.Gambatte) + { + PreviousGbUseGbHawk = Global.Config.GbUseGbHawk; + Global.Config.GbUseGbHawk = false; + } + break; } } diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index 60f41bf7eb..b3fccb2670 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -297,18 +297,6 @@ namespace BizHawk.Emulation.Common return core.VsyncNumerator() / (double)core.VsyncDenominator(); } - // TODO: a better place for these - public static string CoreName(this Type type) - { - if (type == null) - { - return ""; - } - - var attr = (CoreAttribute)Attribute.GetCustomAttribute(type, typeof(CoreAttribute)); - return attr?.CoreName ?? ""; - } - public static bool IsImplemented(this MethodInfo info) { return !info.GetCustomAttributes(false).Any(a => a is FeatureNotImplementedAttribute); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs index 7fe3cd88ac..0bdafd1470 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs @@ -4,7 +4,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBA { - [Core("mGBA", "endrift", true, true, "0.8", "https://mgba.io/", false)] + [Core(CoreNames.Mgba, "endrift", true, true, "0.8", "https://mgba.io/", false)] [ServiceNotApplicable(new[] { typeof(IDriveLight), typeof(IRegionable) })] public partial class MGBAHawk : IEmulator, IVideoProvider, ISoundProvider, IGBAGPUViewable, ISaveRam, IStatable, IInputPollable, ISettable, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index 98e17d5825..c4835e2f37 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { [Core( - "GBHawk", + CoreNames.GbHawk, "", isPorted: false, isReleased: true)] diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 8816e63748..d94b21bc07 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy /// a gameboy/gameboy color emulator wrapped around native C++ libgambatte /// [Core( - "Gambatte", + CoreNames.Gambatte, "", isPorted: true, isReleased: true, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 7f47fad41a..a5ab61c19e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -10,7 +10,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { [Core( - "NesHawk", + CoreNames.NesHawk, "zeromus, natt, alyosha, adelikat", isPorted: false, isReleased: true)] diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index a009cc967a..7b0d11a8a3 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -14,7 +14,7 @@ using BizHawk.Common.BufferExtensions; namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES { [Core( - "QuickNes", + CoreNames.QuickNes, "", isPorted: true, isReleased: true, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 266b58e79a..c4d6dc5267 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -18,7 +18,7 @@ using BizHawk.Emulation.Cores.Components.W65816; namespace BizHawk.Emulation.Cores.Nintendo.SNES { [Core( - "BSNES", + CoreNames.Bsnes, "byuu", isPorted: true, isReleased: true, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index 93d5586c2c..a7adf6cdc5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -9,7 +9,7 @@ using System.Linq; namespace BizHawk.Emulation.Cores.Nintendo.SNES9X { - [Core("Snes9x", "", true, true, + [Core(CoreNames.Snes9X, "", true, true, "5e0319ab3ef9611250efb18255186d0dc0d7e125", "https://github.com/snes9xgit/snes9x", false)] [ServiceNotApplicable(new[] { typeof(IDriveLight) })] public class Snes9x : WaterboxCore, diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs index bad4c7a2a6..73e26b42e8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.cs @@ -4,7 +4,7 @@ using BizHawk.Emulation.Cores.Nintendo.NES; namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk { [Core( - "SubNESHawk", + CoreNames.SubNesHawk, "", isPorted: false, isReleased: true)] diff --git a/BizHawk.Emulation.Cores/CoreNames.cs b/BizHawk.Emulation.Cores/CoreNames.cs new file mode 100644 index 0000000000..e873d71efe --- /dev/null +++ b/BizHawk.Emulation.Cores/CoreNames.cs @@ -0,0 +1,22 @@ +using BizHawk.Emulation.Common; + +namespace BizHawk.Emulation.Cores +{ + /// + /// Constant class for the names of cores, that should be used in every + /// For now we are only including ones that can be picked as a core preference, + /// but all cores should be included ere + /// + public class CoreNames + { + public const string NesHawk = "NesHawk"; + public const string SubNesHawk = "SubNESHawk"; + public const string QuickNes = "QuickNes"; + public const string Snes9X = "Snes9x"; + public const string Bsnes = "BSNES"; + public const string Mgba = "mGBA"; + public const string VbaNext = "VBA-Next"; + public const string GbHawk = "GBHawk"; + public const string Gambatte = "Gambatte"; + } +}