Open main menu

Difference between revisions of "HOWTO-Engines"

437 bytes added ,  14:28, 4 December 2020
Update to reflect the recent MetaEngine changes
(Fix compiler errors)
(Update to reflect the recent MetaEngine changes)
Line 58: Line 58:
=== Subclassing AdvancedMetaEngine ===
=== Subclassing AdvancedMetaEngine ===
Let's implement the plugin interface:<br>
Let's implement the plugin interface:<br>
You'll have to create a custom AdvancedMetaEngine subclass. This provides the information and functionality related to the engine that can be used by the launcher without loading and running the game engine, which includes detecting games, listing savegames and instancing the engine.
You'll have to create a custom AdvancedMetaEngine subclass. This provides the information and functionality related to the engine that can be used by the launcher without loading and running the game engine, which includes defining keymaps and achievements, listing savegames, and instancing the engine. You'll also have to create a custom AdvancedMetaEngineDetection subclass. This provides the information related to detecting games, which is always included in the main ScummVM executable regardless of whether or not the engine is enabled.


The following example illustrates this. It contains the necessary fundamentals of the details of the games and the code to create the engine, as well as REGISTER macros that register the meta engine with ScummVM. For the Quux example, If you create an empty file named quux.txt, the engine will detect it.
The following example illustrates this. It contains the necessary fundamentals of the details of the games and the code to create the engine, as well as REGISTER macros that register the meta engine with ScummVM. For the Quux example, If you create an empty file named quux.txt, the engine will detect it.
Line 293: Line 293:
</syntaxhighlight>
</syntaxhighlight>


=== Example: engines/quux/detection.h ===
=== Example: engines/quux/detection.cpp ===
The following example implements a custom meta engine
<syntaxhighlight lang="cpp">
#include "base/plugins.h"
#include "engines/advancedDetector.h"
 
namespace Quux {
static const PlainGameDescriptor quuxGames[] = {
{ "quux", "Quux the Example Module" },
{ "quuxcd", "Quux the Example Module (CD version)" },
{ 0, 0 }
};


<syntaxhighlight lang="cpp">
#ifndef QUUX_DETECTION_H
#define QUUX_DETECTION_H


#include "engines/advancedDetector.h"
static const ADGameDescription gameDescriptions[] = {
{
"quux",
0,
AD_ENTRY1s("quux.txt", 0, 0),
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO1(GUIO_NOMIDI)
},
AD_TABLE_END_MARKER
};
} // End of namespace Quux


class QuuxMetaEngine : public AdvancedMetaEngine {
class QuuxMetaEngineDetection : public AdvancedMetaEngineDetection {
public:
public:
QuuxMetaEngine();
QuuxMetaEngineDetection() : AdvancedMetaEngineDetection(Quux::gameDescriptions, sizeof(ADGameDescription), Quux::quuxGames) {
}


const char *getEngineId() const override {
const char *getEngineId() const override {
Line 317: Line 336:
return "Copyright (C) Quux Entertainment Ltd.";
return "Copyright (C) Quux Entertainment Ltd.";
}
}
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
};
};


#endif
REGISTER_PLUGIN_STATIC(QUUX_DETECTION, PLUGIN_TYPE_ENGINE_DETECTION, QuuxMetaEngineDetection);
</syntaxhighlight>
</syntaxhighlight>


=== Example: engines/quux/detection.cpp ===
=== Example: engines/quux/metaengine.cpp ===
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
#include "quux/detection.h"
#include "quux/quux.h"
#include "quux/quux.h"
#include "engines/game.h"
#include "engines/advancedDetector.h"


namespace Quux {
class QuuxMetaEngine : public AdvancedMetaEngine {
static const PlainGameDescriptor quuxGames[] = {
public:
{ "quux", "Quux the Example Module" },
const char *getName() const override {
{ "quuxcd", "Quux the Example Module (CD version)" },
return "quux";
{ 0, 0 }
}
};


 
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
static const ADGameDescription gameDescriptions[] = {
{
"quux",
0,
AD_ENTRY1s("quux.txt", 0, 0),
Common::EN_ANY,
Common::kPlatformDOS,
ADGF_NO_FLAGS,
GUIO1(GUIO_NOMIDI)
},
AD_TABLE_END_MARKER
};
};
} // End of namespace Quux
QuuxMetaEngine::QuuxMetaEngine() : AdvancedMetaEngine(
Quux::gameDescriptions, sizeof(ADGameDescription), Quux::quuxGames) {
}


bool QuuxMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
bool QuuxMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
Line 373: Line 372:
   
   
MODULE_OBJS := \
MODULE_OBJS := \
detection.o \
metaengine.o \
quux.o
quux.o
   
   
Line 386: Line 385:
# Include common rules  
# Include common rules  
include $(srcdir)/rules.mk
include $(srcdir)/rules.mk
# Detection objects
DETECT_OBJS += $(MODULE)/detection.o
</syntaxhighlight>
</syntaxhighlight>


271

edits