Open main menu

Difference between revisions of "HOWTO-Engines"

284 bytes added ,  23:12, 3 February 2008
(→‎Example: engines/quux/quux.cpp: quux.cpp was badly outdated and broken -- fixed it)
Line 151: Line 151:
#include "base/game.h"
#include "base/game.h"
#include "base/plugins.h"
#include "base/plugins.h"
#include "engines/metaengine.h"


#include "quux/quux.h"
#include "quux/quux.h"
Line 161: Line 163:
};
};


GameList Engine_QUUX_gameIDList() {
class QuuxMetaEngine : public MetaEngine {
GameList games;
public:
const PlainGameDescriptor *g = quux_setting;
virtual const char *getName() const {
while (g->gameid) {
return "Quux the Example Module";
games.push_back(*g);
}
g++;
virtual const char *getCopyright() const {
return "Copyright (C) Quux Entertainment Ltd.";
}
}


return games;
virtual GameList getSupportedGames() const {
}
GameList games;
 
const PlainGameDescriptor *g = quux_setting;
GameDescriptor Engine_QUUX_findGameID(const char *gameid) {
while (g->gameid) {
const PlainGameDescriptor *g = quux_setting;
games.push_back(*g);
while (g->gameid) {
g++;
if (0 == scumm_stricmp(gameid, g->gameid))
}
break;
g++;
return games;
}
}
return GameDescriptor(g->gameid, g->description);
}
GameList Engine_QUUX_detectGames(const FSList &fslist) {
GameList detectedGames;
// Iterate over all files in the given directory
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
if (!file->isDirectory()) {
const char *gameName = file->getName().c_str();


if (0 == scumm_stricmp("README", gameName)) {
virtual GameDescriptor findGame(const char *gameid) const {
// You could check the contents of the file now if you need to.
const PlainGameDescriptor *g = quux_setting;
detectedGames.push_back(quux_setting[0]);
while (g->gameid) {
if (0 == scumm_stricmp(gameid, g->gameid))
break;
break;
}
g++;
}
}
return GameDescriptor(g->gameid, g->description);
}
}
return detectedGames;
}


PluginError Engine_QUUX_create(OSystem *syst, Engine **engine) {
virtual GameList detectGames(const FSList &fslist) const {
assert(syst);
GameList detectedGames;
assert(engine);
 
// Iterate over all files in the given directory
// Scan the target directory for files (error out if it does not exist)
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
FSList fslist;
if (!file->isDirectory()) {
FilesystemNode dir(ConfMan.get("path"));
const char *gameName = file->getName().c_str();
if (!dir.getChildren(fslist, FilesystemNode::kListAll)) {
return kInvalidPathError;
if (0 == scumm_stricmp("README", gameName)) {
// You could check the contents of the file now if you need to.
detectedGames.push_back(quux_setting[0]);
break;
}
}
}
return detectedGames;
}
}


// Invoke the detector
virtual PluginError createInstance(OSystem *syst, Engine **engine) const {
Common::String gameid = ConfMan.get("gameid");
assert(syst);
GameList detectedGames = Engine_QUUX_detectGames(fslist);
assert(engine);
 
 
// Scan the target directory for files (error out if it does not exist)
for (uint i = 0; i < detectedGames.size(); i++) {
FSList fslist;
if (detectedGames[i].gameid() == gameid) {
FilesystemNode dir(ConfMan.get("path"));
// At this point you may want to perform additional sanity checks.
if (!dir.getChildren(fslist, FilesystemNode::kListAll)) {
*engine = new Quux::QuuxEngine(syst);
return kInvalidPathError;
return kNoError;
}
// Invoke the detector
Common::String gameid = ConfMan.get("gameid");
GameList detectedGames = detectGames(fslist);
for (uint i = 0; i < detectedGames.size(); i++) {
if (detectedGames[i].gameid() == gameid) {
// At this point you may want to perform additional sanity checks.
*engine = new Quux::QuuxEngine(syst);
return kNoError;
}
}
}
// Failed to find any game data
return kNoGameDataFoundError;
}
}
};


// Failed to find any game data
return kNoGameDataFoundError;
}


REGISTER_PLUGIN(QUUX, "Quux the Example Module", "Copyright (C) Quux Entertainment Ltd.");
REGISTER_PLUGIN(QUUX, QuuxMetaEngine);




1,079

edits