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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Dec 19 23:43:28 CET 2006


Revision: 24893
          http://scummvm.svn.sourceforge.net/scummvm/?rev=24893&view=rev
Author:   fingolfin
Date:     2006-12-19 14:43:15 -0800 (Tue, 19 Dec 2006)

Log Message:
-----------
* Change the GameList typedef to a proper class with an additional
  constructor which takes a PlainGameDescriptor 'list'
* Replaced real_ADVANCED_DETECTOR_GAMEID_LIST by this new constructor
* Removed ADVANCED_DETECTOR_GAMEID_LIST and ADVANCED_DETECTOR_FIND_GAMEID
* Some minor cleanup

Modified Paths:
--------------
    scummvm/trunk/base/game.h
    scummvm/trunk/common/advancedDetector.cpp
    scummvm/trunk/common/advancedDetector.h
    scummvm/trunk/engines/kyra/plugin.cpp

Modified: scummvm/trunk/base/game.h
===================================================================
--- scummvm/trunk/base/game.h	2006-12-19 21:52:29 UTC (rev 24892)
+++ scummvm/trunk/base/game.h	2006-12-19 22:43:15 UTC (rev 24893)
@@ -55,7 +55,17 @@
 };
 
 /** List of games. */
-typedef Common::Array<GameDescriptor> GameList;
+class GameList : public Common::Array<GameDescriptor> {
+public:
+	GameList() {}
+	GameList(const GameList &list) : Common::Array<GameDescriptor>(list) {}
+	GameList(const PlainGameDescriptor *g) {
+		while (g->gameid) {
+			push_back(*g);
+			g++;
+		}
+	}
+};
 
 
 

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2006-12-19 21:52:29 UTC (rev 24892)
+++ scummvm/trunk/common/advancedDetector.cpp	2006-12-19 22:43:15 UTC (rev 24893)
@@ -72,16 +72,6 @@
 	return kNoGameDataFoundError;
 }
 
-GameList real_ADVANCED_DETECTOR_GAMEID_LIST(const PlainGameDescriptor *list) {
-	GameList games;
-	const PlainGameDescriptor *g = list;
-	while (g->gameid) {
-		games.push_back(*g);
-		g++;
-	}
-	return games;
-}
-
 GameDescriptor real_ADVANCED_DETECTOR_FIND_GAMEID(
 	const char *gameid,
 	const PlainGameDescriptor *list,
@@ -110,7 +100,7 @@
 	return gs;
 }
 
