From 4938ac9ea1b207f100a73e2ecbf617b7569fb4b0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 31 Dec 2018 22:32:07 -0800 Subject: [PATCH] GLK: Implement passing detection options to the engines --- engines/glk/detection.cpp | 28 +++++++++++++++++++--------- engines/glk/frotz/config.cpp | 6 ++++++ engines/glk/frotz/config.h | 5 +++++ engines/glk/frotz/detection.cpp | 7 +++++-- engines/glk/frotz/detection.h | 7 +++++++ engines/glk/frotz/frotz.cpp | 2 ++ engines/glk/glk.h | 6 ++++++ 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index a1786d047cc..4c0932a561d 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -63,6 +63,18 @@ bool Glk::GlkEngine::hasFeature(EngineFeature f) const { (f == kSupportsSavingDuringRuntime); } +templateEngine *create(OSystem *syst, Glk::GlkGameDescription &gameDesc) { + Glk::GameDescriptor gd = META::findGame(gameDesc._gameId.c_str()); + if (gd._description) { + gameDesc._options = gd._options; + return new ENG(syst, gameDesc); + } else { + return nullptr; + } +} + +#define CREATE(META, ENG) if (!(*engine = create(syst, gameDesc))) + Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const { Glk::GameDescriptor td = Glk::GameDescriptor::empty(); assert(engine); @@ -96,15 +108,11 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons f.close(); // Create the correct engine - if (Glk::Alan2::Alan2MetaEngine::findGame(gameDesc._gameId.c_str())._description) { - *engine = new Glk::Alan2::Alan2(syst, gameDesc); - } else if (Glk::Frotz::FrotzMetaEngine::findGame(gameDesc._gameId.c_str())._description) { - *engine = new Glk::Frotz::Frotz(syst, gameDesc); - } else if (Glk::Glulxe::GlulxeMetaEngine::findGame(gameDesc._gameId.c_str())._description) { - *engine = new Glk::Glulxe::Glulxe(syst, gameDesc); - } else if (Glk::Scott::ScottMetaEngine::findGame(gameDesc._gameId.c_str())._description) { - *engine = new Glk::Scott::Scott(syst, gameDesc); - } else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description) { + CREATE(Glk::Alan2::Alan2MetaEngine, Glk::Alan2::Alan2) + CREATE(Glk::Frotz::FrotzMetaEngine, Glk::Frotz::Frotz) + CREATE(Glk::Glulxe::GlulxeMetaEngine, Glk::Glulxe::Glulxe) + CREATE(Glk::Scott::ScottMetaEngine, Glk::Scott::Scott) + 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); else @@ -116,6 +124,8 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons return Common::kNoError; } +#undef CREATE + Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) const { // Get the list of files in the folder and return detection against them Common::FSNode folder = Common::FSNode(ConfMan.get("path")); diff --git a/engines/glk/frotz/config.cpp b/engines/glk/frotz/config.cpp index 1d0264bc8e0..aff46792d37 100644 --- a/engines/glk/frotz/config.cpp +++ b/engines/glk/frotz/config.cpp @@ -21,6 +21,8 @@ */ #include "glk/frotz/config.h" +#include "glk/frotz/detection.h" +#include "glk/glk.h" #include "common/config-manager.h" #include "common/textconsole.h" @@ -162,5 +164,9 @@ UserOptions::UserOptions() : _undo_slots(MAX_UNDO_SLOTS), _sound(true), _quetzal _defaultBackground = getConfigInt("background", 0x000080, 0xffffff); } +bool UserOptions::isInfocom() const { + return g_vm->getOptions() & OPTION_INFOCOM; +} + } // End of namespace Scott } // End of namespace Glk diff --git a/engines/glk/frotz/config.h b/engines/glk/frotz/config.h index 17e787de3b9..1086d7e51fd 100644 --- a/engines/glk/frotz/config.h +++ b/engines/glk/frotz/config.h @@ -155,6 +155,11 @@ struct UserOptions { * Constructor */ UserOptions(); + + /** + * Returns true if the game being played is one of the original Infocom releases + */ + bool isInfocom() const; }; /** diff --git a/engines/glk/frotz/detection.cpp b/engines/glk/frotz/detection.cpp index 57e2961fd7c..273ca373420 100644 --- a/engines/glk/frotz/detection.cpp +++ b/engines/glk/frotz/detection.cpp @@ -41,8 +41,11 @@ void FrotzMetaEngine::getSupportedGames(PlainGameList &games) { GameDescriptor FrotzMetaEngine::findGame(const char *gameId) { for (const PlainGameDescriptor *pd = INFOCOM_GAME_LIST; pd->gameId; ++pd) { - if (!strcmp(gameId, pd->gameId)) - return *pd; + if (!strcmp(gameId, pd->gameId)) { + GameDescriptor gd(*pd); + gd._options |= OPTION_INFOCOM; + return gd; + } } for (const PlainGameDescriptor *pd = ZCODE_GAME_LIST; pd->gameId; ++pd) { if (!strcmp(gameId, pd->gameId)) diff --git a/engines/glk/frotz/detection.h b/engines/glk/frotz/detection.h index e0163bc9f7e..7943385aa90 100644 --- a/engines/glk/frotz/detection.h +++ b/engines/glk/frotz/detection.h @@ -32,6 +32,13 @@ namespace Glk { namespace Frotz { +/** + * Game descriptor detection options + */ +enum DetectionOption { + OPTION_INFOCOM = 1 +}; + class FrotzMetaEngine { public: /** diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp index c2341d40264..3d6bf6c9f98 100644 --- a/engines/glk/frotz/frotz.cpp +++ b/engines/glk/frotz/frotz.cpp @@ -48,6 +48,8 @@ void Frotz::runGame(Common::SeekableReadStream *gameFile) { story_fp = gameFile; initialize(); + debug("Game %s an Infocom original", isInfocom() ? "is" : "isn't"); + // If save was selected from the launcher, handle loading it int saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; if (saveSlot != -1) { diff --git a/engines/glk/glk.h b/engines/glk/glk.h index 55066e2cdee..91a6371e98f 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -60,6 +60,7 @@ struct GlkGameDescription { Common::Platform _platform; Common::String _filename; Common::String _md5; + uint _options; }; /** @@ -163,6 +164,11 @@ public: */ const Common::String &getFilename() const { return _gameDescription._filename; } + /** + * Returns any options returned with the game's detection entry + */ + const uint getOptions() const { return _gameDescription._options; } + /** * Return the game engine's target name */