[Scummvm-cvs-logs] CVS: scummvm/base gameDetector.cpp,1.31,1.32 gameDetector.h,1.11,1.12 plugins.h,1.9,1.10 plugins.cpp,1.13,1.14

Max Horn fingolfin at users.sourceforge.net
Fri Oct 17 05:20:03 CEST 2003


Update of /cvsroot/scummvm/scummvm/base
In directory sc8-pr-cvs1:/tmp/cvs-serv22464/base

Modified Files:
	gameDetector.cpp gameDetector.h plugins.h plugins.cpp 
Log Message:
factored out the game detection code into the Plugin class; this is the first step towards allowing more powerful, plugin specific detection code; also, moved the Plugin GameSettings APIs to a slightly higher level

Index: gameDetector.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/gameDetector.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- gameDetector.cpp	16 Oct 2003 23:16:15 -0000	1.31
+++ gameDetector.cpp	17 Oct 2003 12:18:58 -0000	1.32
@@ -240,41 +240,39 @@
 	// 2) List all available (configured) targets, including those with custom
 	//    names, e.g. "monkey-mac", "skycd-demo", ...
 	const PluginList &plugins = PluginManager::instance().getPlugins();
-	const GameSettings *v;
 
 	printf("Game             Full Title                                            \n"
 	       "---------------- ------------------------------------------------------\n");
 
 	PluginList::ConstIterator iter = plugins.begin();
 	for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
-		v = (*iter)->getSupportedGames();
-		while (v->gameName && v->description) {
+		GameList list = (*iter)->getSupportedGames();
+		for (GameList::Iterator v = list.begin(); v != list.end(); ++v) {
 #if 1
 			printf("%-17s%-56s\n", v->gameName, v->description);
 #else
 			const char *config = (g_config->has_domain(v->gameName)) ? "Yes" : "";
 			printf("%-17s%-56s%s\n", v->gameName, v->description, config);
 #endif
-			v++;
 		}
 	}
 }
 
