From 7572d2b4f2ac98cf31602d6c5e4ed7399de54a30 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 13 Feb 2007 23:37:44 +0000 Subject: Changed detectBestMatchingGame to return a pointer to a ADGameDescription (or a subclass of it); added a (currently fake) fallback callback entry in ADParams svn-id: r25574 --- common/advancedDetector.cpp | 33 +++++++++++++++++---------- common/advancedDetector.h | 46 +++++++++++++++++++++----------------- engines/agi/detection.cpp | 10 ++++----- engines/agos/game.cpp | 10 ++++----- engines/cine/detection.cpp | 10 ++++----- engines/gob/detection.cpp | 22 ++++++++++-------- engines/kyra/plugin.cpp | 15 ++++++------- engines/parallaction/detection.cpp | 8 +++---- engines/saga/game.cpp | 8 +++---- engines/touche/plugin.cpp | 8 ++++--- 10 files changed, 92 insertions(+), 78 deletions(-) diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index d6ec293620..1b0f5e2817 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -188,9 +188,10 @@ GameList detectAllGames( return detectedGames; } -int detectBestMatchingGame( +const ADGameDescription *detectBestMatchingGame( const Common::ADParams ¶ms ) { + const ADGameDescription *agdDesc = 0; Common::Language language = Common::UNK_LANG; Common::Platform platform = Common::kPlatformUnknown; @@ -203,24 +204,23 @@ int detectBestMatchingGame( 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 @@ static ADList detectGame(const FSList *fslist, const Common::ADParams ¶ms, L 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 @@ static ADList detectGame(const FSList *fslist, const Common::ADParams ¶ms, L matchEntry = entryStart; maxFiles = matchFiles; - debug(4, "and overrided"); + debug(4, "and overriden"); } ptr++; @@ -515,6 +517,8 @@ static ADList detectGame(const FSList *fslist, const Common::ADParams ¶ms, L 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 @@ static ADList detectGame(const FSList *fslist, const Common::ADParams ¶ms, L } } } - +/* + // 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; } diff --git a/common/advancedDetector.h b/common/advancedDetector.h index 592b019c9b..799c796d3f 100644 --- a/common/advancedDetector.h +++ b/common/advancedDetector.h @@ -120,7 +120,7 @@ struct ADParams { const PlainGameDescriptor *list; /** - * Structure for autoupgrading obsolete targets (optional) + * Structure for autoupgrading obsolete targets (optional). * * @todo Properly explain this. */ @@ -134,13 +134,31 @@ struct ADParams { 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 @@ GameList gameIDList(const Common::ADParams ¶ms); * 'gameid' in there. If a match is found, returns a GameDescriptor * with gameid and description set. */ -GameDescriptor findGameID( - const char *gameid, - const Common::ADParams ¶ms - ); - +GameDescriptor findGameID(const char *gameid, const Common::ADParams ¶ms); // FIXME/TODO: Rename this function to something more sensible. -GameList detectAllGames( - const FSList &fslist, - const Common::ADParams ¶ms - ); - +GameList detectAllGames(const FSList &fslist, const Common::ADParams ¶ms); // FIXME/TODO: Rename this function to something more sensible. -int detectBestMatchingGame( - const Common::ADParams ¶ms - ); +const ADGameDescription *detectBestMatchingGame(const Common::ADParams ¶ms); // FIXME/TODO: Rename this function to something more sensible. void upgradeTargetIfNecessary(const Common::ADParams ¶ms); // FIXME/TODO: Rename this function to something more sensible. -PluginError detectGameForEngineCreation( - const Common::ADParams ¶ms - ); +PluginError detectGameForEngineCreation(const Common::ADParams ¶ms); // FIXME: It would probably be good to merge detectBestMatchingGame diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index 96e74d2da7..920ef287ce 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -1741,6 +1741,8 @@ static const Common::ADParams detectionParams = { "agi", // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags Common::kADFlagAugmentPreferredTarget }; @@ -1752,12 +1754,8 @@ REGISTER_PLUGIN(AGI, "AGI v2 + v3 Engine", "Sierra AGI Engine (C) Sierra On-Line 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 diff --git a/engines/agos/game.cpp b/engines/agos/game.cpp index 6df5a1a7a5..e0e60c43a2 100644 --- a/engines/agos/game.cpp +++ b/engines/agos/game.cpp @@ -96,6 +96,8 @@ static const Common::ADParams detectionParams = { 0, // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags Common::kADFlagAugmentPreferredTarget }; @@ -107,12 +109,8 @@ REGISTER_PLUGIN(AGOS, "AGOS", "AGOS (C) Adventure Soft"); 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); } diff --git a/engines/cine/detection.cpp b/engines/cine/detection.cpp index ad5f917e91..7edb196d02 100644 --- a/engines/cine/detection.cpp +++ b/engines/cine/detection.cpp @@ -480,6 +480,8 @@ static const Common::ADParams detectionParams = { "cine", // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags Common::kADFlagAugmentPreferredTarget }; @@ -491,12 +493,8 @@ REGISTER_PLUGIN(CINE, "Cinematique evo 1 engine", "Future Wars & Operation Steal 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 diff --git a/engines/gob/detection.cpp b/engines/gob/detection.cpp index 7140892787..8dca4c4eb7 100644 --- a/engines/gob/detection.cpp +++ b/engines/gob/detection.cpp @@ -913,6 +913,8 @@ static const ADParams detectionParams = { "gob", // List of files for file-based fallback detection (optional) Gob::fileBased, + // Fallback callback + 0, // Flags kADFlagAugmentPreferredTarget }; @@ -925,25 +927,27 @@ REGISTER_PLUGIN(GOB, "Gob Engine", "Goblins Games (C) Coktel Vision"); 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; } diff --git a/engines/kyra/plugin.cpp b/engines/kyra/plugin.cpp index 0fdf766cc9..25b7df4ae4 100644 --- a/engines/kyra/plugin.cpp +++ b/engines/kyra/plugin.cpp @@ -97,6 +97,8 @@ const Common::ADParams detectionParams = { 0, // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags 0 }; @@ -119,19 +121,16 @@ PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) { 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) { diff --git a/engines/parallaction/detection.cpp b/engines/parallaction/detection.cpp index 23db8c0597..dd8c3706ff 100644 --- a/engines/parallaction/detection.cpp +++ b/engines/parallaction/detection.cpp @@ -94,6 +94,8 @@ static const Common::ADParams detectionParams = { "parallaction", // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags Common::kADFlagAugmentPreferredTarget }; @@ -106,10 +108,8 @@ REGISTER_PLUGIN(PARALLACTION, "Parallaction engine", "Nippon Safes Inc. (C) Dyna 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 diff --git a/engines/saga/game.cpp b/engines/saga/game.cpp index ca3e4ddfca..820331b9c7 100644 --- a/engines/saga/game.cpp +++ b/engines/saga/game.cpp @@ -115,6 +115,8 @@ static const Common::ADParams detectionParams = { "saga", // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags Common::kADFlagAugmentPreferredTarget }; @@ -126,12 +128,10 @@ REGISTER_PLUGIN(SAGA, "SAGA Engine", "Inherit the Earth (C) Wyrmkeep Entertainme 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; diff --git a/engines/touche/plugin.cpp b/engines/touche/plugin.cpp index 3749a73027..5bd94d69d3 100644 --- a/engines/touche/plugin.cpp +++ b/engines/touche/plugin.cpp @@ -108,6 +108,8 @@ static const Common::ADParams detectionParams = { "touche", // List of files for file-based fallback detection (optional) 0, + // Fallback callback + 0, // Flags 0 }; @@ -119,11 +121,11 @@ REGISTER_PLUGIN(TOUCHE, "Touche Engine", "Touche: The Adventures of the 5th Musk 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; } -- cgit v1.2.3