Open main menu

Difference between revisions of "HOWTO-Engines"

2,284 bytes added ,  13:21, 12 February 2006
Added code for a minimal example "engine"
(Added example module.mk)
(Added code for a minimal example "engine")
Line 26: Line 26:


Important note: Use a C++ namespace for all your work, e.g. "namespace Quux" in this case.
Important note: Use a C++ namespace for all your work, e.g. "namespace Quux" in this case.
=== Subclassing Engine ===
TODO: We should probably give some sample code, maybe even provide a full (empty) Engine demo class. Maybe even provide a real mini engine project somewhere on our site which demonstrates using events, drawing, etc. ? Not sure whether this would be worth the effort, though.
TODO: At the very least, describe the plugin interface: I.e. which functions *must* be implemented, and what they are supposed to do. Once again, sample code would be nice.
=== Example: engines/quux/quux.h ===
<pre>
#ifndef QUUX_H
#define QUUX_H
#include "base/engine.h"
namespace Quux {
class QuuxEngine : public Engine {
public:
QuuxEngine(OSystem *syst);
~QuuxEngine();
virtual int init(GameDetector &detector);
virtual int go();
};
} // End of namespace Quux
#endif
</pre>
=== Example: engines/quux/quux.cpp ===
<pre>
#include "common/stdafx.h"
#include "backends/fs/fs.h"
#include "base/gameDetector.h"
#include "base/plugins.h"
#include "quux/quux.h"
static const GameSettings quux_setting[] = {
{ "quux", "Quux the Example Module", 0 },
{ "quuxcd", "Quux the Example Module (CD version)", 0 },
{ 0, 0, 0 }
};
GameList Engine_QUUX_gameList() {
GameList games;
const GameSettings *g = quux_setting;
while (g->gameid) {
games.push_back(*g);
g++;
}
return games;
}
DetectedGameList Engine_QUUX_detectGames(const FSList &fslist) {
DetectedGameList 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->displayName().c_str();
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;
}
Engine *Engine_QUUX_create(GameDetector *detector, OSystem *syst) {
// At this point you may want to perform a sanity check on the
// values in 'detecetor'.
return new Quux::QuuxEngine(syst);
}
REGISTER_PLUGIN(QUUX, "Quux the Example Module")
namespace Quux {
QuuxEngine::QuuxEngine(OSystem *syst)
: Engine(syst) {
// Put your engine in a sane state, but do nothing big yet;
// in particular, do not load data from files; rather, if you
// need to do such things, do them from init().
printf("QuuxEngine::QuuxEngine\n");
}
QuuxEngine::~QuuxEngine() {
// Dispose your resources here
printf("QuuxEngine::~QuuxEngine\n");
}
int QuuxEngine::init(GameDetector &detector) {
// Additional setup.
printf("QuuxEngine::init\n");
return 0;
}
int QuuxEngine::go() {
// Your main even loop should be (invoked from) here.
printf("QuuxEngine::go: Hello, World!\n");
return 0;
}
} // End of namespace Quux
</pre>




Line 46: Line 165:
include $(srcdir)/common.rules
include $(srcdir)/common.rules
</pre>
</pre>
=== Subclassing Engine ===
TODO: We should probably give some sample code, maybe even provide a full (empty) Engine demo class. Maybe even provide a real mini engine project somewhere on our site which demonstrates using events, drawing, etc. ? Not sure whether this would be worth the effort, though.
TODO: At the very least, describe the plugin interface: I.e. which functions *must* be implemented, and what they are supposed to do. Once again, sample code would be nice.
1,079

edits