Open main menu

Difference between revisions of "HOWTO-Engines"

881 bytes added ,  13:59, 22 January 2008
→‎Example: engines/quux/quux.cpp: quux.cpp was badly outdated and broken -- fixed it
(→‎Example: engines/quux/quux.h: update / compilation fixes)
(→‎Example: engines/quux/quux.cpp: quux.cpp was badly outdated and broken -- fixed it)
Line 143: Line 143:
<pre>
<pre>
#include "common/scummsys.h"
#include "common/scummsys.h"
#include "common/events.h" // for getEventManager()
#include "common/events.h" // for getEventManager()
#include "common/config-manager.h"
#include "common/file.h"
#include "common/fs.h"


#include "backends/fs/fs.h"
#include "base/game.h"
#include "base/gameDetector.h"
#include "base/plugins.h"
#include "base/plugins.h"


Line 152: Line 155:




static const GameSettings quux_setting[] = {
static const PlainGameDescriptor quux_setting[] = {
{ "quux", "Quux the Example Module", 0 },
{ "quux", "Quux the Example Module" },
{ "quuxcd", "Quux the Example Module (CD version)", 0 },
{ "quuxcd", "Quux the Example Module (CD version)" },
{ 0, 0, 0 }
{ 0, 0 }
};
};


GameList Engine_QUUX_gameList() {
GameList Engine_QUUX_gameIDList() {
GameList games;
GameList games;
const GameSettings *g = quux_setting;
const PlainGameDescriptor *g = quux_setting;
while (g->gameid) {
while (g->gameid) {
games.push_back(*g);
games.push_back(*g);
Line 169: Line 172:
}
}


DetectedGameList Engine_QUUX_detectGames(const FSList &fslist) {
GameDescriptor Engine_QUUX_findGameID(const char *gameid) {
DetectedGameList detectedGames;
const PlainGameDescriptor *g = quux_setting;
while (g->gameid) {
if (0 == scumm_stricmp(gameid, g->gameid))
break;
g++;
}
return GameDescriptor(g->gameid, g->description);
}
 
GameList Engine_QUUX_detectGames(const FSList &fslist) {
GameList detectedGames;


// Iterate over all files in the given directory
// Iterate over all files in the given directory
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
if (!file->isDirectory()) {
if (!file->isDirectory()) {
const char *gameName = file->displayName().c_str();
const char *gameName = file->getName().c_str();


if (0 == scumm_stricmp("README", gameName)) {
if (0 == scumm_stricmp("README", gameName)) {
Line 187: Line 200:
}
}


Engine *Engine_QUUX_create(GameDetector *detector, OSystem *syst) {
PluginError Engine_QUUX_create(OSystem *syst, Engine **engine) {
// At this point you may want to perform a sanity check on the
assert(syst);
// values in 'detecetor'.
assert(engine);
return new Quux::QuuxEngine(syst);
 
// Scan the target directory for files (error out if it does not exist)
FSList fslist;
FilesystemNode dir(ConfMan.get("path"));
if (!dir.getChildren(fslist, FilesystemNode::kListAll)) {
return kInvalidPathError;
}
 
// Invoke the detector
Common::String gameid = ConfMan.get("gameid");
GameList detectedGames = Engine_QUUX_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;
}
}


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




Line 208: Line 243:


// However this is the place to specify all default directories
// However this is the place to specify all default directories
File::addDefaultDirectory(_gameDataPath + "sound/");
Common::File::addDefaultDirectory(_gameDataPath + "sound/");


// Here is the right place to set up the engine specific debug levels
// Here is the right place to set up the engine specific debug levels
Line 228: Line 263:
}
}


int QuuxEngine::init(GameDetector &detector) {
int QuuxEngine::init() {
// Initialize graphics using following template
// Initialize graphics using following template
// You have to use transactions
// You have to use transactions
Line 234: Line 269:
// This is handled by base Engine class and processes command
// This is handled by base Engine class and processes command
// line parameters
// line parameters
_vm->initCommonGFX(detector);
initCommonGFX(true);


// Specify dimensions of game graphics window
// Specify dimensions of game graphics window.
_system->initSize(width, height);
// In this example: 320x200
_system->initSize(320, 200);
_system->endGFXTransaction();
_system->endGFXTransaction();
Line 260: Line 296:
return 0;
return 0;
}
}




1,079

edits