Convert all single-CD loading to use CoreInventory

This commit is contained in:
nattthebear 2020-07-12 13:21:10 -04:00
parent ab07e67a07
commit 8d56b65734
6 changed files with 26 additions and 41 deletions

View File

@ -66,7 +66,7 @@ namespace BizHawk.Client.Common
public List<IDiscAsset> Discs { get; set; } = new List<IDiscAsset>(); public List<IDiscAsset> Discs { get; set; } = new List<IDiscAsset>();
public bool DeterministicEmulationRequested { get; set; } public bool DeterministicEmulationRequested => _parent.Deterministic;
public object FetchSettings(Type emulatorType, Type settingsType) public object FetchSettings(Type emulatorType, Type settingsType)
=> _parent.GetCoreSettings(emulatorType, settingsType); => _parent.GetCoreSettings(emulatorType, settingsType);
@ -381,34 +381,21 @@ namespace BizHawk.Client.Common
return MakeCore<TEmulator>(clps); return MakeCore<TEmulator>(clps);
} }
switch (game.System) var cip = new CoreInventoryParameters(this)
{ {
case "GEN": Comm = nextComm,
nextEmulator = MakeCoreFromCds<GPGX>(game); Game = game,
break; Discs =
case "SAT":
nextEmulator = MakeCoreFromCds<Saturnus>(game);
break;
case "PSX":
nextEmulator = MakeCoreFromCds<Octoshock>(game);
break;
case "PCFX":
nextEmulator = MakeCoreFromCds<Tst>(game);
break;
case "PCE": // TODO: this is clearly not used, its set to PCE by code above
case "PCECD":
var core = _config.PreferredCores.TryGetValue("PCECD", out var preferredCore) ? preferredCore : CoreNames.PceHawk;
nextEmulator = core switch
{ {
CoreNames.PceHawk => MakeCoreFromCds<PCEngine>(game), new DiscAsset
CoreNames.HyperNyma => MakeCoreFromCds<HyperNyma>(game), {
_ => MakeCoreFromCds<TurboNyma>(game), DiscData = disc,
}; DiscType = new DiscIdentifier(disc).DetectDiscType(),
break; DiscName = Path.GetFileNameWithoutExtension(path)
default: }
nextEmulator = null; },
break; };
} nextEmulator = MakeCoreFromCoreInventory(cip);
return true; return true;
} }
@ -430,11 +417,11 @@ namespace BizHawk.Client.Common
}; };
} }
private IEmulator MakeCoreFromCoreInventory(string systemId, CoreInventoryParameters cip, string forcedCoreGameDb) private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip)
{ {
_config.PreferredCores.TryGetValue(systemId, out var preferredCore); _config.PreferredCores.TryGetValue(cip.Game.System, out var preferredCore);
var forcedCore = ForcedCoreToCoreName(forcedCoreGameDb); var forcedCore = ForcedCoreToCoreName(cip.Game.ForcedCore);
var cores = CoreInventory.Instance.GetCores(systemId) var cores = CoreInventory.Instance.GetCores(cip.Game.System)
.OrderBy(c => .OrderBy(c =>
{ {
if (c.Name == preferredCore) if (c.Name == preferredCore)
@ -445,6 +432,8 @@ namespace BizHawk.Client.Common
return (int)c.Priority; return (int)c.Priority;
}) })
.ToList(); .ToList();
if (cores.Count == 0)
throw new InvalidOperationException("No core was found to try on the game");
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
foreach (var core in cores) foreach (var core in cores)
{ {
@ -457,7 +446,7 @@ namespace BizHawk.Client.Common
exceptions.Add(e); exceptions.Add(e);
} }
} }
throw new AggregateException("No core could load the ROM", exceptions); throw new AggregateException("No core could load the game", exceptions);
} }
private void LoadOther(string path, CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game, out bool cancel) private void LoadOther(string path, CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game, out bool cancel)
@ -539,10 +528,8 @@ namespace BizHawk.Client.Common
Game = game Game = game
} }
}, },
DeterministicEmulationRequested = Deterministic
}; };
nextEmulator = MakeCoreFromCoreInventory(game.System, cip, game.ForcedCore); nextEmulator = MakeCoreFromCoreInventory(cip);
} }
private void LoadPSF(string path, CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game) private void LoadPSF(string path, CoreComm nextComm, HawkFile file, out IEmulator nextEmulator, out RomGame rom, out GameInfo game)

