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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Feb 14 00:37:45 CET 2007


Revision: 25574
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25574&view=rev
Author:   fingolfin
Date:     2007-02-13 15:37:44 -0800 (Tue, 13 Feb 2007)

Log Message:
-----------
Changed detectBestMatchingGame to return a pointer to a ADGameDescription (or a subclass of it); added a (currently fake) fallback callback entry in ADParams

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

Modified: scummvm/trunk/common/advancedDetector.cpp
===================================================================
--- scummvm/trunk/common/advancedDetector.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/common/advancedDetector.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -188,9 +188,10 @@
 	return detectedGames;
 }
 
-int detectBestMatchingGame(
+const ADGameDescription *detectBestMatchingGame(
 	const Common::ADParams &params
 	) {
+	const ADGameDescription *agdDesc = 0;
 	Common::Language language = Common::UNK_LANG;
 	Common::Platform platform = Common::kPlatformUnknown;
 
@@ -203,24 +204,23 @@
 
 	Common::ADList matches = detectGame(0, params, language, platform);
 
-	int gameNumber = -1;
-
 	if (params.singleid == NULL) {
 		for (uint i = 0; i < matches.size(); i++) {
-			if (((const ADGameDescription *)(params.descs + matches[i] * params.descItemSize))->gameid == gameid) {
-				gameNumber = matches[i];
+			agdDesc = (const ADGameDescription *)(params.descs + matches[i] * params.descItemSize);
+			if (agdDesc->gameid == gameid) {
 				break;
 			}
+			agdDesc = 0;
 		}
-	} else {
-		gameNumber = matches[0];
+	} else if (matches.size() > 0) {
+		agdDesc = (const ADGameDescription *)(params.descs + matches[0] * params.descItemSize);
 	}
 
-	if (gameNumber >= 0) {
-		debug(2, "Running %s", toGameDescriptor(*(const ADGameDescription *)(params.descs + gameNumber * params.descItemSize), params.list).description().c_str());
+	if (agdDesc != 0) {
+		debug(2, "Running %s", toGameDescriptor(*agdDesc, params.list).description().c_str());
 	}
 
-	return gameNumber;
+	return agdDesc;
 }
 
 PluginError detectGameForEngineCreation(
@@ -426,6 +426,8 @@
 		return matched;
 
 	if (!filesMD5.empty()) {
+		// TODO: This message should be cleaned up / made more specific.
+		// For example, we should specify at least which engine triggered this.
 		printf("MD5s of your game version are unknown. Please, report following data to\n");
 		printf("ScummVM team along with your game name and version:\n");
 
@@ -505,7 +507,7 @@
 				matchEntry = entryStart;
 				maxFiles = matchFiles;
 
-				debug(4, "and overrided");
+				debug(4, "and overriden");
 			}
 
 			ptr++;
@@ -515,6 +517,8 @@
 			for (i = 0; i < gameDescriptions.size(); i++) {
 				if (gameDescriptions[i]->filesDescriptions[0].fileName == 0) {
 					if (!scumm_stricmp(gameDescriptions[i]->gameid, *matchEntry)) {
+						// FIXME: This warning, if ever seen by somebody, is
+						// extremly cryptic!
 						warning("But it looks like unknown variant of %s", *matchEntry);
 
 						matched.push_back(i);
@@ -523,7 +527,12 @@
 			}
 		}
 	}
-
+/*	
+	// If we still haven't got a match, try to use the fallback callback :-)
+	if (matched.empty() && params.fallbackDetectFunc != 0) {
+		matched = (*params.fallbackDetectFunc)(fslist);
+	}
+*/
 	return matched;
 }
 

Modified: scummvm/trunk/common/advancedDetector.h
===================================================================
--- scummvm/trunk/common/advancedDetector.h	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/common/advancedDetector.h	2007-02-13 23:37:44 UTC (rev 25574)
@@ -120,7 +120,7 @@
 	const PlainGameDescriptor *list;
 
 	/**
-	 * Structure for autoupgrading obsolete targets (optional)
+	 * Structure for autoupgrading obsolete targets (optional).
 	 *
 	 * @todo Properly explain this.
 	 */
@@ -134,13 +134,31 @@
 	const char *singleid;
 
 	/**
-	 * List of files for file-based fallback detection (optional)
-	 
+	 * List of files for file-based fallback detection (optional).
+	 * This is used if the regular MD5 based detection failed to 
+	 * detect anything.
+	 *
 	 * @todo Properly explain this
 	 */
 	const char **fileBasedFallback;
+	
+	/** 
+	 * A callback pointing to an (optional) generic fallback detect
+	 * function. If present, this gets called if both the regular
+	 * MD5 based detection as well as the file based fallback failed
+	 * to detect anything. It is supposed
+	 *
+	 * @note The fslist parameter may be 0 -- in that case, it is assumed
+	 *       that the callback searchs the current directory.
+	 */
+	//GameList (*fallbackDetectFunc)(const FSList *fslist);
+	uint dummy;
 
-	/** Flags */
+	/**
+	 * A bitmask of flags which can be used to configure the behavior
+	 * of the AdvancedDetector. Refer to ADFlags for a list of flags
+	 * that can be ORed together and passed here.
+	 */
 	uint32 flags;
 };
 
@@ -158,31 +176,19 @@
  * 'gameid' in there. If a match is found, returns a  GameDescriptor
  * with gameid and description set.
  */
-GameDescriptor findGameID(
-	const char *gameid,
-	const Common::ADParams &params
-	);
+GameDescriptor findGameID(const char *gameid, const Common::ADParams &params);
 
-
 // FIXME/TODO: Rename this function to something more sensible.
-GameList detectAllGames(
-	const FSList &fslist,
-	const Common::ADParams &params
-	);
+GameList detectAllGames(const FSList &fslist, const Common::ADParams &params);
 
-
 // FIXME/TODO: Rename this function to something more sensible.
-int detectBestMatchingGame(
-	const Common::ADParams &params
-	);
+const ADGameDescription *detectBestMatchingGame(const Common::ADParams &params);
 
 // FIXME/TODO: Rename this function to something more sensible.
 void upgradeTargetIfNecessary(const Common::ADParams &params);
 
 // FIXME/TODO: Rename this function to something more sensible.
-PluginError detectGameForEngineCreation(
-	const Common::ADParams &params
-	);
+PluginError detectGameForEngineCreation(const Common::ADParams &params);
 
 
 // FIXME: It would probably be good to merge detectBestMatchingGame

Modified: scummvm/trunk/engines/agi/detection.cpp
===================================================================
--- scummvm/trunk/engines/agi/detection.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/agi/detection.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -1741,6 +1741,8 @@
 	"agi",
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	Common::kADFlagAugmentPreferredTarget
 };
@@ -1752,12 +1754,8 @@
 namespace Agi {
 
 bool AgiEngine::initGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (i < 0)
-		return false;
-
-	_gameDescription = &gameDescriptions[i];
-	return true;
+	_gameDescription = (const AGIGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	return (_gameDescription != 0);
 }
 
 } // End of namespace Agi

Modified: scummvm/trunk/engines/agos/game.cpp
===================================================================
--- scummvm/trunk/engines/agos/game.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/agos/game.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -96,6 +96,8 @@
 	0,
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	Common::kADFlagAugmentPreferredTarget
 };
