aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2007-01-24 22:24:52 +0000
committerEugene Sandulenko2007-01-24 22:24:52 +0000
commitedd2422a55caeb5a46ee240feaea70a5aa4a4da2 (patch)
tree11c26d31c32895f734b2c7a9b177379e74d3cc24
parentdc8dde1872e30182b178fb1a772d564a3fb696af (diff)
downloadscummvm-rg350-edd2422a55caeb5a46ee240feaea70a5aa4a4da2.tar.gz
scummvm-rg350-edd2422a55caeb5a46ee240feaea70a5aa4a4da2.tar.bz2
scummvm-rg350-edd2422a55caeb5a46ee240feaea70a5aa4a4da2.zip
Hide all AdvacedDetector parameters into a structure for easier maintenance
and extensibility svn-id: r25163
-rw-r--r--common/advancedDetector.cpp47
-rw-r--r--common/advancedDetector.h38
-rw-r--r--engines/agos/agosgame.cpp2
-rw-r--r--engines/agos/game.cpp39
-rw-r--r--engines/cine/detection.cpp43
-rw-r--r--engines/kyra/plugin.cpp30
-rw-r--r--engines/parallaction/detection.cpp44
7 files changed, 129 insertions, 114 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp
index ff46517e61..dbee275d2a 100644
--- a/common/advancedDetector.cpp
+++ b/common/advancedDetector.cpp
@@ -35,12 +35,12 @@ namespace Common {
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 @@ PluginError ADVANCED_DETECTOR_ENGINE_CREATE(
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 ADVANCED_DETECTOR_FIND_GAMEID(
}
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 @@ static GameDescriptor toGameDescriptor(const ADGameDescription &g, const PlainGa
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 @@ GameList ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(
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 @@ int ADVANCED_DETECTOR_DETECT_INIT_GAME(
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 @@ int ADVANCED_DETECTOR_DETECT_INIT_GAME(
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 @@ static String getDescription(const ADGameDescription *g) {
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 @@ ADList AdvancedDetector::detectGame(const FSList *fslist, int md5Bytes, Language
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 @@ ADList AdvancedDetector::detectGame(const FSList *fslist, int md5Bytes, Language
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]);
}
diff --git a/common/advancedDetector.h b/common/advancedDetector.h
index 8bf347884c..5623cbf76e 100644
--- a/common/advancedDetector.h
+++ b/common/advancedDetector.h
@@ -50,6 +50,19 @@ struct ADObsoleteGameID {
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 @@ public:
* @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 @@ private:
// 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 @@ GameDescriptor ADVANCED_DETECTOR_FIND_GAMEID(
// 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 ADVANCED_DETECTOR_ENGINE_CREATE(
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; \
diff --git a/engines/agos/agosgame.cpp b/engines/agos/agosgame.cpp
index fa62a85b3c..cdc16d916b 100644
--- a/engines/agos/agosgame.cpp
+++ b/engines/agos/agosgame.cpp
@@ -1,5 +1,3 @@
-#define FILE_MD5_BYTES 5000
-
static const AGOSGameDescription gameDescriptions[] = {
// Elvira 1 - English Amiga Floppy
{
diff --git a/engines/agos/game.cpp b/engines/agos/game.cpp
index d2e0e496c9..263dfa9e7c 100644
--- a/engines/agos/game.cpp
+++ b/engines/agos/game.cpp
@@ -79,33 +79,40 @@ static const PlainGameDescriptor simonGames[] = {
{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(
- (const byte *)gameDescriptions,
- sizeof(AGOSGameDescription),
- FILE_MD5_BYTES,
- simonGames
- );
+ 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(AGOSGameDescription),
- FILE_MD5_BYTES,
- simonGames
- );
+ return Common::ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(fslist, detectionParams);
}
int AGOSEngine::getGameId() const {
diff --git a/engines/cine/detection.cpp b/engines/cine/detection.cpp
index f4bbcd58dc..176378de3d 100644
--- a/engines/cine/detection.cpp
+++ b/engines/cine/detection.cpp
@@ -54,14 +54,8 @@ static const PlainGameDescriptor cineGames[] = {
{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 @@ static const CINEGameDescription gameDescriptions[] = {
{ { 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
diff --git a/engines/kyra/plugin.cpp b/engines/kyra/plugin.cpp
index 0f48af6f75..6211987db0 100644
--- a/engines/kyra/plugin.cpp
+++ b/engines/kyra/plugin.cpp
@@ -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 @@ const PlainGameDescriptor gameList[] = {
{ 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 @@ GameList Engine_KYRA_gameIDList() {
}
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 @@ PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) {
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;
diff --git a/engines/parallaction/detection.cpp b/engines/parallaction/detection.cpp
index d3faefe31c..06aedd483a 100644
--- a/engines/parallaction/detection.cpp
+++ b/engines/parallaction/detection.cpp
@@ -51,15 +51,8 @@ static const PlainGameDescriptor parallactionGames[] = {
{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 @@ static const PARALLACTIONGameDescription gameDescriptions[] = {
{ { 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