GLK: Standardizing on a common GameDescriptor class for detectors

This commit is contained in:
Paul Gilbert 2018-12-31 19:47:14 -08:00
parent 84b6534c3f
commit 013f39cb5d
15 changed files with 91 additions and 101 deletions

View file

@ -31,18 +31,18 @@ namespace Glk {
namespace Alan2 { namespace Alan2 {
void Alan2MetaEngine::getSupportedGames(PlainGameList &games) { void Alan2MetaEngine::getSupportedGames(PlainGameList &games) {
for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) {
games.push_back(*pd); games.push_back(*pd);
} }
} }
Alan2Descriptor Alan2MetaEngine::findGame(const char *gameId) { GameDescriptor Alan2MetaEngine::findGame(const char *gameId) {
for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) {
if (!strcmp(gameId, pd->gameId)) if (!strcmp(gameId, pd->gameId))
return *pd; return *pd;
} }
return Alan2Descriptor(); return GameDescriptor::empty();
} }
bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
@ -107,7 +107,7 @@ bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
} }
void Alan2MetaEngine::detectClashes(Common::StringMap &map) { void Alan2MetaEngine::detectClashes(Common::StringMap &map) {
for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) {
if (map.contains(pd->gameId)) if (map.contains(pd->gameId))
error("Duplicate game Id found - %s", pd->gameId); error("Duplicate game Id found - %s", pd->gameId);
map[pd->gameId] = ""; map[pd->gameId] = "";

View file

@ -26,25 +26,11 @@
#include "common/fs.h" #include "common/fs.h"
#include "common/hash-str.h" #include "common/hash-str.h"
#include "engines/game.h" #include "engines/game.h"
#include "glk/detection.h"
namespace Glk { namespace Glk {
namespace Alan2 { namespace Alan2 {
/**
* Alan2 game descriptior
*/
struct Alan2Descriptor {
const char *gameId;
const char *description;
operator PlainGameDescriptor() const {
PlainGameDescriptor pd;
pd.gameId = gameId;
pd.description = description;
return pd;
}
};
/** /**
* Meta engine for Alan2 interpreter * Meta engine for Alan2 interpreter
*/ */
@ -58,7 +44,7 @@ public:
/** /**
* Returns a game description for the given game Id, if it's supported * Returns a game description for the given game Id, if it's supported
*/ */
static Alan2Descriptor findGame(const char *gameId); static GameDescriptor findGame(const char *gameId);
/** /**
* Detect supported games * Detect supported games

View file

@ -38,9 +38,8 @@ struct Alan2GameDescription {
Common::Language _language; Common::Language _language;
}; };
const Alan2Descriptor ALAN2_GAME_LIST[] = { const PlainGameDescriptor ALAN2_GAME_LIST[] = {
{ "alan2", "Alan2 Game" }, { "alan2", "Alan2 Game" },
//{ "cragne", "Cragne Manor" },
{ nullptr, nullptr } { nullptr, nullptr }
}; };

View file

@ -64,7 +64,7 @@ bool Glk::GlkEngine::hasFeature(EngineFeature f) const {
} }
Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const { Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
Glk::TADS::TADSDescriptor td; Glk::GameDescriptor td = Glk::GameDescriptor::empty();
assert(engine); assert(engine);
// Populate the game description // Populate the game description
@ -96,16 +96,16 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
f.close(); f.close();
// Create the correct engine // Create the correct engine
if (Glk::Alan2::Alan2MetaEngine::findGame(gameDesc._gameId.c_str()).description) { if (Glk::Alan2::Alan2MetaEngine::findGame(gameDesc._gameId.c_str())._description) {
*engine = new Glk::Alan2::Alan2(syst, gameDesc); *engine = new Glk::Alan2::Alan2(syst, gameDesc);
} else if (Glk::Frotz::FrotzMetaEngine::findGame(gameDesc._gameId.c_str()).description) { } else if (Glk::Frotz::FrotzMetaEngine::findGame(gameDesc._gameId.c_str())._description) {
*engine = new Glk::Frotz::Frotz(syst, gameDesc); *engine = new Glk::Frotz::Frotz(syst, gameDesc);
} else if (Glk::Glulxe::GlulxeMetaEngine::findGame(gameDesc._gameId.c_str()).description) { } else if (Glk::Glulxe::GlulxeMetaEngine::findGame(gameDesc._gameId.c_str())._description) {
*engine = new Glk::Glulxe::Glulxe(syst, gameDesc); *engine = new Glk::Glulxe::Glulxe(syst, gameDesc);
} else if (Glk::Scott::ScottMetaEngine::findGame(gameDesc._gameId.c_str()).description) { } else if (Glk::Scott::ScottMetaEngine::findGame(gameDesc._gameId.c_str())._description) {
*engine = new Glk::Scott::Scott(syst, gameDesc); *engine = new Glk::Scott::Scott(syst, gameDesc);
} else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str())).description) { } else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description) {
if (td.isTADS3) if (td._options & Glk::TADS::OPTION_TADS3)
*engine = new Glk::TADS::TADS3::TADS3(syst, gameDesc); *engine = new Glk::TADS::TADS3::TADS3(syst, gameDesc);
else else
*engine = new Glk::TADS::TADS2::TADS2(syst, gameDesc); *engine = new Glk::TADS::TADS2::TADS2(syst, gameDesc);
@ -150,22 +150,20 @@ PlainGameList GlkMetaEngine::getSupportedGames() const {
} }
PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const { PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const {
PlainGameDescriptor gd; Glk::GameDescriptor gd = Glk::Alan2::Alan2MetaEngine::findGame(gameId);
if (gd._description) return gd;
gd = Glk::Alan2::Alan2MetaEngine::findGame(gameId);
if (gd.description) return gd;
gd = Glk::Frotz::FrotzMetaEngine::findGame(gameId); gd = Glk::Frotz::FrotzMetaEngine::findGame(gameId);
if (gd.description) return gd; if (gd._description) return gd;
gd = Glk::Glulxe::GlulxeMetaEngine::findGame(gameId); gd = Glk::Glulxe::GlulxeMetaEngine::findGame(gameId);
if (gd.description) return gd; if (gd._description) return gd;
gd = Glk::Scott::ScottMetaEngine::findGame(gameId); gd = Glk::Scott::ScottMetaEngine::findGame(gameId);
if (gd.description) return gd; if (gd._description) return gd;
gd = Glk::TADS::TADSMetaEngine::findGame(gameId); gd = Glk::TADS::TADSMetaEngine::findGame(gameId);
if (gd.description) return gd; if (gd._description) return gd;
return PlainGameDescriptor(); return PlainGameDescriptor();
} }

View file

@ -24,9 +24,13 @@
#define GLK_DETECTION_H #define GLK_DETECTION_H
#include "engines/advancedDetector.h" #include "engines/advancedDetector.h"
#include "engines/game.h"
#define MAX_SAVES 99 #define MAX_SAVES 99
/**
* ScummVM Meta Engine interface
*/
class GlkMetaEngine : public MetaEngine { class GlkMetaEngine : public MetaEngine {
private: private:
Common::String findFileByGameId(const Common::String &gameId) const; Common::String findFileByGameId(const Common::String &gameId) const;
@ -71,4 +75,33 @@ public:
void detectClashes() const; void detectClashes() const;
}; };
namespace Glk {
/**
* Holds the name of a recognised game
*/
struct GameDescriptor {
const char *_gameId;
const char *_description;
uint _options;
GameDescriptor(const char *gameId, const char *description, uint options) :
_gameId(gameId), _description(description), _options(options) {}
GameDescriptor(const PlainGameDescriptor &gd) : _gameId(gd.gameId), _description(gd.description),
_options(0) {}
static PlainGameDescriptor empty() {
return GameDescriptor(nullptr, nullptr, 0);
}
operator PlainGameDescriptor() const {
PlainGameDescriptor pd;
pd.gameId = _gameId;
pd.description = _description;
return pd;
}
};
} // End of namespace Glk
#endif #endif

View file

@ -39,7 +39,7 @@ void FrotzMetaEngine::getSupportedGames(PlainGameList &games) {
games.push_back(*pd); games.push_back(*pd);
} }
PlainGameDescriptor FrotzMetaEngine::findGame(const char *gameId) { GameDescriptor FrotzMetaEngine::findGame(const char *gameId) {
for (const PlainGameDescriptor *pd = INFOCOM_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = INFOCOM_GAME_LIST; pd->gameId; ++pd) {
if (!strcmp(gameId, pd->gameId)) if (!strcmp(gameId, pd->gameId))
return *pd; return *pd;
@ -49,7 +49,7 @@ PlainGameDescriptor FrotzMetaEngine::findGame(const char *gameId) {
return *pd; return *pd;
} }
return PlainGameDescriptor();; return GameDescriptor::empty();
} }
bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
@ -129,8 +129,8 @@ bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
const PlainGameDescriptor &desc = ZCODE_GAME_LIST[0]; const PlainGameDescriptor &desc = ZCODE_GAME_LIST[0];
gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown);
} else { } else {
PlainGameDescriptor gameDesc = findGame(p->_gameId); GameDescriptor gameDesc = findGame(p->_gameId);
gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra); gd = DetectedGame(p->_gameId, gameDesc._description, p->_language, Common::kPlatformUnknown, p->_extra);
gd.setGUIOptions(p->_guiOptions); gd.setGUIOptions(p->_guiOptions);
} }

View file

@ -27,6 +27,7 @@
#include "common/hash-str.h" #include "common/hash-str.h"
#include "engines/game.h" #include "engines/game.h"
#include "glk/streams.h" #include "glk/streams.h"
#include "glk/detection.h"
namespace Glk { namespace Glk {
namespace Frotz { namespace Frotz {
@ -38,11 +39,10 @@ public:
*/ */
static void getSupportedGames(PlainGameList &games); static void getSupportedGames(PlainGameList &games);
/** /**
* Returns a game description for the given game Id, if it's supported * Returns a game description for the given game Id, if it's supported
*/ */
static PlainGameDescriptor findGame(const char *gameId); static GameDescriptor findGame(const char *gameId);
/** /**
* Detect supported games * Detect supported games

View file

@ -31,18 +31,18 @@ namespace Glk {
namespace Glulxe { namespace Glulxe {
void GlulxeMetaEngine::getSupportedGames(PlainGameList &games) { void GlulxeMetaEngine::getSupportedGames(PlainGameList &games) {
for (const GlulxeDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) {
games.push_back(*pd); games.push_back(*pd);
} }
} }
GlulxeDescriptor GlulxeMetaEngine::findGame(const char *gameId) { GameDescriptor GlulxeMetaEngine::findGame(const char *gameId) {
for (const GlulxeDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) {
if (!strcmp(gameId, pd->gameId)) if (!strcmp(gameId, pd->gameId))
return *pd; return *pd;
} }
return GlulxeDescriptor(); return GameDescriptor::empty();
} }
bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
@ -107,7 +107,7 @@ bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
} }
void GlulxeMetaEngine::detectClashes(Common::StringMap &map) { void GlulxeMetaEngine::detectClashes(Common::StringMap &map) {
for (const GlulxeDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = GLULXE_GAME_LIST; pd->gameId; ++pd) {
if (map.contains(pd->gameId)) if (map.contains(pd->gameId))
error("Duplicate game Id found - %s", pd->gameId); error("Duplicate game Id found - %s", pd->gameId);
map[pd->gameId] = ""; map[pd->gameId] = "";

View file

@ -26,25 +26,11 @@
#include "common/fs.h" #include "common/fs.h"
#include "common/hash-str.h" #include "common/hash-str.h"
#include "engines/game.h" #include "engines/game.h"
#include "glk/detection.h"
namespace Glk { namespace Glk {
namespace Glulxe { namespace Glulxe {
/**
* Glulxe game descriptior
*/
struct GlulxeDescriptor {
const char *gameId;
const char *description;
operator PlainGameDescriptor() const {
PlainGameDescriptor pd;
pd.gameId = gameId;
pd.description = description;
return pd;
}
};
/** /**
* Meta engine for Glulxe interpreter * Meta engine for Glulxe interpreter
*/ */
@ -58,7 +44,7 @@ public:
/** /**
* Returns a game description for the given game Id, if it's supported * Returns a game description for the given game Id, if it's supported
*/ */
static GlulxeDescriptor findGame(const char *gameId); static GameDescriptor findGame(const char *gameId);
/** /**
* Detect supported games * Detect supported games

View file

@ -38,7 +38,7 @@ struct GlulxeGameDescription {
Common::Language _language; Common::Language _language;
}; };
const GlulxeDescriptor GLULXE_GAME_LIST[] = { const PlainGameDescriptor GLULXE_GAME_LIST[] = {
{ "glulxe", "Glulxe Game" }, { "glulxe", "Glulxe Game" },
{ "cragne", "Cragne Manor" }, { "cragne", "Cragne Manor" },

View file

@ -34,13 +34,13 @@ void ScottMetaEngine::getSupportedGames(PlainGameList &games) {
games.push_back(*pd); games.push_back(*pd);
} }
PlainGameDescriptor ScottMetaEngine::findGame(const char *gameId) { GameDescriptor ScottMetaEngine::findGame(const char *gameId) {
for (const PlainGameDescriptor *pd = SCOTT_GAME_LIST; pd->gameId; ++pd) { for (const PlainGameDescriptor *pd = SCOTT_GAME_LIST; pd->gameId; ++pd) {
if (!strcmp(gameId, pd->gameId)) if (!strcmp(gameId, pd->gameId))
return *pd; return *pd;
} }
return PlainGameDescriptor();; return GameDescriptor::empty();
} }
bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {

View file

@ -26,6 +26,7 @@
#include "common/fs.h" #include "common/fs.h"
#include "common/hash-str.h" #include "common/hash-str.h"
#include "engines/game.h" #include "engines/game.h"
#include "glk/detection.h"
namespace Glk { namespace Glk {
namespace Scott { namespace Scott {
@ -40,7 +41,7 @@ public:
/** /**
* Returns a game description for the given game Id, if it's supported * Returns a game description for the given game Id, if it's supported
*/ */
static PlainGameDescriptor findGame(const char *gameId); static GameDescriptor findGame(const char *gameId);
/** /**
* Detect supported games * Detect supported games

View file

@ -31,18 +31,18 @@ namespace Glk {
namespace TADS { namespace TADS {
void TADSMetaEngine::getSupportedGames(PlainGameList &games) { void TADSMetaEngine::getSupportedGames(PlainGameList &games) {
for (const TADSDescriptor *pd = TADS_GAME_LIST; pd->gameId; ++pd) { for (const GameDescriptor *pd = TADS_GAME_LIST; pd->_gameId; ++pd) {
games.push_back(*pd); games.push_back(*pd);
} }
} }
TADSDescriptor TADSMetaEngine::findGame(const char *gameId) { GameDescriptor TADSMetaEngine::findGame(const char *gameId) {
for (const TADSDescriptor *pd = TADS_GAME_LIST; pd->gameId; ++pd) { for (const GameDescriptor *pd = TADS_GAME_LIST; pd->_gameId; ++pd) {
if (!strcmp(gameId, pd->gameId)) if (!strcmp(gameId, pd->_gameId))
return *pd; return *pd;
} }
return TADSDescriptor();; return GameDescriptor::empty();
} }
bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
@ -81,8 +81,8 @@ bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &ga
debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize); debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize);
} }
const TADSDescriptor &desc = TADS_GAME_LIST[0]; const GameDescriptor &desc = TADS_GAME_LIST[0];
gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); gd = DetectedGame(desc._gameId, desc._description, Common::UNK_LANG, Common::kPlatformUnknown);
} }
else { else {
PlainGameDescriptor gameDesc = findGame(p->_gameId); PlainGameDescriptor gameDesc = findGame(p->_gameId);
@ -97,10 +97,10 @@ bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &ga
} }
void TADSMetaEngine::detectClashes(Common::StringMap &map) { void TADSMetaEngine::detectClashes(Common::StringMap &map) {
for (const TADSDescriptor *pd = TADS_GAME_LIST; pd->gameId; ++pd) { for (const GameDescriptor *pd = TADS_GAME_LIST; pd->_gameId; ++pd) {
if (map.contains(pd->gameId)) if (map.contains(pd->_gameId))
error("Duplicate game Id found - %s", pd->gameId); error("Duplicate game Id found - %s", pd->_gameId);
map[pd->gameId] = ""; map[pd->_gameId] = "";
} }
} }

View file

@ -25,25 +25,12 @@
#include "common/fs.h" #include "common/fs.h"
#include "engines/game.h" #include "engines/game.h"
#include "glk/detection.h"
namespace Glk { namespace Glk {
namespace TADS { namespace TADS {
/** enum TADSOption { OPTION_TADS2 = 0, OPTION_TADS3 = 1 };
* TADS game descriptior
*/
struct TADSDescriptor {
const char *gameId;
const char *description;
bool isTADS3;
operator PlainGameDescriptor() const {
PlainGameDescriptor pd;
pd.gameId = gameId;
pd.description = description;
return pd;
}
};
/** /**
* Meta engine for TADS interpreter * Meta engine for TADS interpreter
@ -58,7 +45,7 @@ public:
/** /**
* Returns a game description for the given game Id, if it's supported * Returns a game description for the given game Id, if it's supported
*/ */
static TADSDescriptor findGame(const char *gameId); static GameDescriptor findGame(const char *gameId);
/** /**
* Detect supported games * Detect supported games

View file

@ -38,14 +38,14 @@ struct TADSGameDescription {
Common::Language _language; Common::Language _language;
}; };
const TADSDescriptor TADS_GAME_LIST[] = { const GameDescriptor TADS_GAME_LIST[] = {
// TADS 2 Games // TADS 2 Games
{ "tads2", "TADS 2 Game", false }, { "tads2", "TADS 2 Game", OPTION_TADS2 },
{ "oncefuture", "Once and Future", false }, { "oncefuture", "Once and Future", OPTION_TADS2 },
// TADS 3 Games // TADS 3 Games
{ "tads3", "TADS 3 Game", true }, { "tads3", "TADS 3 Game", OPTION_TADS3 },
{ nullptr, nullptr, false } { nullptr, nullptr, 0 }
}; };
#define ENTRY0(ID, MD5, FILESIZE) { ID, "", MD5, FILESIZE, Common::EN_ANY } #define ENTRY0(ID, MD5, FILESIZE) { ID, "", MD5, FILESIZE, Common::EN_ANY }