aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEugene Sandulenko2006-11-10 22:43:10 +0000
committerEugene Sandulenko2006-11-10 22:43:10 +0000
commita977988058676dbf878637f41982d85db2fbd720 (patch)
treedc89b39d5464fb39c2daae160c42b5d584323cd0 /common
parent588a6842c818ef98e2b29b82991d9727a3e4a73e (diff)
downloadscummvm-rg350-a977988058676dbf878637f41982d85db2fbd720.tar.gz
scummvm-rg350-a977988058676dbf878637f41982d85db2fbd720.tar.bz2
scummvm-rg350-a977988058676dbf878637f41982d85db2fbd720.zip
Next step in AdvancedDetector unification. Moved all common functions to
macroses. Now typical usage is just list of macros with parameters and array of game details. svn-id: r24670
Diffstat (limited to 'common')
-rw-r--r--common/advancedDetector.cpp4
-rw-r--r--common/advancedDetector.h183
2 files changed, 187 insertions, 0 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp
index 3773c54c7a..b2107b85f2 100644
--- a/common/advancedDetector.cpp
+++ b/common/advancedDetector.cpp
@@ -30,6 +30,10 @@
namespace Common {
+bool ADTrue() {
+ return true;
+}
+
AdvancedDetector::AdvancedDetector() {
_fileMD5Bytes = 0;
}
diff --git a/common/advancedDetector.h b/common/advancedDetector.h
index 6d7ce23e3b..11d8a32e9b 100644
--- a/common/advancedDetector.h
+++ b/common/advancedDetector.h
@@ -41,9 +41,192 @@ struct ADGameDescription {
Platform platform;
};
+struct ADObsoleteGameID {
+ const char *from;
+ const char *to;
+ Common::Platform platform;
+};
+
+bool ADTrue(void);
+
typedef Array<int> ADList;
typedef Array<const ADGameDescription*> ADGameDescList;
+#define ADVANCED_DETECTOR_GAMEID_LIST(engine,list) \
+ GameList Engine_##engine##_gameIDList() { \
+ GameList games; \
+ const PlainGameDescriptor *g = list; \
+ while (g->gameid) { \
+ games.push_back(*g); \
+ g++; \
+ } \
+ \
+ return games; \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+#define ADVANCED_DETECTOR_FIND_GAMEID(engine,list,obsoleteList) \
+ GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
+ const PlainGameDescriptor *g = list; \
+ while (g->gameid) { \
+ if (0 == scumm_stricmp(gameid, g->gameid)) \
+ break; \
+ g++; \
+ } \
+ \
+ GameDescriptor gs; \
+ if (obsoleteList) {\
+ const Common::ADObsoleteGameID *o = obsoleteList; \
+ while (o->from) { \
+ if (0 == scumm_stricmp(gameid, o->from)) { \
+ gs.gameid = gameid; \
+ gs.description = "Obsolete game ID"; \
+ return gs; \
+ } \
+ o++; \
+ } \
+ } else \
+ return *g; \
+ return gs; \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+#define ADVANCED_DETECTOR_DETECT_GAMES(engine,function) \
+ DetectedGameList Engine_##engine##_detectGames(const FSList &fslist) { \
+ return function(fslist); \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+
+#define ADVANCED_DETECTOR_ENGINE_CREATE(engine,createFunction,engineName,obsoleteList) \
+ PluginError Engine_##engine##_create(OSystem *syst, Engine **engine) { \
+ assert(syst); \
+ assert(engine); \
+ const char *gameid = ConfMan.get("gameid").c_str(); \
+ \
+ if (obsoleteList) { \
+ for (const Common::ADObsoleteGameID *o = obsoleteList; o->from; ++o) { \
+ if (!scumm_stricmp(gameid, o->from)) { \
+ gameid = o->to; \
+ ConfMan.set("gameid", o->to); \
+ \
+ if (o->platform != Common::kPlatformUnknown) \
+ ConfMan.set("platform", Common::getPlatformCode(o->platform)); \
+ \
+ warning("Target upgraded from %s to %s", o->from, o->to); \
+ ConfMan.flushToDisk(); \
+ break; \
+ } \
+ } \
+ } \
+ \
+ FSList fslist; \
+ FilesystemNode dir(ConfMan.get("path")); \
+ if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { \
+ warning("%s: invalid game path '%s'", engineName, dir.path().c_str()); \
+ return kInvalidPathError; \
+ } \
+ \
+ DetectedGameList detectedGames = Engine_##engine##_detectGames(fslist); \
+ \
+ for (uint i = 0; i < detectedGames.size(); i++) { \
+ if (detectedGames[i].gameid == gameid) { \
+ *engine = new createFunction(syst); \
+ return kNoError; \
+ } \
+ } \
+ \
+ warning("%s: Unable to locate game data at path '%s'", engineName, dir.path().c_str()); \
+ return kNoGameDataFoundError; \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+#define ADVANCED_DETECTOR_TO_DETECTED_GAME(list) \
+ DetectedGame toDetectedGame(const ADGameDescription &g) { \
+ const char *title = 0; \
+ \
+ const PlainGameDescriptor *sg = list; \
+ while (sg->gameid) { \
+ if (!scumm_stricmp(g.name, sg->gameid)) \
+ title = sg->description; \
+ sg++; \
+ } \
+ \
+ DetectedGame dg(g.name, title, g.language, g.platform); \
+ dg.updateDesc(g.extra); \
+ return dg; \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+#define ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(function,descriptions) \
+ DetectedGameList function(const FSList &fslist) { \
+ DetectedGameList detectedGames; \
+ Common::AdvancedDetector AdvDetector; \
+ Common::ADList matches; \
+ Common::ADGameDescList descList; \
+ \
+ for (int i = 0; i < ARRAYSIZE(descriptions); i++) \
+ descList.push_back((const ADGameDescription *)&descriptions[i]); \
+ \
+ AdvDetector.registerGameDescriptions(descList); \
+ AdvDetector.setFileMD5Bytes(FILE_MD5_BYTES); \
+ \
+ matches = AdvDetector.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown); \
+ \
+ for (uint i = 0; i < matches.size(); i++) \
+ detectedGames.push_back(toDetectedGame(descriptions[matches[i]].desc)); \
+ \
+ return detectedGames; \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+#define ADVANCED_DETECTOR_DETECT_INIT_GAME(function,descriptions,varname,postFunction) \
+ bool function() { \
+ int gameNumber = -1; \
+ \
+ DetectedGameList detectedGames; \
+ Common::AdvancedDetector AdvDetector; \
+ Common::ADList matches; \
+ Common::ADGameDescList descList; \
+ \
+ Common::Language language = Common::UNK_LANG; \
+ Common::Platform platform = Common::kPlatformUnknown; \
+ \
+ if (ConfMan.hasKey("language")) \
+ language = Common::parseLanguage(ConfMan.get("language")); \
+ if (ConfMan.hasKey("platform")) \
+ platform = Common::parsePlatform(ConfMan.get("platform")); \
+ \
+ Common::String gameid = ConfMan.get("gameid"); \
+ \
+ for (int i = 0; i < ARRAYSIZE(descriptions); i++) \
+ descList.push_back((const ADGameDescription *)&descriptions[i]); \
+ \
+ AdvDetector.registerGameDescriptions(descList); \
+ AdvDetector.setFileMD5Bytes(FILE_MD5_BYTES); \
+ \
+ matches = AdvDetector.detectGame(NULL, language, platform); \
+ \
+ for (uint i = 0; i < matches.size(); i++) { \
+ if (toDetectedGame(descriptions[matches[i]].desc).gameid == gameid) { \
+ gameNumber = matches[i]; \
+ break; \
+ } \
+ } \
+ \
+ if (gameNumber >= ARRAYSIZE(descriptions) || gameNumber == -1) { \
+ error("%s wrong gameNumber", "##function##"); \
+ } \
+ \
+ debug(2, "Running %s", toDetectedGame(descriptions[gameNumber].desc).description.c_str()); \
+ \
+ varname = &descriptions[gameNumber]; \
+ \
+ return postFunction(); \
+ } \
+ void dummyFuncToAllowTrailingSemicolon()
+
+
class AdvancedDetector {
public: