Skip to content

Commit 8ac1743

Browse files
committed
- renamed PLUGIN_getSupportedGames to PLUGIN_gameIDList for consistency
- renamed Engine_XXX_gameList to Engine_XXX_gameList for consistency - added new Engine_XXX_findGameID / PLUGIN_findGameID function - updated plugins code to take advantage of the new plugin API, to support obsolete gameids w/o showing them to the user svn-id: r20752
1 parent d0e637f commit 8ac1743

File tree

13 files changed

+207
-93
lines changed

13 files changed

+207
-93
lines changed

base/plugins.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
3333

3434
typedef const char *(*NameFunc)();
35+
typedef GameSettings (*GameIDQueryFunc)(const char *gameid);
3536
typedef GameList (*GameIDListFunc)();
3637
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
3738

@@ -60,30 +61,14 @@ typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
6061

6162
#else
6263

63-
PluginRegistrator::PluginRegistrator(const char *name, GameList games, EngineFactory ef, DetectFunc df)
64-
: _name(name), _ef(ef), _df(df), _games(games) {
64+
PluginRegistrator::PluginRegistrator(const char *name, GameList games, GameIDQueryFunc qf, EngineFactory ef, DetectFunc df)
65+
: _name(name), _qf(qf), _ef(ef), _df(df), _games(games) {
6566
//printf("Automatically registered plugin '%s'\n", name);
6667
}
6768

6869
#endif
6970

7071

71-
#pragma mark -
72-
73-
GameSettings Plugin::findGame(const char *gameName) const {
74-
// Find the GameSettings for this game
75-
assert(gameName);
76-
GameList games = getSupportedGames();
77-
GameSettings result = {NULL, NULL};
78-
for (GameList::iterator g = games.begin(); g != games.end(); ++g) {
79-
if (!scumm_stricmp(g->gameid, gameName)) {
80-
result = *g;
81-
break;
82-
}
83-
}
84-
return result;
85-
}
86-
8772
#pragma mark -
8873

8974
#ifndef DYNAMIC_MODULES
@@ -92,6 +77,7 @@ class StaticPlugin : public Plugin {
9277
public:
9378
StaticPlugin(PluginRegistrator *plugin)
9479
: _plugin(plugin) {
80+
assert(_plugin);
9581
}
9682

9783
~StaticPlugin() {
@@ -101,11 +87,19 @@ class StaticPlugin : public Plugin {
10187
const char *getName() const { return _plugin->_name; }
10288

10389
Engine *createInstance(GameDetector *detector, OSystem *syst) const {
90+
assert(_plugin->_ef);
10491
return (*_plugin->_ef)(detector, syst);
10592
}
10693

10794
GameList getSupportedGames() const { return _plugin->_games; }
95+
96+
GameSettings findGame(const char *gameid) const {
97+
assert(_plugin->_qf);
98+
return (*_plugin->_qf)(gameid);
99+
}
100+
108101
DetectedGameList detectGames(const FSList &fslist) const {
102+
assert(_plugin->_df);
109103
return (*_plugin->_df)(fslist);
110104
}
111105
};
@@ -120,6 +114,7 @@ class DynamicPlugin : public Plugin {
120114
Common::String _filename;
121115

122116
Common::String _name;
117+
GameIDQueryFunc _qf;
123118
EngineFactory _ef;
124119
DetectFunc _df;
125120
GameList _games;
@@ -128,7 +123,7 @@ class DynamicPlugin : public Plugin {
128123

129124
public:
130125
DynamicPlugin(const Common::String &filename)
131-
: _dlHandle(0), _filename(filename), _ef(0), _df(0), _games() {}
126+
: _dlHandle(0), _filename(filename), _qf(0), _ef(0), _df(0), _games() {}
132127

133128
const char *getName() const { return _name.c_str(); }
134129

@@ -138,6 +133,12 @@ class DynamicPlugin : public Plugin {
138133
}
139134

140135
GameList getSupportedGames() const { return _games; }
136+
137+
GameSettings findGame(const char *gameid) const {
138+
assert(_qf);
139+
return (*_qf)(gameid);
140+
}
141+
141142
DetectedGameList detectGames(const FSList &fslist) const {
142143
assert(_df);
143144
return (*_df)(fslist);
@@ -196,13 +197,20 @@ bool DynamicPlugin::loadPlugin() {
196197
_name = nameFunc();
197198

198199
// Query the plugin for the game ids it supports
199-
GameIDListFunc gameListFunc = (GameIDListFunc)findSymbol("PLUGIN_getSupportedGames");
200+
GameIDListFunc gameListFunc = (GameIDListFunc)findSymbol("PLUGIN_gameIDList");
200201
if (!gameListFunc) {
201202
unloadPlugin();
202203
return false;
203204
}
204205
_games = gameListFunc();
205206

207+
// Retrieve the gameid query function
208+
_qf = (GameIDQueryFunc)findSymbol("PLUGIN_findGameID");
209+
if (!_qf) {
210+
unloadPlugin();
211+
return false;
212+
}
213+
206214
// Retrieve the factory function
207215
_ef = (EngineFactory)findSymbol("PLUGIN_createEngine");
208216
if (!_ef) {
@@ -225,23 +233,18 @@ bool DynamicPlugin::loadPlugin() {
225233
}
226234

227235
void DynamicPlugin::unloadPlugin() {
228-
#if defined(UNIX) || defined(__DC__)
229236
if (_dlHandle) {
237+
#if defined(UNIX) || defined(__DC__)
230238
if (dlclose(_dlHandle) != 0)
231239
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
232-
}
233-
}
234-
#else
235-
#if defined(_WIN32)
236-
if (_dlHandle) {
240+
#elif defined(_WIN32)
237241
if (!FreeLibrary((HMODULE)_dlHandle))
238242
warning("Failed unloading plugin '%s'", _filename.c_str());
239-
}
240-
}
241243
#else
242244
#error TODO
243245
#endif
244-
#endif
246+
}
247+
}
245248

246249
#endif // DYNAMIC_MODULES
247250

base/plugins.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ typedef Common::Array<GameSettings> GameList;
4141
* A detected game. Carries the GameSettings, but also (optionally)
4242
* information about the language and platform of the detected game.
4343
*/
44-
struct DetectedGame : GameSettings {
44+
struct DetectedGame {
45+
const char *gameid;
46+
const char *description;
4547
Common::Language language;
4648
Common::Platform platform;
4749
DetectedGame() : language(Common::UNK_LANG), platform(Common::kPlatformUnknown) {}
4850
DetectedGame(const GameSettings &game,
4951
Common::Language l = Common::UNK_LANG,
5052
Common::Platform p = Common::kPlatformUnknown)
51-
: GameSettings(game), language(l), platform(p) {}
53+
: gameid(game.gameid), description(game.description), language(l), platform(p) {}
5254
};
5355

5456
/** List of detected games. */
@@ -71,7 +73,7 @@ class Plugin {
7173
virtual int getVersion() const { return 0; } // TODO!
7274

7375
virtual GameList getSupportedGames() const = 0;
74-
virtual GameSettings findGame(const char *gameName) const;
76+
virtual GameSettings findGame(const char *gameid) const = 0;
7577
virtual DetectedGameList detectGames(const FSList &fslist) const = 0;
7678

7779
virtual Engine *createInstance(GameDetector *detector, OSystem *syst) const = 0;
@@ -84,20 +86,41 @@ class Plugin {
8486
* makes it possible to compile the very same code in a module
8587
* both as a static and a dynamic plugin.
8688
*
89+
* Each plugin has to define the following functions:
90+
* - GameList Engine_##ID##_gameIDList()
91+
* -> returns a list of gameid/desc pairs. Only used to implement '--list-games'.
92+
* - GameSettings Engine_##ID##_findGameID(const char *gameid)
93+
* -> asks the Engine for a GameSettings matching the gameid. If that is not
94+
* possible, the engine MUST set the gameid of the returned value to 0.
95+
* Note: This MUST succeed for every gameID on the list returned by
96+
* gameIDList(), but MAY also work for additional gameids (e.g. to support
97+
* obsolete targets).
98+
* - DetectedGameList Engine_##ID##_detectGames(const FSList &fslist)
99+
* -> scans through the given file list (usually the contents of a directory),
100+
* and attempts to detects games present in that location.
101+
* - Engine *Engine_##ID##_create(GameDetector *detector, OSystem *syst)
102+
* -> factory function, create an instance of the Engine class.
103+
*
87104
* @todo add some means to query the plugin API version etc.
88105
*/
89106

90107
#ifndef DYNAMIC_MODULES
91108
#define REGISTER_PLUGIN(ID,name) \
92109
PluginRegistrator *g_##ID##_PluginReg; \
93110
void g_##ID##_PluginReg_alloc() { \
94-
g_##ID##_PluginReg = new PluginRegistrator(name, Engine_##ID##_gameList(), Engine_##ID##_create, Engine_##ID##_detectGames);\
111+
g_##ID##_PluginReg = new PluginRegistrator(name, \
112+
Engine_##ID##_gameIDList(), \
113+
Engine_##ID##_findGameID, \
114+
Engine_##ID##_create, \
115+
Engine_##ID##_detectGames \
116+
);\
95117
}
96118
#else
97119
#define REGISTER_PLUGIN(ID,name) \
98120
extern "C" { \
99121
PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \
100-
PLUGIN_EXPORT GameList PLUGIN_getSupportedGames() { return Engine_##ID##_gameList(); } \
122+
PLUGIN_EXPORT GameList PLUGIN_gameIDList() { return Engine_##ID##_gameIDList(); } \
123+
PLUGIN_EXPORT GameSettings PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \
101124
PLUGIN_EXPORT Engine *PLUGIN_createEngine(GameDetector *detector, OSystem *syst) { return Engine_##ID##_create(detector, syst); } \
102125
PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
103126
}
@@ -111,17 +134,19 @@ class Plugin {
111134
class PluginRegistrator {
112135
friend class StaticPlugin;
113136
public:
137+
typedef GameSettings (*GameIDQueryFunc)(const char *gameid);
114138
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
115139
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
116140

117141
protected:
118142
const char *_name;
143+
GameIDQueryFunc _qf;
119144
EngineFactory _ef;
120145
DetectFunc _df;
121146
GameList _games;
122147

123148
public:
124-
PluginRegistrator(const char *name, GameList games, EngineFactory ef, DetectFunc df);
149+
PluginRegistrator(const char *name, GameList games, GameIDQueryFunc qf, EngineFactory ef, DetectFunc df);
125150
};
126151
#endif
127152

engines/gob/gob.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ int GobEngine::init(GameDetector &detector) {
266266

267267
using namespace Gob;
268268

269-
GameList Engine_GOB_gameList() {
269+
GameList Engine_GOB_gameIDList() {
270270
GameList games;
271271
const GameSettings *g = gob_list;
272272

@@ -278,6 +278,16 @@ GameList Engine_GOB_gameList() {
278278
return games;
279279
}
280280

281+
GameSettings Engine_GOB_findGameID(const char *gameid) {
282+
const GameSettings *g = gob_list;
283+
while (g->gameid) {
284+
if (0 == strcmp(gameid, g->gameid))
285+
break;
286+
g++;
287+
}
288+
return *g;
289+
}
290+
281291
DetectedGameList Engine_GOB_detectGames(const FSList &fslist) {
282292
DetectedGameList detectedGames;
283293
const GobGameSettings *g;

engines/kyra/kyra.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static Common::Language convertKyraLang(uint32 features) {
129129
return Common::UNK_LANG;
130130
}
131131

132-
GameList Engine_KYRA_gameList() {
132+
GameList Engine_KYRA_gameIDList() {
133133
GameList games;
134134
const GameSettings *g = kyra_list;
135135

@@ -140,6 +140,16 @@ GameList Engine_KYRA_gameList() {
140140
return games;
141141
}
142142

143+
GameSettings Engine_KYRA_findGameID(const char *gameid) {
144+
const GameSettings *g = kyra_list;
145+
while (g->gameid) {
146+
if (0 == strcmp(gameid, g->gameid))
147+
break;
148+
g++;
149+
}
150+
return *g;
151+
}
152+
143153
DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) {
144154
DetectedGameList detectedGames;
145155
const KyraGameSettings *g;

engines/lure/lure.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const GameSettings lure_list[] = {
7373
{ 0, 0 }
7474
};
7575

76-
GameList Engine_LURE_gameList() {
76+
GameList Engine_LURE_gameIDList() {
7777
GameList games;
7878
const GameSettings *g = lure_list;
7979

@@ -84,6 +84,16 @@ GameList Engine_LURE_gameList() {
8484
return games;
8585
}
8686

87+
GameSettings Engine_LURE_findGameID(const char *gameid) {
88+
const GameSettings *g = lure_list;
89+
while (g->gameid) {
90+
if (0 == strcmp(gameid, g->gameid))
91+
break;
92+
g++;
93+
}
94+
return *g;
95+
}
96+
8797
DetectedGameList Engine_LURE_detectGames(const FSList &fslist) {
8898
DetectedGameList detectedGames;
8999
const LureGameSettings *g;

engines/queen/queen.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,20 @@ static const GameSettings queen_setting[] = {
6262
{ 0, 0 }
6363
};
6464

65-
GameList Engine_QUEEN_gameList() {
65+
GameList Engine_QUEEN_gameIDList() {
6666
GameList games;
67-
const GameSettings *g = queen_setting;
68-
69-
while (g->gameid) {
70-
games.push_back(*g);
71-
g++;
72-
}
67+
games.push_back(queen_setting[0]);
7368
return games;
7469
}
7570

71+
GameSettings Engine_QUEEN_findGameID(const char *gameid) {
72+
if (0 == strcmp(gameid, queen_setting[0].gameid))
73+
return queen_setting[0];
74+
GameSettings dummy = { 0, 0 };
75+
return dummy;
76+
}
77+
78+
7679
GameSettings determineTarget(uint32 size) {
7780
switch (size) {
7881
case 3724538: //regular demo

engines/saga/saga.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const GameSettings saga_games[] = {
6262
{0, 0}
6363
};
6464

65-
GameList Engine_SAGA_gameList() {
65+
GameList Engine_SAGA_gameIDList() {
6666
GameList games;
6767
const GameSettings *g = saga_games;
6868

@@ -74,6 +74,16 @@ GameList Engine_SAGA_gameList() {
7474
return games;
7575
}
7676

77+
GameSettings Engine_SAGA_findGameID(const char *gameid) {
78+
const GameSettings *g = saga_games;
79+
while (g->gameid) {
80+
if (0 == strcmp(gameid, g->gameid))
81+
break;
82+
g++;
83+
}
84+
return *g;
85+
}
86+
7787
DetectedGameList Engine_SAGA_detectGames(const FSList &fslist) {
7888
return Saga::GAME_ProbeGame(fslist);
7989
}

0 commit comments

Comments
 (0)