View File

@ -24,6 +24,7 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCE
{ {
_hyperNyma = DoInit<LibHyperNyma>(game, rom, null, "hyper.wbx", extension, deterministic); _hyperNyma = DoInit<LibHyperNyma>(game, rom, null, "hyper.wbx", extension, deterministic);
} }
[CoreConstructor("PCECD", Priority = CorePriority.Low)]
public HyperNyma(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp) public HyperNyma(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp)
: base(lp.Comm, "PCE", "PC Engine Controller", lp.Settings, lp.SyncSettings) : base(lp.Comm, "PCE", "PC Engine Controller", lp.Settings, lp.SyncSettings)
{ {

View File

@ -26,6 +26,7 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCE
SettingOverrides["pce.disable_bram_hucard"].Default = "0"; SettingOverrides["pce.disable_bram_hucard"].Default = "0";
_turboNyma = DoInit<LibTurboNyma>(game, rom, null, "turbo.wbx", extension, deterministic); _turboNyma = DoInit<LibTurboNyma>(game, rom, null, "turbo.wbx", extension, deterministic);
} }
[CoreConstructor("PCECD")]
public TurboNyma(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp) public TurboNyma(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp)
: base(lp.Comm, "PCE", "PC Engine Controller", lp.Settings, lp.SyncSettings) : base(lp.Comm, "PCE", "PC Engine Controller", lp.Settings, lp.SyncSettings)
{ {

View File

@ -17,6 +17,7 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCFX
"https://mednafen.github.io/releases/", false, "PC-FX")] "https://mednafen.github.io/releases/", false, "PC-FX")]
public class Tst : NymaCore public class Tst : NymaCore
{ {
[CoreConstructor("PCFX")]
public Tst(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp) public Tst(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp)
: base(lp.Comm, "PCFX", "PC-FX Controller", lp.Settings, lp.SyncSettings) : base(lp.Comm, "PCFX", "PC-FX Controller", lp.Settings, lp.SyncSettings)
{ {

View File

@ -54,6 +54,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
int IVideoLogicalOffsets.ScreenY => Settings.TopLine; int IVideoLogicalOffsets.ScreenY => Settings.TopLine;
[CoreConstructor("PCECD", Priority = CorePriority.Low)]
public PCEngine(CoreLoadParameters<PCESettings, PCESyncSettings> lp) public PCEngine(CoreLoadParameters<PCESettings, PCESyncSettings> lp)
{ {
SystemId = "PCECD"; SystemId = "PCECD";

View File

@ -20,12 +20,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
public class Saturnus : NymaCore, IRegionable public class Saturnus : NymaCore, IRegionable
{ {
[CoreConstructor("SAT")] [CoreConstructor("SAT")]
public Saturnus(CoreComm comm, NymaSettings settings, NymaSyncSettings syncSettings)
: base(comm, "SAT", "Saturn Controller", settings, syncSettings)
{
throw new InvalidOperationException("To load a Saturn game, please load the CUE file and not the BIN file.");
}
public Saturnus(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp) public Saturnus(CoreLoadParameters<NymaSettings, NymaSyncSettings> lp)
: base(lp.Comm, "SAT", "Saturn Controller", lp.Settings, lp.SyncSettings) : base(lp.Comm, "SAT", "Saturn Controller", lp.Settings, lp.SyncSettings)
{ {