-DetectedGame toDetectedGame(const ADGameDescription &g, const PlainGameDescriptor *sg) {
+static DetectedGame toDetectedGame(const ADGameDescription &g, const PlainGameDescriptor *sg) {
 	const char *title = 0;
 
 	while (sg->gameid) {
@@ -132,7 +122,7 @@
 	const PlainGameDescriptor *list
 	) {
 	DetectedGameList detectedGames;
-	Common::AdvancedDetector AdvDetector;
+	Common::AdvancedDetector ad;
 	Common::ADList matches;
 	Common::ADGameDescList descList;
 	const byte *descPtr;
@@ -140,12 +130,12 @@
 	for (descPtr = descs; *descPtr != 0; descPtr += descItemSize)
 		descList.push_back((const ADGameDescription *)descPtr);
 
-	AdvDetector.registerGameDescriptions(descList);
-	AdvDetector.setFileMD5Bytes(md5Bytes);
+	ad.registerGameDescriptions(descList);
+	ad.setFileMD5Bytes(md5Bytes);
 
 	debug(3, "%s: cnt: %d", ((const ADGameDescription *)descs)->name,  descList.size());
 
-	matches = AdvDetector.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown);
+	matches = ad.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown);
 
 	for (uint i = 0; i < matches.size(); i++)
 		detectedGames.push_back(toDetectedGame(*(const ADGameDescription *)(descs + matches[i] * descItemSize), list));
@@ -162,7 +152,7 @@
 	int gameNumber = -1;
 
 	DetectedGameList detectedGames;
-	Common::AdvancedDetector AdvDetector;
+	Common::AdvancedDetector ad;
 	Common::ADList matches;
 	Common::ADGameDescList descList;
 	const byte *descPtr;
@@ -180,10 +170,10 @@
 	for (descPtr = descs; *descPtr != 0; descPtr += descItemSize)
 		descList.push_back((const ADGameDescription *)descPtr);
 
-	AdvDetector.registerGameDescriptions(descList);
-	AdvDetector.setFileMD5Bytes(md5Bytes);
+	ad.registerGameDescriptions(descList);
+	ad.setFileMD5Bytes(md5Bytes);
 
-	matches = AdvDetector.detectGame(0, language, platform);
+	matches = ad.detectGame(0, language, platform);
 
 	for (uint i = 0; i < matches.size(); i++) {
 		if (toDetectedGame(*(const ADGameDescription *)(descs + matches[i] * descItemSize), list).gameid == gameid) {

Modified: scummvm/trunk/common/advancedDetector.h
===================================================================
--- scummvm/trunk/common/advancedDetector.h	2006-12-19 21:52:29 UTC (rev 24892)
+++ scummvm/trunk/common/advancedDetector.h	2006-12-19 22:43:15 UTC (rev 24893)
@@ -53,12 +53,56 @@
 typedef Array<int> ADList;
 typedef Array<const ADGameDescription*> ADGameDescList;
 
-// FIXME/TODO: Rename this function to something more sensible.
-// Possibly move it inside class AdvancedDetector ?
-// Maybe rename it to something like asGameList or pgdArrayToGameList,
-// and move it to base/game.h. Or add a constructor to GameList ... ?
-GameList real_ADVANCED_DETECTOR_GAMEID_LIST(const PlainGameDescriptor *list);
 
+
+// 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:
+	AdvancedDetector();
+	~AdvancedDetector() {};
+
+
+	void registerGameDescriptions(ADGameDescList gameDescriptions) {
+		_gameDescriptions = gameDescriptions;
+	}
+
+	/**
+	 * Specify number of bytes which are used to calculate MD5.
+	 * Default value is 0 which means whole file.
+	 */
+	void setFileMD5Bytes(int bytes) { _fileMD5Bytes = bytes; }
+
+	/**
+	 * 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 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, Language language, Platform platform);
+
+private:
+	ADGameDescList _gameDescriptions;
+
+	int _fileMD5Bytes;
+
+	String getDescription(int num) const;
+};
+
+
 // FIXME/TODO: Rename this function to something more sensible.
 // Possibly move it inside class AdvancedDetector ?
 GameDescriptor real_ADVANCED_DETECTOR_FIND_GAMEID(
@@ -102,18 +146,6 @@
 	);
 
 
-#define ADVANCED_DETECTOR_GAMEID_LIST(engine,list) \
-	GameList Engine_##engine##_gameIDList() { \
-		return Common::real_ADVANCED_DETECTOR_GAMEID_LIST(list); \
-	} \
-	void dummyFuncToAllowTrailingSemicolon()
-
-#define ADVANCED_DETECTOR_FIND_GAMEID(engine,list,obsoleteList) \
-	GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
-		return Common::real_ADVANCED_DETECTOR_FIND_GAMEID(gameid,list,obsoleteList); \
-	} \
-	void dummyFuncToAllowTrailingSemicolon()
-
 #define ADVANCED_DETECTOR_DETECT_GAMES(engine,detectFunc) \
 	DetectedGameList Engine_##engine##_detectGames(const FSList &fslist) { \
 		return detectFunc(fslist);						\
@@ -132,59 +164,16 @@
 	void dummyFuncToAllowTrailingSemicolon()
 
 #define ADVANCED_DETECTOR_DEFINE_PLUGIN(engine,createFunction,detectFunc,list,obsoleteList) \
-	ADVANCED_DETECTOR_GAMEID_LIST(engine, list); \
-	ADVANCED_DETECTOR_FIND_GAMEID(engine, list, obsoleteList); \
+	GameList Engine_##engine##_gameIDList() { \
+		return GameList(list); \
+	} \
+	GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
+		return Common::real_ADVANCED_DETECTOR_FIND_GAMEID(gameid,list,obsoleteList); \
+	} \
 	ADVANCED_DETECTOR_DETECT_GAMES(engine, detectFunc); \
 	ADVANCED_DETECTOR_ENGINE_CREATE(engine, createFunction, detectFunc, obsoleteList)
 
 
-// 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:
-	AdvancedDetector();
-	~AdvancedDetector() {};
-
-
-	void registerGameDescriptions(ADGameDescList gameDescriptions) {
-		_gameDescriptions = gameDescriptions;
-	}
-
-	/**
-	 * Specify number of bytes which are used to calculate MD5.
-	 * Default value is 0 which means whole file.
-	 */
-	void setFileMD5Bytes(int bytes) { _fileMD5Bytes = bytes; }
-
-	/**
-	 * 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 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, Language language, Platform platform);
-
-private:
-	ADGameDescList _gameDescriptions;
-
-	int _fileMD5Bytes;
-
-	String getDescription(int num) const;
-};
-
 }	// End of namespace Common
 
 #endif

Modified: scummvm/trunk/engines/kyra/plugin.cpp
===================================================================
--- scummvm/trunk/engines/kyra/plugin.cpp	2006-12-19 21:52:29 UTC (rev 24892)
+++ scummvm/trunk/engines/kyra/plugin.cpp	2006-12-19 22:43:15 UTC (rev 24893)
@@ -39,7 +39,7 @@
 };
 
 struct KYRAGameDescription {
-	ADGameDescription desc;
+	Common::ADGameDescription desc;
 
 	const char *id;
 	GameFlags flags;
@@ -151,27 +151,23 @@
 	{ { NULL, NULL, NULL, UNK_LANG, kPlatformUnknown }, NULL, KYRA2_UNK_FLAGS }
 };
 
-ADGameDescList getADDescList() {
-	ADGameDescList gameDesc;
+static ADList detectKyraGames(const FSList &fslist) {
+	Common::AdvancedDetector ad;
+	Common::ADList matches;
+	Common::ADGameDescList descList;
 
 	for (int i = 0; i < ARRAYSIZE(adGameDescs) - 1; ++i) {
-		gameDesc.push_back(&adGameDescs[i].desc);
+		descList.push_back(&adGameDescs[i].desc);
 	}
 
-	return gameDesc;
-}
-
-ADList detectKyraGames(const FSList &fslist) {
-	AdvancedDetector ad;
-
-	ad.registerGameDescriptions(getADDescList());
+	ad.registerGameDescriptions(descList);
 	ad.setFileMD5Bytes(kMD5FileSizeLimit);
 
-	ADList list = ad.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown);
-	return list;
+	matches = ad.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown);
+	return matches;
 }
 
-bool setupGameFlags(const ADList &list, GameFlags &flags) {
+static bool setupGameFlags(const ADList &list, GameFlags &flags) {
 	if (!list.size()) {
 		// maybe add non md5 based detection again?
 		return false;
@@ -224,7 +220,7 @@
 } // End of anonymous namespace
 
 GameList Engine_KYRA_gameIDList() {
-	return Common::real_ADVANCED_DETECTOR_GAMEID_LIST(gameList);
+	return GameList(gameList);
 }
 
 GameDescriptor Engine_KYRA_findGameID(const char *gameid) {


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