@@ -107,12 +109,8 @@
 namespace AGOS {
 
 bool AGOSEngine::initGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (i < 0)
-		return false;
-
-	_gameDescription = &gameDescriptions[i];
-	return true;
+	_gameDescription = (const AGOSGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	return (_gameDescription != 0);
 }
 
 

Modified: scummvm/trunk/engines/cine/detection.cpp
===================================================================
--- scummvm/trunk/engines/cine/detection.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/cine/detection.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -480,6 +480,8 @@
 	"cine",
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	Common::kADFlagAugmentPreferredTarget
 };
@@ -491,12 +493,8 @@
 namespace Cine {
 
 bool CineEngine::initGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (i < 0)
-		return false;
-
-	_gameDescription = &gameDescriptions[i];
-	return true;
+	_gameDescription = (const CINEGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	return (_gameDescription != 0);
 }
 
 } // End of namespace Cine

Modified: scummvm/trunk/engines/gob/detection.cpp
===================================================================
--- scummvm/trunk/engines/gob/detection.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/gob/detection.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -913,6 +913,8 @@
 	"gob",
 	// List of files for file-based fallback detection (optional)
 	Gob::fileBased,
+	// Fallback callback
+	0,
 	// Flags
 	kADFlagAugmentPreferredTarget
 };
