From 5f5ac6b475599da5c11df98852f1dbd1e62db8b5 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 7 May 2019 15:27:14 +1000 Subject: GLK: MAGNETIC: Hook up Magnetic sub-engine --- engines/glk/detection.cpp | 19 ++++++++++++++----- engines/glk/magnetic/detection.cpp | 32 +++++++++++++++----------------- engines/glk/magnetic/detection.h | 22 ++++------------------ engines/glk/magnetic/detection_tables.h | 2 +- 4 files changed, 34 insertions(+), 41 deletions(-) (limited to 'engines/glk') diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index f9b06a22d8..193d439ba9 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -28,6 +28,8 @@ #include "glk/frotz/frotz.h" #include "glk/glulxe/detection.h" #include "glk/glulxe/glulxe.h" +#include "glk/magnetic/detection.h" +#include "glk/magnetic/magnetic.h" #include "glk/scott/detection.h" #include "glk/scott/scott.h" #include "glk/tads/detection.h" @@ -108,10 +110,11 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons // Create the correct engine *engine = nullptr; if ((*engine = create(syst, gameDesc)) != nullptr) {} + else if ((*engine = create(syst, gameDesc)) != nullptr) {} else if ((*engine = create(syst, gameDesc)) != nullptr) {} #ifndef RELEASE_BUILD else if ((*engine = create(syst, gameDesc)) != nullptr) {} - else if ((*engine = create(syst, gameDesc)) != nullptr) {} + else if ((*engine = create(syst, gameDesc)) != nullptr) {} else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description) { if (td._options & Glk::TADS::OPTION_TADS3) *engine = new Glk::TADS::TADS3::TADS3(syst, gameDesc); @@ -151,10 +154,11 @@ Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) con PlainGameList GlkMetaEngine::getSupportedGames() const { PlainGameList list; Glk::Frotz::FrotzMetaEngine::getSupportedGames(list); + Glk::Glulxe::GlulxeMetaEngine::getSupportedGames(list); Glk::Scott::ScottMetaEngine::getSupportedGames(list); #ifndef RELEASE_BUILD Glk::Alan2::Alan2MetaEngine::getSupportedGames(list); - Glk::Glulxe::GlulxeMetaEngine::getSupportedGames(list); + Glk::Magnetic::MagneticMetaEngine::getSupportedGames(list); Glk::TADS::TADSMetaEngine::getSupportedGames(list); #endif @@ -165,6 +169,9 @@ PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const { Glk::GameDescriptor gd = Glk::Frotz::FrotzMetaEngine::findGame(gameId); if (gd._description) return gd; + gd = Glk::Glulxe::GlulxeMetaEngine::findGame(gameId); + if (gd._description) return gd; + gd = Glk::Scott::ScottMetaEngine::findGame(gameId); if (gd._description) return gd; @@ -172,7 +179,7 @@ PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const { gd = Glk::Alan2::Alan2MetaEngine::findGame(gameId); if (gd._description) return gd; - gd = Glk::Glulxe::GlulxeMetaEngine::findGame(gameId); + gd = Glk::Magnetic::MagneticMetaEngine::findGame(gameId); if (gd._description) return gd; gd = Glk::TADS::TADSMetaEngine::findGame(gameId); @@ -187,11 +194,12 @@ DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const { DetectedGames detectedGames; Glk::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames); + Glk::Glulxe::GlulxeMetaEngine::detectGames(fslist, detectedGames); Glk::Scott::ScottMetaEngine::detectGames(fslist, detectedGames); #ifndef RELEASE_BUILD Glk::Alan2::Alan2MetaEngine::detectGames(fslist, detectedGames); - Glk::Glulxe::GlulxeMetaEngine::detectGames(fslist, detectedGames); + Glk::Magnetic::MagneticMetaEngine::detectGames(fslist, detectedGames); Glk::TADS::TADSMetaEngine::detectGames(fslist, detectedGames); #endif @@ -201,11 +209,12 @@ DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const { void GlkMetaEngine::detectClashes() const { Common::StringMap map; Glk::Frotz::FrotzMetaEngine::detectClashes(map); + Glk::Glulxe::GlulxeMetaEngine::detectClashes(map); Glk::Scott::ScottMetaEngine::detectClashes(map); #ifndef RELEASE_BUILD Glk::Alan2::Alan2MetaEngine::detectClashes(map); - Glk::Glulxe::GlulxeMetaEngine::detectClashes(map); + Glk::Magnetic::MagneticMetaEngine::detectClashes(map); Glk::TADS::TADSMetaEngine::detectClashes(map); #endif } diff --git a/engines/glk/magnetic/detection.cpp b/engines/glk/magnetic/detection.cpp index cfd0102895..db899a28be 100644 --- a/engines/glk/magnetic/detection.cpp +++ b/engines/glk/magnetic/detection.cpp @@ -31,22 +31,22 @@ namespace Glk { namespace Magnetic { void MagneticMetaEngine::getSupportedGames(PlainGameList &games) { - for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { + for (const PlainGameDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { games.push_back(*pd); } } -MagneticDescriptor MagneticMetaEngine::findGame(const char *gameId) { - for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { +GameDescriptor MagneticMetaEngine::findGame(const char *gameId) { + for (const PlainGameDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { if (!strcmp(gameId, pd->gameId)) return *pd; } - return MagneticDescriptor(); + return PlainGameDescriptor(); } bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { - const char *const EXTENSIONS[] = { ".magnetic", nullptr }; + const char *const EXTENSIONS[] = { ".rsc", nullptr }; // Loop through the files of the folder for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { @@ -64,6 +64,12 @@ bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames Common::File gameFile; if (!gameFile.open(*file)) continue; + if (gameFile.readUint32BE() != MKTAG('M', 'a', 'S', 'c')) { + gameFile.close(); + continue; + } + + gameFile.seek(0); Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000); size_t filesize = gameFile.size(); gameFile.close(); @@ -76,18 +82,10 @@ bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames DetectedGame gd; if (!p->_gameId) { if (gDebugLevel > 0) { - // Print an entry suitable for putting into the detection_tables.h, using the - // name of the parent folder the game is in as the presumed game Id - Common::String folderName = file->getParent().getName(); - if (folderName.hasSuffix("\\")) - folderName.deleteLastChar(); - Common::String fname = filename; - const char *dot = strchr(fname.c_str(), '.'); - if (dot) - fname = Common::String(fname.c_str(), dot); - - debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize); + // Print an entry suitable for putting into the detection_tables.h + debug("ENTRY0(\"%s\", \"%s\", %u),", filename.c_str(), md5.c_str(), (uint)filesize); } + const PlainGameDescriptor &desc = MAGNETIC_GAME_LIST[0]; gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); } else { @@ -104,7 +102,7 @@ bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames } void MagneticMetaEngine::detectClashes(Common::StringMap &map) { - for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { + for (const PlainGameDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) { if (map.contains(pd->gameId)) error("Duplicate game Id found - %s", pd->gameId); map[pd->gameId] = ""; diff --git a/engines/glk/magnetic/detection.h b/engines/glk/magnetic/detection.h index 3ea881075e..28ea70ffc2 100644 --- a/engines/glk/magnetic/detection.h +++ b/engines/glk/magnetic/detection.h @@ -20,31 +20,17 @@ * */ -#ifndef GLK_GLULXE_DETECTION -#define GLK_GLULXE_DETECTION +#ifndef GLK_MAGNETIC_DETECTION +#define GLK_MAGNETIC_DETECTION #include "common/fs.h" #include "common/hash-str.h" #include "engines/game.h" +#include "glk/detection.h" namespace Glk { namespace Magnetic { -/** - * Magnetic game descriptior - */ -struct MagneticDescriptor { - const char *gameId; - const char *description; - - operator PlainGameDescriptor() const { - PlainGameDescriptor pd; - pd.gameId = gameId; - pd.description = description; - return pd; - } -}; - /** * Meta engine for Magnetic interpreter */ @@ -58,7 +44,7 @@ public: /** * Returns a game description for the given game Id, if it's supported */ - static MagneticDescriptor findGame(const char *gameId); + static GameDescriptor findGame(const char *gameId); /** * Detect supported games diff --git a/engines/glk/magnetic/detection_tables.h b/engines/glk/magnetic/detection_tables.h index a67d2a9a77..18d3b84b33 100644 --- a/engines/glk/magnetic/detection_tables.h +++ b/engines/glk/magnetic/detection_tables.h @@ -38,7 +38,7 @@ struct MagneticGameDescription { Common::Language _language; }; -const MagneticDescriptor MAGNETIC_GAME_LIST[] = { +const PlainGameDescriptor MAGNETIC_GAME_LIST[] = { { "magnetic", "Magnetic Scrolls Game" }, { nullptr, nullptr } -- cgit v1.2.3