-const GameSettings *GameDetector::findGame(const String &gameName, const Plugin **plugin) const {
+GameSettings GameDetector::findGame(const String &gameName, const Plugin **plugin) {
 	// Find the GameSettings for this target
-	const GameSettings *target;
 	const PluginList &plugins = PluginManager::instance().getPlugins();
+	GameSettings result = {NULL, NULL, 0, 0, MDT_NONE, 0, NULL};
 	
 	PluginList::ConstIterator iter = plugins.begin();
 	for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
-		target = (*iter)->findGame(gameName.c_str());
-		if (target) {
+		result = (*iter)->findGame(gameName.c_str());
+		if (result.gameName) {
 			if (plugin)
 				*plugin = *iter;
-			return target;
+			break;
 		}
 	}
-	return 0;
+	return result;
 }
 
 void GameDetector::parseCommandLine(int argc, char **argv) {
@@ -454,7 +452,7 @@
 			// To verify this, check if there is either a game domain (i.e
 			// a configured target) matching this argument, or if we can
 			// find any target with that name.
-			if (i == (argc - 1) && (ConfMan.hasGameDomain(s) || findGame(s))) {
+			if (i == (argc - 1) && (ConfMan.hasGameDomain(s) || findGame(s).gameName)) {
 				setTarget(s);
 			} else {
 				if (current_option == NULL)
@@ -543,7 +541,6 @@
 }
 
 bool GameDetector::detectGame() {
-	const GameSettings *target;
 	String realGame;
 
 	if (ConfMan.hasKey("gameid"))
@@ -552,10 +549,9 @@
 		realGame = _targetName;
 	printf("Looking for %s\n", realGame.c_str());
 	
-	target = findGame(realGame, &_plugin);
+	_game = findGame(realGame, &_plugin);
 	
-	if (target) {
-		_game = *target;
+	if (_game.gameName) {
 		printf("Trying to start game '%s'\n", _game.description);
 		return true;
 	} else {

Index: gameDetector.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/gameDetector.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- gameDetector.h	15 Oct 2003 23:16:52 -0000	1.11
+++ gameDetector.h	17 Oct 2003 12:18:58 -0000	1.12
@@ -23,6 +23,7 @@
 #ifndef GAMEDETECTOR_H
 #define GAMEDETECTOR_H
 
+#include "base/plugins.h"
 #include "common/str.h"
 
 class Engine;
@@ -117,7 +118,7 @@
 	static Language parseLanguage(const String &s);
 	static Platform parsePlatform(const String &s);
 	
-	const GameSettings *findGame(const String &gameName, const Plugin **plugin = NULL) const;
+	static GameSettings findGame(const String &gameName, const Plugin **plugin = NULL);
 
 protected:
 	bool detectGame(void);

Index: plugins.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/plugins.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- plugins.h	16 Oct 2003 23:16:15 -0000	1.9
+++ plugins.h	17 Oct 2003 12:18:58 -0000	1.10
@@ -27,16 +27,19 @@
 #include "common/singleton.h"
 
 class Engine;
+class FSList;
 class GameDetector;
 class OSystem;
 struct GameSettings;
 
+/** List of GameSettings- */
+typedef Common::List<GameSettings> GameList;
+
 /**
  * Abstract base class for the plugin system.
  * Subclasses for this can be used to wrap both static and dynamic
  * plugins.
  */
-//typedef Common::List<GameSettings> GameList;
 class Plugin {
 public:
 	virtual ~Plugin()				{}
@@ -47,10 +50,9 @@
 	virtual const char *getName() const = 0;
 	virtual int getVersion() const	{ return 0; }	// TODO!
 	
-	virtual int countSupportedGames() const;
-	virtual const GameSettings *getSupportedGames() const = 0;
-	virtual const GameSettings *findGame(const char *gameName) const;
-	//virtual GameList detectGames(const FSList &fslist) const;
+	virtual GameList getSupportedGames() const = 0;
+	virtual GameSettings findGame(const char *gameName) const;
+	virtual GameList detectGames(const FSList &fslist) const = 0;
 
 	virtual Engine *createInstance(GameDetector *detector, OSystem *syst) const = 0;
 };

Index: plugins.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/plugins.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- plugins.cpp	16 Oct 2003 23:16:15 -0000	1.13
+++ plugins.cpp	17 Oct 2003 12:18:58 -0000	1.14
@@ -20,12 +20,13 @@
  *
  */
 
+#include "backends/fs/fs.h"
 #include "base/gameDetector.h"
 #include "base/plugins.h"
 #include "base/engine.h"
 #include "common/util.h"
 
-
+/** Type of factory functions which make new Engine objects. */
 typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
 
 
@@ -74,47 +75,95 @@
 #pragma mark -
 
 
-int Plugin::countSupportedGames() const {
-	const GameSettings *target = getSupportedGames();
-	int count;
-	for (count = 0; target->gameName; target++, count++)
-		;
-	return count;
-}
-
-const GameSettings *Plugin::findGame(const char *gameName) const {
-	// Find the GameSettings for this target
-	const GameSettings *target = getSupportedGames();
+GameSettings Plugin::findGame(const char *gameName) const {
+	// Find the GameSettings for this game
 	assert(gameName);
-	while (target->gameName) {
-		if (!scumm_stricmp(target->gameName, gameName)) {
-			return target;
+	GameList games = getSupportedGames();
+	GameSettings result = {NULL, NULL, 0, 0, MDT_NONE, 0, NULL};
+	for (GameList::Iterator g = games.begin(); g != games.end(); ++g) {
+		if (!scumm_stricmp(g->gameName, gameName)) {
+			result = *g;
+			break;
 		}
-		target++;
 	}
-	return 0;
+	return result;
 }
 
+/**
+ * Auxillary class to simplify transition from old plugin interface to the
+ * new one (which provides an API for game detection). To be removed once
+ * the transition is complete.
+ */
+class GameSettingsPlugin : public Plugin {
+	const GameSettings *_games;
+public:
+	GameSettingsPlugin(const GameSettings *games) : _games(games) { }
+	GameList getSupportedGames() const {
+		GameList games;
+		const GameSettings *g;
+		for (g = _games; g->gameName; ++g) {
+			games.push_back(*g);
+		}
+		return games;
+	}
+	GameList detectGames(const FSList &fslist) const {
+		GameList games;
+		const GameSettings *g;
+		char detectName[128];
+		char detectName2[128];
+		char detectName3[128];
+	
+		for (g = _games; g->gameName; ++g) {
+			// Determine the 'detectname' for this game, that is, the name of a 
+			// file that *must* be presented if the directory contains the data
+			// for this game. For example, FOA requires atlantis.000
+			if (g->detectname) {
+				strcpy(detectName, g->detectname);
+				strcpy(detectName2, g->detectname);
+				strcat(detectName2, ".");
+				detectName3[0] = '\0';
+			} else {
+				strcpy(detectName, g->gameName);
+				strcpy(detectName2, g->gameName);
+				strcpy(detectName3, g->gameName);
+				strcat(detectName, ".000");
+				if (g->version >= 7) {
+					strcat(detectName2, ".la0");
+				} else
+					strcat(detectName2, ".sm0");
+				strcat(detectName3, ".he0");
+			}
+	
+			// Iterate over all files in the given directory
+			for (FSList::ConstIterator file = fslist.begin(); file != fslist.end(); ++file) {
+				const char *gameName = file->displayName().c_str();
+	
+				if ((0 == scumm_stricmp(detectName, gameName))  || 
+					(0 == scumm_stricmp(detectName2, gameName)) ||
+					(0 == scumm_stricmp(detectName3, gameName))) {
+					// Match found, add to list of candidates, then abort inner loop.
+					games.push_back(*g);
+					break;
+				}
+			}
+		}
+		return games;
+	}
+};
 
 #pragma mark -
 
 
-class StaticPlugin : public Plugin {
+class StaticPlugin : public GameSettingsPlugin {
 	const char *_name;
-	const GameSettings *_targets;
-	int _targetCount;
 	EngineFactory _ef;
 public:
-	StaticPlugin(const char *name, const GameSettings *targets, EngineFactory ef)
-		: _name(name), _targets(targets), _ef(ef) {
-		_targetCount = Plugin::countSupportedGames();
+	StaticPlugin(const char *name, const GameSettings *games, EngineFactory ef)
+		: GameSettingsPlugin(games), _name(name), _ef(ef) {
 	}
 
 	const char *getName() const					{ return _name; }
 
-	int countSupportedGames() const					{ return _targetCount; }
-	const GameSettings *getSupportedGames() const	{ return _targets; }
-
 	Engine *createInstance(GameDetector *detector, OSystem *syst) const {
 		return (*_ef)(detector, syst);
 	}
@@ -126,26 +175,21 @@
 
 #ifdef DYNAMIC_MODULES
 
-class DynamicPlugin : public Plugin {
+class DynamicPlugin : public GameSettingsPlugin {
 	void *_dlHandle;
 	Common::String _filename;
 
 	Common::String _name;
-	const GameSettings *_targets;
-	int _targetCount;
 	EngineFactory _ef;
 	
 	void *findSymbol(const char *symbol);
 
 public:
 	DynamicPlugin(const char *filename)
-		: _dlHandle(0), _filename(filename), _targets(0), _targetCount(0), _ef(0) {}
+		: GameSettingsPlugin(0), _dlHandle(0), _filename(filename), _ef(0) {}
 	
 	const char *getName() const					{ return _name.c_str(); }
 
-	int countSupportedGames() const					{ return _targetCount; }
-	const GameSettings *getSupportedGames() const	{ return _targets; }
-
 	Engine *createInstance(GameDetector *detector, OSystem *syst) const {
 		assert(_ef);
 		return (*_ef)(detector, syst);
@@ -199,7 +243,7 @@
 		unloadPlugin();
 		return false;
 	}
-	_targets = targetListFunc();
+	_games = targetListFunc();
 	
 	// Finally, retrieve the factory function
 	_ef = (EngineFactory)findSymbol("PLUGIN_createEngine");





More information about the Scummvm-git-logs mailing list