@@ -925,25 +927,27 @@
 namespace Gob {
 
 bool GobEngine::detectGame() {
-	int i = AdvancedDetector::detectBestMatchingGame(detectionParams);
+	const GOBGameDescription *gd = (const GOBGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	if (gd == 0)
+		return false;
 
-	if (gameDescriptions[i].startTotBase == 0) {
+	if (gd->startTotBase == 0) {
 		_startTot = new char[10];
 		_startTot0 = new char[11];
 		strcpy(_startTot, "intro.tot");
 		strcpy(_startTot0, "intro0.tot");
 	} else {
-		_startTot = new char[strlen(gameDescriptions[i].startTotBase) + 5];
-		_startTot0 = new char[strlen(gameDescriptions[i].startTotBase) + 6];
-		strcpy(_startTot, gameDescriptions[i].startTotBase);
-		strcpy(_startTot0, gameDescriptions[i].startTotBase);
+		_startTot = new char[strlen(gd->startTotBase) + 5];
+		_startTot0 = new char[strlen(gd->startTotBase) + 6];
+		strcpy(_startTot, gd->startTotBase);
+		strcpy(_startTot0, gd->startTotBase);
 		strcat(_startTot, ".tot");
 		strcat(_startTot0, "0.tot");
 	}
 
-	_features = gameDescriptions[i].features;
-	_language = gameDescriptions[i].desc.language;
-	_platform = gameDescriptions[i].desc.platform;
+	_features = gd->features;
+	_language = gd->desc.language;
+	_platform = gd->desc.platform;
 
 	return true;
 }

Modified: scummvm/trunk/engines/kyra/plugin.cpp
===================================================================
--- scummvm/trunk/engines/kyra/plugin.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/kyra/plugin.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -97,6 +97,8 @@
 	0,
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	0
 };
@@ -119,19 +121,16 @@
 	assert(engine);
 	const char *gameid = ConfMan.get("gameid").c_str();
 	
-	int id = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (id == -1) {
-		// FIXME: This case currently can never happen, as we simply error out
-		// inside AdvancedDetector::detectBestMatchingGame.
-		
+	const KYRAGameDescription *gd = (const KYRAGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	if (gd == 0) {
 		// maybe add non md5 based detection again?
 		return kNoGameDataFoundError;
 	}
 
-	Kyra::GameFlags flags = adGameDescs[id].flags;
+	Kyra::GameFlags flags = gd->flags;
 	
-	flags.lang = adGameDescs[id].desc.language;
-	flags.platform = adGameDescs[id].desc.platform;
+	flags.lang = gd->desc.language;
+	flags.platform = gd->desc.platform;
 
 	Common::Platform platform = Common::parsePlatform(ConfMan.get("platform"));
 	if (platform != Common::kPlatformUnknown) {

Modified: scummvm/trunk/engines/parallaction/detection.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/detection.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/parallaction/detection.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -94,6 +94,8 @@
 	"parallaction",
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	Common::kADFlagAugmentPreferredTarget
 };
@@ -106,10 +108,8 @@
 namespace Parallaction {
 
 bool Parallaction::detectGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-
-	_gameDescription = &gameDescriptions[i];
-	return true;
+	_gameDescription = (const PARALLACTIONGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	return (_gameDescription != 0);
 }
 
 } // End of namespace Parallaction

Modified: scummvm/trunk/engines/saga/game.cpp
===================================================================
--- scummvm/trunk/engines/saga/game.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/saga/game.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -115,6 +115,8 @@
 	"saga",
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	Common::kADFlagAugmentPreferredTarget
 };
@@ -126,12 +128,10 @@
 namespace Saga {
 
 bool SagaEngine::initGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (i < 0)
+	_gameDescription = (const SAGAGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	if (_gameDescription == 0)
 		return false;
 
-	_gameDescription = &gameDescriptions[i];
-
 	_gameDisplayInfo = *_gameDescription->gameDisplayInfo;
 	_displayClip.right = _gameDisplayInfo.logicalWidth;
 	_displayClip.bottom = _gameDisplayInfo.logicalHeight;

Modified: scummvm/trunk/engines/touche/plugin.cpp
===================================================================
--- scummvm/trunk/engines/touche/plugin.cpp	2007-02-13 23:15:46 UTC (rev 25573)
+++ scummvm/trunk/engines/touche/plugin.cpp	2007-02-13 23:37:44 UTC (rev 25574)
@@ -108,6 +108,8 @@
 	"touche",
 	// List of files for file-based fallback detection (optional)
 	0,
+	// Fallback callback
+	0,
 	// Flags
 	0
 };
@@ -119,11 +121,11 @@
 namespace Touche {
 
 bool ToucheEngine::detectGame() {
-	int i = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
-	if (i < 0)
+	const Common::ADGameDescription *gd = Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
+	if (gd == 0)
 		return false;
 
-	_language = gameDescriptions[i].language;
+	_language = gd->language;
 	return true;
 }
 


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