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

sev at users.sourceforge.net sev at users.sourceforge.net
Wed Jan 24 23:24:53 CET 2007


Revision: 25163
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25163&view=rev
Author:   sev
Date:     2007-01-24 14:24:52 -0800 (Wed, 24 Jan 2007)

Log Message:
-----------
Hide all AdvacedDetector parameters into a structure for easier maintenance
and extensibility

Modified Paths:
--------------
    scummvm/trunk/common/advancedDetector.cpp
    scummvm/trunk/common/advancedDetector.h
    scummvm/trunk/engines/agos/agosgame.cpp
    scummvm/trunk/engines/agos/game.cpp
    scummvm/trunk/engines/cine/detection.cpp
    scummvm/trunk/engines/kyra/plugin.cpp
    scummvm/trunk/engines/parallaction/detection.cpp

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/common/advancedDetector.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -35,12 +35,12 @@
 
 PluginError ADVANCED_DETECTOR_ENGINE_CREATE(
 	GameList (*detectFunc)(const FSList &fslist),
-	const Common::ADObsoleteGameID *obsoleteList
+	const Common::ADParams &params
 	) {
 	const char *gameid = ConfMan.get("gameid").c_str();
 
-	if (obsoleteList != 0) {
-		for (const Common::ADObsoleteGameID *o = obsoleteList; o->from; ++o) {
+	if (params.obsoleteList != 0) {
+		for (const Common::ADObsoleteGameID *o = params.obsoleteList; o->from; ++o) {
 			if (!scumm_stricmp(gameid, o->from)) {
 				gameid = o->to;
 				ConfMan.set("gameid", o->to);
@@ -74,10 +74,9 @@
 
 GameDescriptor ADVANCED_DETECTOR_FIND_GAMEID(
 	const char *gameid,
-	const PlainGameDescriptor *list,
-	const Common::ADObsoleteGameID *obsoleteList
+	const Common::ADParams &params
 	) {
-	const PlainGameDescriptor *g = list;
+	const PlainGameDescriptor *g = params.list;
 	while (g->gameid) {
 		if (0 == scumm_stricmp(gameid, g->gameid))
 			return *g;
@@ -85,8 +84,8 @@
 	}
 
 	GameDescriptor gs;
-	if (obsoleteList != 0) {
-		const Common::ADObsoleteGameID *o = obsoleteList;
+	if (params.obsoleteList != 0) {
+		const Common::ADObsoleteGameID *o = params.obsoleteList;
 		while (o->from) {
 			if (0 == scumm_stricmp(gameid, o->from)) {
 				gs["gameid"] = gameid;
@@ -116,10 +115,7 @@
 
 GameList ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
 	const FSList &fslist,
-	const byte *descs,
-	const int descItemSize,
-	const int md5Bytes,
-	const PlainGameDescriptor *list
+	const Common::ADParams &params
 	) {
 	GameList detectedGames;
 	Common::AdvancedDetector ad;
@@ -127,26 +123,23 @@
 	Common::ADGameDescList descList;
 	const byte *descPtr;
 
-	for (descPtr = descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += descItemSize)
+	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 *)descs)->gameid,  descList.size());
+	debug(3, "%s: cnt: %d", ((const ADGameDescription *)params.descs)->gameid,  descList.size());
 
-	matches = ad.detectGame(&fslist, md5Bytes, Common::UNK_LANG, Common::kPlatformUnknown);
+	matches = ad.detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown);
 
 	for (uint i = 0; i < matches.size(); i++)
-		detectedGames.push_back(toGameDescriptor(*(const ADGameDescription *)(descs + matches[i] * descItemSize), list));
+		detectedGames.push_back(toGameDescriptor(*(const ADGameDescription *)(params.descs + matches[i] * params.descItemSize), params.list));
 
 	return detectedGames;
 }
 
 int ADVANCED_DETECTOR_DETECT_INIT_GAME(
-	const byte *descs,
-	const int descItemSize,
-	const int md5Bytes,
-	const PlainGameDescriptor *list
+	const Common::ADParams &params
 	) {
 	int gameNumber = -1;
 
@@ -166,15 +159,15 @@
 
 	Common::String gameid = ConfMan.get("gameid");
 
-	for (descPtr = descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += descItemSize)
+	for (descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize)
 		descList.push_back((const ADGameDescription *)descPtr);
 
 	ad.registerGameDescriptions(descList);
 
-	matches = ad.detectGame(0, md5Bytes, language, platform);
+	matches = ad.detectGame(0, params, language, platform);
 
 	for (uint i = 0; i < matches.size(); i++) {
-		if (((const ADGameDescription *)(descs + matches[i] * descItemSize))->gameid == gameid) {
+		if (((const ADGameDescription *)(params.descs + matches[i] * params.descItemSize))->gameid == gameid) {
 			gameNumber = matches[i];
 			break;
 		}
@@ -184,7 +177,7 @@
 		error("TODO invalid gameNumber %d (max. expected value: %d)", gameNumber, descList.size());
 	}
 
-	debug(2, "Running %s", toGameDescriptor(*(const ADGameDescription *)(descs + gameNumber * descItemSize), list).description().c_str());
+	debug(2, "Running %s", toGameDescriptor(*(const ADGameDescription *)(params.descs + gameNumber * params.descItemSize), params.list).description().c_str());
 
 	return gameNumber;
 }
@@ -199,7 +192,7 @@
 	return String(tmp);
 }
 
-ADList AdvancedDetector::detectGame(const FSList *fslist, int md5Bytes, Language language, Platform platform) {
+ADList AdvancedDetector::detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform) {
 	typedef HashMap<String, bool, CaseSensitiveString_Hash, CaseSensitiveString_EqualTo> StringSet;
 	StringSet filesList;
 
@@ -238,7 +231,7 @@
 
 			if (!filesList.contains(tstr) && !filesList.contains(tstr2)) continue;
 
-			if (!md5_file(*file, md5sum, md5Bytes)) continue;
+			if (!md5_file(*file, md5sum, params.md5Bytes)) continue;
 			for (j = 0; j < 16; j++) {
 				sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 			}
@@ -257,7 +250,7 @@
 				if (testFile.open(file->_key)) {
 					testFile.close();
 
-					if (md5_file(file->_key.c_str(), md5sum, md5Bytes)) {
+					if (md5_file(file->_key.c_str(), md5sum, params.md5Bytes)) {
 						for (j = 0; j < 16; j++) {
 							sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 						}

Modified: scummvm/trunk/common/advancedDetector.h
===================================================================
--- scummvm/trunk/common/advancedDetector.h	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/common/advancedDetector.h	2007-01-24 22:24:52 UTC (rev 25163)
@@ -50,6 +50,19 @@
 	Common::Platform platform;
 };
 
+struct ADParams {
+	// Pointer to ADGameDescription or its superset structure
+	const byte *descs;
+	// Size of that superset structure
+	const int descItemSize;
+	// Number of bytes to compute MD5 sum for
+	const int md5Bytes;
+	// List of all engine targets
+	const PlainGameDescriptor *list;
+	// Structure for autoupgrading obsolete targets
+	const Common::ADObsoleteGameID *obsoleteList;
+};
+
 typedef Array<int> ADList;
 typedef Array<const ADGameDescription*> ADGameDescList;
 
@@ -84,7 +97,7 @@
 	 * @param platform	restrict results to specified platform only
 	 * @return	list of indexes to GameDescriptions of matched games
 	 */
-	ADList detectGame(const FSList *fslist, int md5Bytes, Language language, Platform platform);
+	ADList detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform);
 
 private:
 	ADGameDescList _gameDescriptions;
@@ -95,8 +108,7 @@
 // Possibly move it inside class AdvancedDetector ?
 GameDescriptor ADVANCED_DETECTOR_FIND_GAMEID(
 	const char *gameid,
-	const PlainGameDescriptor *list,
-	const Common::ADObsoleteGameID *obsoleteList
+	const Common::ADParams &params
 	);
 
 
@@ -104,36 +116,30 @@
 // Possibly move it inside class AdvancedDetector ?
 GameList ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
 	const FSList &fslist,
-	const byte *descs,
-	const int descItemSize,
-	const int md5Bytes,
-	const PlainGameDescriptor *list
+	const Common::ADParams &params
 	);
 
 
 // FIXME/TODO: Rename this function to something more sensible.
 // Possibly move it inside class AdvancedDetector ?
 int ADVANCED_DETECTOR_DETECT_INIT_GAME(
-	const byte *descs,
-	const int descItemSize,
-	const int md5Bytes,
-	const PlainGameDescriptor *list
+	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::ADObsoleteGameID *obsoleteList
+	const Common::ADParams &params
 	);
 
 
-#define ADVANCED_DETECTOR_DEFINE_PLUGIN(engine,createFunction,detectFunc,list,obsoleteList) \
+#define ADVANCED_DETECTOR_DEFINE_PLUGIN(engine,createFunction,detectFunc,params) \
 	GameList Engine_##engine##_gameIDList() { \
-		return GameList(list); \
+		return GameList(params.list); \
 	} \
 	GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
-		return Common::ADVANCED_DETECTOR_FIND_GAMEID(gameid,list,obsoleteList); \
+		return Common::ADVANCED_DETECTOR_FIND_GAMEID(gameid, params); \
 	} \
 	GameList Engine_##engine##_detectGames(const FSList &fslist) { \
 		return detectFunc(fslist);						\
@@ -141,7 +147,7 @@
 	PluginError Engine_##engine##_create(OSystem *syst, Engine **engine) { \
 		assert(syst); \
 		assert(engine); \
-		PluginError err = ADVANCED_DETECTOR_ENGINE_CREATE(detectFunc, obsoleteList); \
+		PluginError err = ADVANCED_DETECTOR_ENGINE_CREATE(detectFunc, params); \
 		if (err == kNoError) \
 			*engine = new createFunction(syst); \
 		return err; \

Modified: scummvm/trunk/engines/agos/agosgame.cpp
===================================================================
--- scummvm/trunk/engines/agos/agosgame.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/engines/agos/agosgame.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -1,5 +1,3 @@
-#define FILE_MD5_BYTES 5000
-
 static const AGOSGameDescription gameDescriptions[] = {
 	// Elvira 1 - English Amiga Floppy
 	{

Modified: scummvm/trunk/engines/agos/game.cpp
===================================================================
--- scummvm/trunk/engines/agos/game.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/engines/agos/game.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -79,33 +79,40 @@
 	{0, 0}
 };
 
-ADVANCED_DETECTOR_DEFINE_PLUGIN(AGOS, AGOS::AGOSEngine, AGOS::GAME_detectGames, simonGames, obsoleteGameIDsTable);
+namespace AGOS {
 
+#include "agosgame.cpp"
+
+}
+
+static const Common::ADParams detectionParams = {
+	// Pointer to ADGameDescription or its superset structure
+	(const byte *)AGOS::gameDescriptions,
+	// Size of that superset structure
+	sizeof(AGOS::AGOSGameDescription),
+	// Number of bytes to compute MD5 sum for
+	5000,
+	// List of all engine targets
+	simonGames,
+	// Structure for autoupgrading obsolete targets
+	obsoleteGameIDsTable
+};
+
+ADVANCED_DETECTOR_DEFINE_PLUGIN(AGOS, AGOS::AGOSEngine, AGOS::GAME_detectGames, detectionParams);
+
 REGISTER_PLUGIN(AGOS, "AGOS", "AGOS (C) Adventure Soft");
 
 namespace AGOS {
 
-#include "agosgame.cpp"
+bool AGOSEngine::initGame() {
+	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(detectionParams);
 
-bool AGOSEngine::initGame() {
-	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(
-		(const byte *)gameDescriptions,
-		sizeof(AGOSGameDescription),
-		FILE_MD5_BYTES,
-		simonGames
-		);
 	_gameDescription = &gameDescriptions[i];
 	return true;
 }
 
 GameList GAME_detectGames(const FSList &fslist) {
-	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
-		fslist,
-		(const byte *)gameDescriptions,
-		sizeof(AGOSGameDescription),
-		FILE_MD5_BYTES,
-		simonGames
-	);
+	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(fslist, detectionParams);
 }
 
 int AGOSEngine::getGameId() const {

Modified: scummvm/trunk/engines/cine/detection.cpp
===================================================================
--- scummvm/trunk/engines/cine/detection.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/engines/cine/detection.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -54,14 +54,8 @@
 	{0, 0}
 };
 
-ADVANCED_DETECTOR_DEFINE_PLUGIN(CINE, Cine::CineEngine, Cine::GAME_detectGames, cineGames, 0);
-
-REGISTER_PLUGIN(CINE, "Cinematique evo 1 engine", "Future Wars & Operation Stealth (C) Delphine Software");
-
 namespace Cine {
 
-#define FILE_MD5_BYTES 5000
-
 static const CINEGameDescription gameDescriptions[] = {
 	{
 		{
@@ -435,25 +429,36 @@
 	{ { NULL, NULL, AD_ENTRY1(NULL, NULL), Common::UNK_LANG, Common::kPlatformUnknown }, 0, 0 }
 };
 
+}
+
+static const Common::ADParams detectionParams = {
+	// Pointer to ADGameDescription or its superset structure
+	(const byte *)Cine::gameDescriptions,
+	// Size of that superset structure
+	sizeof(Cine::CINEGameDescription),
+	// Number of bytes to compute MD5 sum for
+	5000,
+	// List of all engine targets
+	cineGames,
+	// Structure for autoupgrading obsolete targets
+	0
+};
+
+ADVANCED_DETECTOR_DEFINE_PLUGIN(CINE, Cine::CineEngine, Cine::GAME_detectGames, detectionParams);
+
+REGISTER_PLUGIN(CINE, "Cinematique evo 1 engine", "Future Wars & Operation Stealth (C) Delphine Software");
+
+namespace Cine {
+
 bool CineEngine::initGame() {
-	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(
-		(const byte *)gameDescriptions,
-		sizeof(CINEGameDescription),
-		FILE_MD5_BYTES,
-		cineGames
-		);
+	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(detectionParams);
+
 	_gameDescription = &gameDescriptions[i];
 	return true;
 }
 
 GameList GAME_detectGames(const FSList &fslist) {
-	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
-		fslist,
-		(const byte *)gameDescriptions,
-		sizeof(CINEGameDescription),
-		FILE_MD5_BYTES,
-		cineGames
-	);
+	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(fslist, detectionParams);
 }
 
 } // End of namespace Cine

Modified: scummvm/trunk/engines/kyra/plugin.cpp
===================================================================
--- scummvm/trunk/engines/kyra/plugin.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/engines/kyra/plugin.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -33,11 +33,6 @@
 using namespace Kyra;
 using namespace Common;
 
-enum {
-	// We only compute MD5 of the first megabyte of our data files.
-	kMD5FileSizeLimit = 1024 * 1024
-};
-
 struct KYRAGameDescription {
 	Common::ADGameDescription desc;
 
@@ -130,6 +125,19 @@
 	{ 0, 0 }
 };
 
+static const Common::ADParams detectionParams = {
+	// Pointer to ADGameDescription or its superset structure
+	(const byte *)adGameDescs,
+	// Size of that superset structure
+	sizeof(KYRAGameDescription),
+	// Number of bytes to compute MD5 sum for
+	1024 * 1024,
+	// List of all engine targets
+	gameList,
+	// Structure for autoupgrading obsolete targets
+	0
+};
+
 } // End of anonymous namespace
 
 GameList Engine_KYRA_gameIDList() {
@@ -137,17 +145,11 @@
 }
 
 GameDescriptor Engine_KYRA_findGameID(const char *gameid) {
-	return Common::ADVANCED_DETECTOR_FIND_GAMEID(gameid, gameList, 0);
+	return Common::ADVANCED_DETECTOR_FIND_GAMEID(gameid, detectionParams);
 }
 
 GameList Engine_KYRA_detectGames(const FSList &fslist) {
-	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
-		fslist,
-		(const byte *)adGameDescs,
-		sizeof(KYRAGameDescription),
-		kMD5FileSizeLimit,
-		gameList
-	);
+	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(fslist, detectionParams);
 }
 
 PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) {
@@ -171,7 +173,7 @@
 
 	ad.registerGameDescriptions(descList);
 
-	matches = ad.detectGame(&fslist, kMD5FileSizeLimit, Common::UNK_LANG, Common::kPlatformUnknown);
+	matches = ad.detectGame(&fslist, detectionParams, Common::UNK_LANG, Common::kPlatformUnknown);
 
 	if (!setupGameFlags(matches, flags)) {
 		return kNoGameDataFoundError;

Modified: scummvm/trunk/engines/parallaction/detection.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/detection.cpp	2007-01-24 00:11:22 UTC (rev 25162)
+++ scummvm/trunk/engines/parallaction/detection.cpp	2007-01-24 22:24:52 UTC (rev 25163)
@@ -51,15 +51,8 @@
 	{0, 0}
 };
 
-ADVANCED_DETECTOR_DEFINE_PLUGIN(PARALLACTION, Parallaction::Parallaction, Parallaction::GAME_detectGames, parallactionGames, 0);
-
-REGISTER_PLUGIN(PARALLACTION, "Parallaction engine", "Nippon Safes Inc. (C) Dynabyte");
-
-
 namespace Parallaction {
 
-#define FILE_MD5_BYTES 5000
-
 static const PARALLACTIONGameDescription gameDescriptions[] = {
 	{
 		{
@@ -85,26 +78,37 @@
 	{ { NULL, NULL, { { NULL, 0, NULL } }, Common::UNK_LANG, Common::kPlatformUnknown }, 0, 0 }
 };
 
+}
 
+static const Common::ADParams detectionParams = {
+	// Pointer to ADGameDescription or its superset structure
+	(const byte *)Parallaction::gameDescriptions,
+	// Size of that superset structure
+	sizeof(Parallaction::PARALLACTIONGameDescription),
+	// Number of bytes to compute MD5 sum for
+	5000,
+	// List of all engine targets
+	parallactionGames,
+	// Structure for autoupgrading obsolete targets
+	0
+};
+
+ADVANCED_DETECTOR_DEFINE_PLUGIN(PARALLACTION, Parallaction::Parallaction, Parallaction::GAME_detectGames, detectionParams);
+
+REGISTER_PLUGIN(PARALLACTION, "Parallaction engine", "Nippon Safes Inc. (C) Dynabyte");
+
+
+namespace Parallaction {
+
 bool Parallaction::detectGame() {
-	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(
-		(const byte *)gameDescriptions,
-		sizeof(PARALLACTIONGameDescription),
-		FILE_MD5_BYTES,
-		parallactionGames
-		);
+	int i = Common::ADVANCED_DETECTOR_DETECT_INIT_GAME(detectionParams);
+
 	_gameDescription = &gameDescriptions[i];
 	return true;
 }
 
 GameList GAME_detectGames(const FSList &fslist) {
-	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
-		fslist,
-		(const byte *)gameDescriptions,
-		sizeof(PARALLACTIONGameDescription),
-		FILE_MD5_BYTES,
-		parallactionGames
-	);
+	return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(fslist, detectionParams);
 }
 
 } // End of namespace Parallaction


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