Advanced Detector: Changed fallback detector from a callback function pointer to an overrideable method of AdvancedMetaEngine
svn-id: r31119
This commit is contained in:
parent
1e6f59e2dc
commit
8a9a14002e
14 changed files with 48 additions and 66 deletions
|
@ -34,6 +34,8 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
using namespace AdvancedDetector;
|
||||
|
||||
namespace AdvancedDetector {
|
||||
|
||||
// FIXME/TODO: Rename this function to something more sensible.
|
||||
|
@ -209,16 +211,15 @@ static void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *
|
|||
desc["extra"] = realDesc->extra;
|
||||
}
|
||||
|
||||
GameList detectAllGames(
|
||||
const FSList &fslist,
|
||||
const Common::ADParams ¶ms
|
||||
) {
|
||||
} // End of namespace AdvancedDetector
|
||||
|
||||
GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const {
|
||||
ADGameDescList matches = detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, "");
|
||||
GameList detectedGames;
|
||||
|
||||
// Use fallback detector if there were no matches by other means
|
||||
if (matches.empty() && params.fallbackDetectFunc != NULL) {
|
||||
EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(&fslist);
|
||||
if (matches.empty()) {
|
||||
EncapsulatedADGameDesc fallbackDesc = fallbackDetect(&fslist);
|
||||
if (fallbackDesc.realDesc != 0) {
|
||||
GameDescriptor desc(toGameDescriptor(fallbackDesc, params.list));
|
||||
updateGameDescriptor(desc, fallbackDesc.realDesc, params);
|
||||
|
@ -233,9 +234,10 @@ GameList detectAllGames(
|
|||
return detectedGames;
|
||||
}
|
||||
|
||||
EncapsulatedADGameDesc detectBestMatchingGame(
|
||||
const Common::ADParams ¶ms
|
||||
) {
|
||||
PluginError AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
|
||||
assert(engine);
|
||||
Common::AdvancedDetector::upgradeTargetIfNecessary(params);
|
||||
|
||||
const ADGameDescription *agdDesc = 0;
|
||||
EncapsulatedADGameDesc result;
|
||||
Common::Language language = Common::UNK_LANG;
|
||||
|
@ -267,8 +269,9 @@ EncapsulatedADGameDesc detectBestMatchingGame(
|
|||
|
||||
if (agdDesc != 0) { // Check if we found a match without fallback detection
|
||||
result = EncapsulatedADGameDesc(agdDesc);
|
||||
} else if (params.fallbackDetectFunc != NULL) { // Use fallback detector if there were no matches by other means
|
||||
EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(NULL);
|
||||
} else {
|
||||
// Use fallback detector if there were no matches by other means
|
||||
EncapsulatedADGameDesc fallbackDesc = fallbackDetect(NULL);
|
||||
if (fallbackDesc.realDesc != 0 && (params.singleid != NULL || fallbackDesc.getGameID() == gameid)) {
|
||||
result = fallbackDesc; // Found a fallback match
|
||||
}
|
||||
|
@ -278,8 +281,16 @@ EncapsulatedADGameDesc detectBestMatchingGame(
|
|||
debug(2, "Running %s", toGameDescriptor(result, params.list).description().c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
if (result.realDesc == 0) {
|
||||
return kNoGameDataFoundError;
|
||||
}
|
||||
if (!createInstance(syst, engine, result)) {
|
||||
return kNoGameDataFoundError;
|
||||
}
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
namespace AdvancedDetector {
|
||||
|
||||
void reportUnknown(StringMap &filesMD5, HashMap<String, int32, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> &filesSize) {
|
||||
// TODO: This message should be cleaned up / made more specific.
|
||||
|
@ -571,21 +582,5 @@ GameList AdvancedMetaEngine::getSupportedGames() const {
|
|||
GameDescriptor AdvancedMetaEngine::findGame(const char *gameid) const {
|
||||
return Common::AdvancedDetector::findGameID(gameid, params.list, params.obsoleteList);
|
||||
}
|
||||
GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const {
|
||||
return Common::AdvancedDetector::detectAllGames(fslist, params);
|
||||
}
|
||||
|
||||
PluginError AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
|
||||
assert(engine);
|
||||
Common::AdvancedDetector::upgradeTargetIfNecessary(params);
|
||||
Common::EncapsulatedADGameDesc encapsulatedDesc = Common::AdvancedDetector::detectBestMatchingGame(params);
|
||||
if (encapsulatedDesc.realDesc == 0) {
|
||||
return kNoGameDataFoundError;
|
||||
}
|
||||
if (!createInstance(syst,engine,encapsulatedDesc)) {
|
||||
return kNoGameDataFoundError;
|
||||
}
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
|
@ -67,6 +67,8 @@ struct ADGameDescription {
|
|||
/**
|
||||
* Encapsulates ADGameDescription and makes gameid and extra strings dynamic.
|
||||
* Used in fallback detection when dynamically creating string content.
|
||||
*
|
||||
* @todo Get rid of this once the fallback detection is a member of AdvancedMetaEngine.
|
||||
*/
|
||||
struct EncapsulatedADGameDesc {
|
||||
Common::String gameid;
|
||||
|
@ -76,8 +78,8 @@ struct EncapsulatedADGameDesc {
|
|||
// Constructor for the EncapsulatedADGameDesc
|
||||
EncapsulatedADGameDesc() : realDesc(0) {}
|
||||
EncapsulatedADGameDesc(const ADGameDescription *paramRealDesc,
|
||||
Common::String paramGameID = Common::String(""),
|
||||
Common::String paramExtra = Common::String(""))
|
||||
Common::String paramGameID = Common::String(),
|
||||
Common::String paramExtra = Common::String())
|
||||
: realDesc(paramRealDesc), gameid(paramGameID), extra(paramExtra) {
|
||||
assert(paramRealDesc != NULL);
|
||||
}
|
||||
|
@ -192,20 +194,6 @@ struct ADParams {
|
|||
*/
|
||||
const ADFileBasedFallback *fileBasedFallback;
|
||||
|
||||
/**
|
||||
* A callback pointing to an (optional) generic fallback detect
|
||||
* function. If present, this callback is invoked if both the regular
|
||||
* MD5 based detection as well as the file based fallback failed
|
||||
* to detect anything.
|
||||
*
|
||||
* @note The fslist parameter may be 0 -- in that case, it is assumed
|
||||
* that the callback searchs the current directory.
|
||||
*
|
||||
* @todo Change this to a member method of AdvancedMetaEngine which can
|
||||
* be overriden via subclassing.
|
||||
*/
|
||||
EncapsulatedADGameDesc (*fallbackDetectFunc)(const FSList *fslist);
|
||||
|
||||
/**
|
||||
* A bitmask of flags which can be used to configure the behavior
|
||||
* of the AdvancedDetector. Refer to ADFlags for a list of flags
|
||||
|
@ -245,6 +233,19 @@ public:
|
|||
|
||||
// To be provided by subclasses
|
||||
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* An (optional) generic fallback detect function which is invoked
|
||||
* if both the regular MD5 based detection as well as the file
|
||||
* based fallback failed to detect anything.
|
||||
*
|
||||
* @note The fslist parameter may be 0 -- in that case, it is assumed
|
||||
* that the callback searchs the current directory.
|
||||
*/
|
||||
EncapsulatedADGameDesc fallbackDetect(const FSList *fslist) const {
|
||||
return EncapsulatedADGameDesc();
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
|
@ -2255,8 +2255,6 @@ static const Common::ADParams detectionParams = {
|
|||
"agi",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
Agi::fallbackDetector,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
@ -2273,6 +2271,10 @@ public:
|
|||
}
|
||||
|
||||
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const;
|
||||
|
||||
Common::EncapsulatedADGameDesc fallbackDetect(const FSList *fslist) const {
|
||||
return Agi::fallbackDetector(fslist);
|
||||
}
|
||||
};
|
||||
|
||||
bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const {
|
||||
|
|
|
@ -93,8 +93,6 @@ static const Common::ADParams detectionParams = {
|
|||
0,
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -482,8 +482,6 @@ static const Common::ADParams detectionParams = {
|
|||
"cine",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -117,8 +117,6 @@ static const Common::ADParams detectionParams = {
|
|||
"cruise",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -157,8 +157,6 @@ static const Common::ADParams detectionParams = {
|
|||
"drascula",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
Drascula::fallbackDetector,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
@ -176,6 +174,10 @@ public:
|
|||
}
|
||||
|
||||
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const;
|
||||
|
||||
Common::EncapsulatedADGameDesc fallbackDetect(const FSList *fslist) const {
|
||||
return Drascula::fallbackDetector(fslist);
|
||||
}
|
||||
};
|
||||
|
||||
bool DrasculaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const {
|
||||
|
|
|
@ -1853,8 +1853,6 @@ static const ADParams detectionParams = {
|
|||
"gob",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
Gob::fileBased,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -101,7 +101,6 @@ static const Common::ADParams igorDetectionParams = {
|
|||
0,
|
||||
"igor",
|
||||
0,
|
||||
0,
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
||||
|
|
|
@ -422,8 +422,6 @@ const Common::ADParams detectionParams = {
|
|||
0,
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
0
|
||||
};
|
||||
|
|
|
@ -168,8 +168,6 @@ static const Common::ADParams detectionParams = {
|
|||
"lure",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget | Common::kADFlagUseExtraAsHint
|
||||
};
|
||||
|
|
|
@ -178,8 +178,6 @@ static const Common::ADParams detectionParams = {
|
|||
"parallaction",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -135,8 +135,6 @@ static const Common::ADParams detectionParams = {
|
|||
"saga",
|
||||
// List of files for file-based fallback detection (optional)
|
||||
0,
|
||||
// Fallback callback
|
||||
0,
|
||||
// Flags
|
||||
Common::kADFlagAugmentPreferredTarget
|
||||
};
|
||||
|
|
|
@ -120,7 +120,6 @@ static const Common::ADParams detectionParams = {
|
|||
0, // no obsolete targets data
|
||||
"touche",
|
||||
Touche::fileBasedFallback, // file-based detection data to enable not yet known versions to start
|
||||
0, // no fallback callback
|
||||
Common::kADFlagAugmentPreferredTarget | Common::kADFlagPrintWarningOnFileBasedFallback
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue