[Scummvm-cvs-logs] SF.net SVN: scummvm: [25174] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jan 25 01:43:35 CET 2007


Revision: 25174
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25174&view=rev
Author:   fingolfin
Date:     2007-01-24 16:43:35 -0800 (Wed, 24 Jan 2007)

Log Message:
-----------
Removed class AdvancedDetector

Modified Paths:
--------------
    scummvm/trunk/common/advancedDetector.cpp
    scummvm/trunk/common/advancedDetector.h

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2007-01-25 00:38:36 UTC (rev 25173)
+++ scummvm/trunk/common/advancedDetector.cpp	2007-01-25 00:43:35 UTC (rev 25174)
@@ -33,6 +33,21 @@
 
 namespace Common {
 
+/**
+ * Detect games in specified directory.
+ * Parameters language and platform are used to pass on values
+ * specified by the user. I.e. this is used to restrict search scope.
+ *
+ * @param fslist	FSList to scan or NULL for scanning all specified
+ *  default directories.
+ * @param params	a ADParams struct containing various parameters
+ * @param language	restrict results to specified language only
+ * @param platform	restrict results to specified platform only
+ * @return	list of indexes to GameDescriptions of matched games
+ */
+static ADList detectGame(ADGameDescList gameDescriptions, const FSList *fslist, const Common::ADParams &params, Language language, Platform platform);
+
+
 PluginError ADVANCED_DETECTOR_ENGINE_CREATE(
 	GameList (*detectFunc)(const FSList &fslist),
 	const Common::ADParams &params
@@ -118,7 +133,6 @@
 	const Common::ADParams &params
 	) {
 	GameList detectedGames;
-	Common::AdvancedDetector ad;
 	Common::ADList matches;
 	Common::ADGameDescList descList;
 	const byte *descPtr;
@@ -126,11 +140,9 @@
 	for (descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize)
 		descList.push_back((const ADGameDescription *)descPtr);
 
-	ad.registerGameDescriptions(descList);
-
 	debug(3, "%s: cnt: %d", ((const ADGameDescription *)params.descs)->gameid,  descList.size());
 
-	matches = ad.detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown);
+	matches = detectGame(descList, &fslist, params, Common::UNK_LANG, Common::kPlatformUnknown);
 
 	for (uint i = 0; i < matches.size(); i++)
 		detectedGames.push_back(toGameDescriptor(*(const ADGameDescription *)(params.descs + matches[i] * params.descItemSize), params.list));
@@ -144,7 +156,6 @@
 	int gameNumber = -1;
 
 	GameList detectedGames;
-	Common::AdvancedDetector ad;
 	Common::ADList matches;
 	Common::ADGameDescList descList;
 	const byte *descPtr;
@@ -162,10 +173,8 @@
 	for (descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize)
 		descList.push_back((const ADGameDescription *)descPtr);
 
-	ad.registerGameDescriptions(descList);
+	matches = detectGame(descList, 0, params, language, platform);
 
-	matches = ad.detectGame(0, params, language, platform);
-
 	for (uint i = 0; i < matches.size(); i++) {
 		if (((const ADGameDescription *)(params.descs + matches[i] * params.descItemSize))->gameid == gameid) {
 			gameNumber = matches[i];
@@ -192,7 +201,7 @@
 	return String(tmp);
 }
 
-ADList AdvancedDetector::detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform) {
+static ADList detectGame(ADGameDescList gameDescriptions, const FSList *fslist, const Common::ADParams &params, Language language, Platform platform) {
 	typedef HashMap<String, bool, CaseSensitiveString_Hash, CaseSensitiveString_EqualTo> StringSet;
 	StringSet filesList;
 
@@ -211,12 +220,12 @@
 	bool fileMissing;
 	const ADGameFileDescription *fileDesc;
 
-	assert(_gameDescriptions.size());
+	assert(gameDescriptions.size());
 
 	// First we compose list of files which we need MD5s for
-	for (i = 0; i < _gameDescriptions.size(); i++) {
-		for (j = 0; _gameDescriptions[i]->filesDescriptions[j].fileName; j++) {
-			tstr = String(_gameDescriptions[i]->filesDescriptions[j].fileName);
+	for (i = 0; i < gameDescriptions.size(); i++) {
+		for (j = 0; gameDescriptions[i]->filesDescriptions[j].fileName; j++) {
+			tstr = String(gameDescriptions[i]->filesDescriptions[j].fileName);
 			tstr.toLowercase();
 			tstr2 = tstr + ".";
 			filesList[tstr] = true;
@@ -275,8 +284,8 @@
 	ADList matched;
 	int maxFilesMatched = 0;
 
-	for (i = 0; i < _gameDescriptions.size(); i++) {
-		const ADGameDescription *g = _gameDescriptions[i];
+	for (i = 0; i < gameDescriptions.size(); i++) {
+		const ADGameDescription *g = gameDescriptions[i];
 		fileMissing = false;
 
 		// Do not even bother to look at entries which do not have matching

Modified: scummvm/trunk/common/advancedDetector.h
===================================================================
--- scummvm/trunk/common/advancedDetector.h	2007-01-25 00:38:36 UTC (rev 25173)
+++ scummvm/trunk/common/advancedDetector.h	2007-01-25 00:43:35 UTC (rev 25174)
@@ -32,9 +32,9 @@
 
 struct ADGameFileDescription {
 	const char *fileName;
-	uint16 fileType;      // Optional. Not used in detection, only be engines
-	const char *md5;      // Optional could be NULL
-	const int32 fileSize; // Optional. Set to -1 to ignore
+	uint16 fileType;      // Optional. Not used during detection, only by engines.
+	const char *md5;      // Optional. May be NULL.
+	const int32 fileSize; // Optional. Set to -1 to ignore.
 };
 
 struct ADGameDescription {
@@ -70,43 +70,7 @@
 #define AD_ENTRY1(f, x) {{ f, 0, x, -1}, {NULL, 0, NULL, 0}}
 
 
-// TODO/FIXME: Fingolfin asks: Why is AdvancedDetector a class, considering that
-// it is only used as follow:
-//  1) Create an instance of it on the stack
-//  2) invoke registerGameDescriptions and setFileMD5Bytes 
-//  3) invoke detectGame *once*
-// Obviously, 2) could also be handled by passing more params to detectGame.
-// So it seem we could replace this class by a simple advancedDetectGame(...)
-// function, w/o a class or instantiating object... ? Or is there a deeper
-// reason I miss?
-class AdvancedDetector {
-public:
-
-	void registerGameDescriptions(ADGameDescList gameDescriptions) {
-		_gameDescriptions = gameDescriptions;
-	}
-
-	/**
-	 * Detect games in specified directory.
-	 * Parameters language and platform are used to pass on values
-	 * specified by the user. I.e. this is used to restrict search scope.
-	 *
-	 * @param fslist	FSList to scan or NULL for scanning all specified
-	 *  default directories.
-	 * @param params	a ADParams struct containing various parameters
-	 * @param language	restrict results to specified language only
-	 * @param platform	restrict results to specified platform only
-	 * @return	list of indexes to GameDescriptions of matched games
-	 */
-	ADList detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform);
-
-private:
-	ADGameDescList _gameDescriptions;
-};
-
-
 // FIXME/TODO: Rename this function to something more sensible.
-// Possibly move it inside class AdvancedDetector ?
 GameDescriptor ADVANCED_DETECTOR_FIND_GAMEID(
 	const char *gameid,
 	const Common::ADParams &params
@@ -114,7 +78,6 @@
 
 
 // FIXME/TODO: Rename this function to something more sensible.
-// Possibly move it inside class AdvancedDetector ?
 GameList ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
 	const FSList &fslist,
 	const Common::ADParams &params
@@ -122,13 +85,11 @@
 
 
 // FIXME/TODO: Rename this function to something more sensible.
-// Possibly move it inside class AdvancedDetector ?
 int ADVANCED_DETECTOR_DETECT_INIT_GAME(
 	const Common::ADParams &params
 	);
 
 // FIXME/TODO: Rename this function to something more sensible.
-// Possibly move it inside class AdvancedDetector ?
 PluginError ADVANCED_DETECTOR_ENGINE_CREATE(
 	GameList (*detectFunc)(const FSList &fslist),
 	const Common::ADParams &params


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list