[Scummvm-git-logs] scummvm master -> 2564ce272a8f5c1c0510764af0a51bc64122c03c

sev- noreply at scummvm.org
Mon Nov 29 00:57:39 UTC 2021


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
55dc78960b AD: Refactor of graylist check code
ccfaf478ab AD: Make sure that we initialize hashmaps. Unfortunately, this leads to less const'ness
2564ce272a AD: Use hashmap for directory globs.


Commit: 55dc78960b0d5fffc811ce589bb834443befb069
    https://github.com/scummvm/scummvm/commit/55dc78960b0d5fffc811ce589bb834443befb069
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-11-29T01:50:03+01:00

Commit Message:
AD: Refactor of graylist check code

Changed paths:
    engines/advancedDetector.cpp
    engines/advancedDetector.h


diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index 5b9e9f06ab..11c27ff3a1 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -577,7 +577,7 @@ ADDetectedGames AdvancedMetaEngineDetection::detectGame(const Common::FSNode &pa
 
 	debugC(3, kDebugGlobalDetection, "Starting detection for engine '%s' in dir '%s'", getEngineId(), parent.getPath().c_str());
 
-	sanityCheck();
+	preprocessDescriptions();
 
 	// Check which files are included in some ADGameDescription *and* whether
 	// they are present. Compute MD5s and file sizes for the available files.
@@ -667,7 +667,7 @@ ADDetectedGames AdvancedMetaEngineDetection::detectGame(const Common::FSNode &pa
 		// cases.
 		if (allFilesPresent && !gotAnyMatchesWithAllFiles) {
 			// Do sanity check
-			if (game.hasUnknownFiles && !sanityCheckEntry(g)) {
+			if (game.hasUnknownFiles && isEntryGrayListed(g)) {
 				debugC(3, kDebugGlobalDetection, "Skipping game: %s (%s %s/%s) (%d), didn't pass sanity", g->gameId, g->extra,
 					getPlatformDescription(g->platform), getLanguageDescription(g->language), i);
 
@@ -768,7 +768,7 @@ PlainGameDescriptor AdvancedMetaEngineDetection::findGame(const char *gameId) co
 	return PlainGameDescriptor::empty();
 }
 
-static const char *blackList[] = {
+static const char *grayList[] = {
 	"game.exe",
 	"demo.exe",
 	"game",
@@ -794,8 +794,8 @@ AdvancedMetaEngineDetection::AdvancedMetaEngineDetection(const void *descs, uint
 	_matchFullPaths = false;
 	_maxAutogenLength = 15;
 
-	for (auto f = blackList; *f; f++)
-		_blackListMap.setVal(*f, true);
+	for (auto f = grayList; *f; f++)
+		_grayListMap.setVal(*f, true);
 }
 
 void AdvancedMetaEngineDetection::initSubSystems(const ADGameDescription *gameDesc) const {
@@ -806,40 +806,30 @@ void AdvancedMetaEngineDetection::initSubSystems(const ADGameDescription *gameDe
 #endif
 }
 
-void AdvancedMetaEngineDetection::sanityCheck() const {
+void AdvancedMetaEngineDetection::preprocessDescriptions() const {
 	// Check if the detection entries have only files from the blacklist
 	for (const byte *descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != nullptr; descPtr += _descItemSize) {
 		const ADGameDescription *g = (const ADGameDescription *)descPtr;
 
-		bool blackIsPresent = false, nonBlackIsPresent = false;
-
-		for (const ADGameFileDescription *fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
-			if (_blackListMap.contains(fileDesc->fileName)) {
-				blackIsPresent = true;
-			} else {
-				nonBlackIsPresent = true;
-			}
-		}
-
-		if (blackIsPresent && !nonBlackIsPresent) {
+		if (isEntryGrayListed(g)) {
 			debug(0, "WARNING: Detection entry for '%s' in engine '%s' contains only blacklisted names. Add more files to the entry (%s)",
 				g->gameId, getEngineId(), g->filesDescriptions[0].md5);
 		}
 	}
 }
 
-bool AdvancedMetaEngineDetection::sanityCheckEntry(const ADGameDescription *g) const {
-	bool blackIsPresent = false, nonBlackIsPresent = false;
+bool AdvancedMetaEngineDetection::isEntryGrayListed(const ADGameDescription *g) const {
+	bool grayIsPresent = false, nonGrayIsPresent = false;
 
 	for (const ADGameFileDescription *fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
-		if (_blackListMap.contains(fileDesc->fileName)) {
-			blackIsPresent = true;
+		if (_grayListMap.contains(fileDesc->fileName)) {
+			grayIsPresent = true;
 		} else {
-			nonBlackIsPresent = true;
+			nonGrayIsPresent = true;
 		}
 	}
 
-	return !(blackIsPresent && !nonBlackIsPresent);
+	return (grayIsPresent && !nonGrayIsPresent);
 }
 
 Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index 8e66e153c4..d37ead7424 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -399,11 +399,11 @@ protected:
 
 private:
 	void initSubSystems(const ADGameDescription *gameDesc) const;
-	void sanityCheck() const;
-	bool sanityCheckEntry(const ADGameDescription *g) const;
+	void preprocessDescriptions() const;
+	bool isEntryGrayListed(const ADGameDescription *g) const;
 
 private:
-	Common::HashMap<Common::String, bool, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _blackListMap;
+	Common::HashMap<Common::String, bool, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _grayListMap;
 
 protected:
 	/**


Commit: ccfaf478ab31ba7645721ea92aeda06fb68bd744
    https://github.com/scummvm/scummvm/commit/ccfaf478ab31ba7645721ea92aeda06fb68bd744
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-11-29T01:50:03+01:00

Commit Message:
AD: Make sure that we initialize hashmaps. Unfortunately, this leads to less const'ness

Changed paths:
    base/plugins.cpp
    engines/adl/detection.cpp
    engines/advancedDetector.cpp
    engines/advancedDetector.h
    engines/agos/metaengine.cpp
    engines/ags/detection.cpp
    engines/ags/detection.h
    engines/glk/detection.cpp
    engines/glk/detection.h
    engines/glk/metaengine.cpp
    engines/grim/metaengine.cpp
    engines/metaengine.h
    engines/scumm/detection.cpp
    engines/scumm/metaengine.cpp
    engines/scumm/metaengine.h
    engines/sky/detection.cpp
    engines/sky/metaengine.cpp
    engines/sword1/detection.cpp
    engines/sword1/metaengine.cpp
    engines/sword2/detection.cpp
    engines/sword2/metaengine.cpp


diff --git a/base/plugins.cpp b/base/plugins.cpp
index f012e569bd..ded732e382 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -718,7 +718,7 @@ QualifiedGameList EngineManager::findGameInLoadedPlugins(const Common::String &g
 	return results;
 }
 
-DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const {
+DetectionResults EngineManager::detectGames(const Common::FSList &fslist) {
 	DetectedGames candidates;
 	PluginList plugins;
 	PluginList::const_iterator iter;
@@ -733,7 +733,7 @@ DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const
 	// Iterate over all known games and for each check if it might be
 	// the game in the presented directory.
 	for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
-		const MetaEngineDetection &metaEngine = (*iter)->get<MetaEngineDetection>();
+		MetaEngineDetection &metaEngine = (*iter)->get<MetaEngineDetection>();
 		// set the debug flags
 		DebugMan.addAllDebugChannels(metaEngine.getDebugChannels());
 		DetectedGames engineCandidates = metaEngine.detectGames(fslist);
@@ -941,7 +941,7 @@ void EngineManager::upgradeTargetForEngineId(const Common::String &target) const
 		}
 
 		// Take the first detection entry
-		const MetaEngineDetection &metaEngine = plugin->get<MetaEngineDetection>();
+		MetaEngineDetection &metaEngine = plugin->get<MetaEngineDetection>();
 		// set debug flags before call detectGames
 		DebugMan.addAllDebugChannels(metaEngine.getDebugChannels());
 		DetectedGames candidates = metaEngine.detectGames(files);
diff --git a/engines/adl/detection.cpp b/engines/adl/detection.cpp
index 43cf5c717f..fb486d9246 100644
--- a/engines/adl/detection.cpp
+++ b/engines/adl/detection.cpp
@@ -479,7 +479,7 @@ public:
 		return debugFlagList;
 	}
 
-	ADDetectedGames detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const override;
+	ADDetectedGames detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) override;
 
 	bool addFileProps(const FileMap &allFiles, Common::String fname, FilePropertiesMap &filePropsMap) const;
 };
@@ -503,7 +503,7 @@ bool AdlMetaEngineDetection::addFileProps(const FileMap &allFiles, Common::Strin
 }
 
 // Based on AdvancedMetaEngine::detectGame
-ADDetectedGames AdlMetaEngineDetection::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const {
+ADDetectedGames AdlMetaEngineDetection::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) {
 	// We run the file-based detector first, if it finds a match we do not search for disk images
 	ADDetectedGames matched = AdvancedMetaEngineDetection::detectGame(parent, allFiles, language, platform, extra);
 
diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index 11c27ff3a1..bf6c3a685e 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -248,12 +248,16 @@ bool AdvancedMetaEngineDetection::cleanupPirated(ADDetectedGames &matched) const
 	return false;
 }
 
-DetectedGames AdvancedMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames AdvancedMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	FileMap allFiles;
 
 	if (fslist.empty())
 		return DetectedGames();
 
+	// Sometimes this method is called directly, so we have to build the maps, especially
+	// the _directoryGlobsMap
+	preprocessDescriptions();
+
 	// Compose a hashmap of all files in fslist.
 	composeFileHashMap(allFiles, fslist, (_maxScanDepth == 0 ? 1 : _maxScanDepth));
 
@@ -329,7 +333,7 @@ const ExtraGuiOptions AdvancedMetaEngineDetection::getExtraGuiOptions(const Comm
 	return options;
 }
 
-Common::Error AdvancedMetaEngineDetection::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error AdvancedMetaEngineDetection::createInstance(OSystem *syst, Engine **engine) {
 	assert(engine);
 
 	Common::Language language = Common::UNK_LANG;
@@ -364,6 +368,10 @@ Common::Error AdvancedMetaEngineDetection::createInstance(OSystem *syst, Engine
 	if (files.empty())
 		return Common::kNoGameDataFoundError;
 
+	// Sometimes this method is called directly, so we have to build the maps, especially
+	// the _directoryGlobsMap
+	preprocessDescriptions();
+
 	// Compose a hashmap of all files in fslist.
 	FileMap allFiles;
 	composeFileHashMap(allFiles, files, (_maxScanDepth == 0 ? 1 : _maxScanDepth));
@@ -567,7 +575,7 @@ static bool getFilePropertiesIntern(uint md5Bytes, const AdvancedMetaEngine::Fil
 	return true;
 }
 
-ADDetectedGames AdvancedMetaEngineDetection::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const {
+ADDetectedGames AdvancedMetaEngineDetection::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) {
 	FilePropertiesMap filesProps;
 	ADDetectedGames matched;
 
@@ -794,6 +802,8 @@ AdvancedMetaEngineDetection::AdvancedMetaEngineDetection(const void *descs, uint
 	_matchFullPaths = false;
 	_maxAutogenLength = 15;
 
+	_hashMapsInited = false;
+
 	for (auto f = grayList; *f; f++)
 		_grayListMap.setVal(*f, true);
 }
@@ -806,7 +816,12 @@ void AdvancedMetaEngineDetection::initSubSystems(const ADGameDescription *gameDe
 #endif
 }
 
-void AdvancedMetaEngineDetection::preprocessDescriptions() const {
+void AdvancedMetaEngineDetection::preprocessDescriptions() {
+	if (_hashMapsInited)
+		return;
+
+	_hashMapsInited = true;
+
 	// Check if the detection entries have only files from the blacklist
 	for (const byte *descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != nullptr; descPtr += _descItemSize) {
 		const ADGameDescription *g = (const ADGameDescription *)descPtr;
@@ -832,7 +847,7 @@ bool AdvancedMetaEngineDetection::isEntryGrayListed(const ADGameDescription *g)
 	return (grayIsPresent && !nonGrayIsPresent);
 }
 
-Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) {
 	PluginList pl = PluginMan.getPlugins(PLUGIN_TYPE_ENGINE);
 	if (pl.size() == 1) {
 		const Plugin *metaEnginePlugin = PluginMan.getMetaEngineFromEngine(pl[0]);
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index d37ead7424..0a4e0ccb89 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -357,7 +357,7 @@ public:
 	 * (possibly empty) list of games supported by the engine that were
 	 * found among the given files.
 	 */
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 
 	/**
 	 * A generic createInstance.
@@ -365,7 +365,7 @@ public:
 	 * For instantiating engine objects, this method is called first,
 	 * and then the subclass implemented createInstance is called from within.
 	 */
-	Common::Error createInstance(OSystem *syst, Engine **engine) const;
+	Common::Error createInstance(OSystem *syst, Engine **engine);
 
 	/**
 	 * Return a list of extra GUI options for the specified target.
@@ -399,11 +399,12 @@ protected:
 
 private:
 	void initSubSystems(const ADGameDescription *gameDesc) const;
-	void preprocessDescriptions() const;
+	void preprocessDescriptions();
 	bool isEntryGrayListed(const ADGameDescription *g) const;
 
 private:
 	Common::HashMap<Common::String, bool, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _grayListMap;
+	bool _hashMapsInited;
 
 protected:
 	/**
@@ -420,7 +421,7 @@ protected:
 	 *
 	 * @return A list of @ref ADGameDescription pointers corresponding to the matched games.
 	 */
-	virtual ADDetectedGames detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
+	virtual ADDetectedGames detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra);
 
 	/**
 	 * @return True if variant of a game with unknown files can be played with the engine and false otherwise.
@@ -473,7 +474,7 @@ public:
 	 * By the time this is called, it is assumed that there is only one
 	 * plugin engine loaded in memory.
 	 */
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 
 	/**
 	 * A createInstance implementation for subclasses. To be called after the base
diff --git a/engines/agos/metaengine.cpp b/engines/agos/metaengine.cpp
index d131083fb8..3bad6cd0e7 100644
--- a/engines/agos/metaengine.cpp
+++ b/engines/agos/metaengine.cpp
@@ -42,7 +42,7 @@ public:
 
 	bool hasFeature(MetaEngineFeature f) const override;
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override {
+	Common::Error createInstance(OSystem *syst, Engine **engine) override {
 		Engines::upgradeTargetIfNecessary(obsoleteGameIDsTable);
 		return AdvancedMetaEngine::createInstance(syst, engine);
 	}
diff --git a/engines/ags/detection.cpp b/engines/ags/detection.cpp
index 75e25dadde..2a10b1439c 100644
--- a/engines/ags/detection.cpp
+++ b/engines/ags/detection.cpp
@@ -76,7 +76,7 @@ AGSMetaEngineDetection::AGSMetaEngineDetection() : AdvancedMetaEngineDetection(A
 	        sizeof(AGS::AGSGameDescription), AGS::GAME_NAMES) {
 }
 
-DetectedGames AGSMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames AGSMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	FileMap allFiles;
 
 	if (fslist.empty())
diff --git a/engines/ags/detection.h b/engines/ags/detection.h
index f4078521aa..8cc35180ac 100644
--- a/engines/ags/detection.h
+++ b/engines/ags/detection.h
@@ -87,7 +87,7 @@ public:
 		return debugFlagList;
 	}
 
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 
 	ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist, ADDetectedGameExtraInfo **extra = nullptr) const override;
 
diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp
index a851107f07..955f172101 100644
--- a/engines/glk/detection.cpp
+++ b/engines/glk/detection.cpp
@@ -181,7 +181,7 @@ PlainGameDescriptor GlkMetaEngineDetection::findGame(const char *gameId) const {
 
 #undef FIND_GAME
 
-DetectedGames GlkMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames GlkMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 #ifndef RELEASE_BUILD
 	// This is as good a place as any to detect multiple sub-engines using the same Ids
 	detectClashes();
diff --git a/engines/glk/detection.h b/engines/glk/detection.h
index e4df7fcf26..1b2308318c 100644
--- a/engines/glk/detection.h
+++ b/engines/glk/detection.h
@@ -57,7 +57,7 @@ public:
 	 * (possibly empty) list of games supported by the engine which it was able
 	 * to detect amongst the given files.
 	 */
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 
 	/**
 	 * Query the engine for a PlainGameDescriptor for the specified gameid, if any.
diff --git a/engines/glk/metaengine.cpp b/engines/glk/metaengine.cpp
index 261275df28..97ed341189 100644
--- a/engines/glk/metaengine.cpp
+++ b/engines/glk/metaengine.cpp
@@ -81,7 +81,7 @@ public:
 	}
 
 	bool hasFeature(MetaEngineFeature f) const override;
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 
 	SaveStateList listSaves(const char *target) const override;
 	int getMaximumSaveSlot() const override;
@@ -144,7 +144,7 @@ Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) con
 	folder.getChildren(fslist, Common::FSNode::kListFilesOnly);
 
 	// Get the matching MetaEngine for this Engine.
-	const MetaEngineDetection &metaEngine = g_engine->getMetaEngineDetection();
+	MetaEngineDetection &metaEngine = g_engine->getMetaEngineDetection();
 
 	// Iterate over the files
 	for (Common::FSList::iterator i = fslist.begin(); i != fslist.end(); ++i) {
@@ -162,7 +162,7 @@ Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) con
 	return Common::String();
 }
 
-Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) {
 #ifndef RELEASE_BUILD
 	Glk::GameDescriptor td = Glk::GameDescriptor::empty();
 #endif
diff --git a/engines/grim/metaengine.cpp b/engines/grim/metaengine.cpp
index 6acbf0c32b..830453ac80 100644
--- a/engines/grim/metaengine.cpp
+++ b/engines/grim/metaengine.cpp
@@ -38,7 +38,7 @@ public:
 		return "grim";
 	}
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override {
+	Common::Error createInstance(OSystem *syst, Engine **engine) override {
 		Engines::upgradeTargetIfNecessary(obsoleteGameIDsTable);
 		return AdvancedMetaEngine::createInstance(syst, engine);
 	}
diff --git a/engines/metaengine.h b/engines/metaengine.h
index fa8bf3f17d..cac7340a7d 100644
--- a/engines/metaengine.h
+++ b/engines/metaengine.h
@@ -156,7 +156,7 @@ public:
 	 * (possibly empty) list of games supported by the engine that were
 	 * found among the given files.
 	 */
-	virtual DetectedGames detectGames(const Common::FSList &fslist) const = 0;
+	virtual DetectedGames detectGames(const Common::FSList &fslist) = 0;
 
 	/**
 	 * Return a list of extra GUI options for the specified target.
@@ -269,7 +269,7 @@ public:
 	 *
 	 * @return A Common::Error describing the error that occurred, or kNoError.
 	 */
-	virtual Common::Error createInstance(OSystem *syst, Engine **engine) const = 0;
+	virtual Common::Error createInstance(OSystem *syst, Engine **engine) = 0;
 
 	/**
 	 * Return a list of all save states associated with the given target.
@@ -576,7 +576,7 @@ public:
 	 *
 	 * Returns an empty list if none are found.
 	 */
-	DetectionResults detectGames(const Common::FSList &fslist) const;
+	DetectionResults detectGames(const Common::FSList &fslist);
 
 	/** Find a plugin by its engine ID. */
 	const Plugin *findPlugin(const Common::String &engineId) const;
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index d595d660f8..acbe5d1c41 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -83,7 +83,7 @@ public:
 
 	PlainGameList getSupportedGames() const override;
 	PlainGameDescriptor findGame(const char *gameid) const override;
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 
 	const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const override;
 };
@@ -122,7 +122,7 @@ static Common::String generatePreferredTarget(const DetectorResult &x) {
 	return res;
 }
 
-DetectedGames ScummMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames ScummMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	DetectedGames detectedGames;
 	Common::List<DetectorResult> results;
 	::detectGames(fslist, results, nullptr);
diff --git a/engines/scumm/metaengine.cpp b/engines/scumm/metaengine.cpp
index 8927ee1dd6..02a89c1f88 100644
--- a/engines/scumm/metaengine.cpp
+++ b/engines/scumm/metaengine.cpp
@@ -245,7 +245,7 @@ bool ScummEngine::hasFeature(EngineFeature f) const {
  *
  * This is heavily based on our MD5 detection scheme.
  */
-Common::Error ScummMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error ScummMetaEngine::createInstance(OSystem *syst, Engine **engine) {
 	assert(syst);
 	assert(engine);
 	const char *gameid = ConfMan.get("gameid").c_str();
diff --git a/engines/scumm/metaengine.h b/engines/scumm/metaengine.h
index 67cbaf9fc7..f6029bcc7c 100644
--- a/engines/scumm/metaengine.h
+++ b/engines/scumm/metaengine.h
@@ -30,7 +30,7 @@ class ScummMetaEngine : public MetaEngine {
 
 	bool hasFeature(MetaEngineFeature f) const override;
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 
 	SaveStateList listSaves(const char *target) const override;
 	int getMaximumSaveSlot() const override;
diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp
index b87c6cd003..33cff2331d 100644
--- a/engines/sky/detection.cpp
+++ b/engines/sky/detection.cpp
@@ -75,7 +75,7 @@ public:
 	PlainGameList getSupportedGames() const override;
 	const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const override;
 	PlainGameDescriptor findGame(const char *gameid) const override;
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 };
 
 const char *SkyMetaEngineDetection::getName() const {
@@ -117,7 +117,7 @@ PlainGameDescriptor SkyMetaEngineDetection::findGame(const char *gameid) const {
 	return PlainGameDescriptor::empty();
 }
 
-DetectedGames SkyMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames SkyMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	DetectedGames detectedGames;
 	bool hasSkyDsk = false;
 	bool hasSkyDnr = false;
diff --git a/engines/sky/metaengine.cpp b/engines/sky/metaengine.cpp
index c960fa29a7..0465fbbb1e 100644
--- a/engines/sky/metaengine.cpp
+++ b/engines/sky/metaengine.cpp
@@ -44,7 +44,7 @@ class SkyMetaEngine : public MetaEngine {
 
 	bool hasFeature(MetaEngineFeature f) const override;
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 
 	SaveStateList listSaves(const char *target) const override;
 	int getMaximumSaveSlot() const override;
@@ -142,7 +142,7 @@ Common::KeymapArray SkyMetaEngine::initKeymaps(const char *target) const {
 	return keymaps;
 }
 
-Common::Error SkyMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error SkyMetaEngine::createInstance(OSystem *syst, Engine **engine) {
 	assert(engine);
 	*engine = new Sky::SkyEngine(syst);
 	return Common::kNoError;
diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp
index e3127e3ea6..86289ee5c7 100644
--- a/engines/sword1/detection.cpp
+++ b/engines/sword1/detection.cpp
@@ -86,7 +86,7 @@ public:
 
 	PlainGameList getSupportedGames() const override;
 	PlainGameDescriptor findGame(const char *gameId) const override;
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 };
 
 PlainGameList SwordMetaEngineDetection::getSupportedGames() const {
@@ -133,7 +133,7 @@ void Sword1CheckDirectory(const Common::FSList &fslist, bool *filesFound) {
 	}
 }
 
-DetectedGames SwordMetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames SwordMetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	int i, j;
 	DetectedGames detectedGames;
 	bool filesFound[NUM_FILES_TO_CHECK];
diff --git a/engines/sword1/metaengine.cpp b/engines/sword1/metaengine.cpp
index ad436e7ea3..9b3ebf0bf6 100644
--- a/engines/sword1/metaengine.cpp
+++ b/engines/sword1/metaengine.cpp
@@ -44,7 +44,7 @@ public:
 	void removeSaveState(const char *target, int slot) const override;
 	SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 	Common::String getSavegameFile(int saveGameIdx, const char *target) const override {
 		if (saveGameIdx == kSavegameFilePattern)
 			return Common::String::format("sword1.###");
@@ -71,7 +71,7 @@ bool Sword1::SwordEngine::hasFeature(EngineFeature f) const {
 	    (f == kSupportsLoadingDuringRuntime);
 }
 
-Common::Error SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) {
 	assert(engine);
 	*engine = new Sword1::SwordEngine(syst);
 	return Common::kNoError;
diff --git a/engines/sword2/detection.cpp b/engines/sword2/detection.cpp
index 648ec6c9b4..6b40403fc5 100644
--- a/engines/sword2/detection.cpp
+++ b/engines/sword2/detection.cpp
@@ -52,7 +52,7 @@ public:
 	PlainGameList getSupportedGames() const override;
 	const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const override;
 	PlainGameDescriptor findGame(const char *gameid) const override;
-	DetectedGames detectGames(const Common::FSList &fslist) const override;
+	DetectedGames detectGames(const Common::FSList &fslist) override;
 };
 
 PlainGameList Sword2MetaEngineDetection::getSupportedGames() const {
@@ -81,7 +81,7 @@ PlainGameDescriptor Sword2MetaEngineDetection::findGame(const char *gameid) cons
 	return PlainGameDescriptor::of(g->gameid, g->description);
 }
 
-DetectedGames Sword2MetaEngineDetection::detectGames(const Common::FSList &fslist) const {
+DetectedGames Sword2MetaEngineDetection::detectGames(const Common::FSList &fslist) {
 	// The required game data files can be located in the game directory, or in
 	// a subdirectory called "clusters". In the latter case, we don't want to
 	// detect the game in that subdirectory, as this will detect the game twice
diff --git a/engines/sword2/metaengine.cpp b/engines/sword2/metaengine.cpp
index faf68d6ba9..499cc9c857 100644
--- a/engines/sword2/metaengine.cpp
+++ b/engines/sword2/metaengine.cpp
@@ -48,7 +48,7 @@ public:
 	int getMaximumSaveSlot() const override;
 	void removeSaveState(const char *target, int slot) const override;
 
-	Common::Error createInstance(OSystem *syst, Engine **engine) const override;
+	Common::Error createInstance(OSystem *syst, Engine **engine) override;
 };
 
 bool Sword2MetaEngine::hasFeature(MetaEngineFeature f) const {
@@ -106,7 +106,7 @@ void Sword2MetaEngine::removeSaveState(const char *target, int slot) const {
 	g_system->getSavefileManager()->removeSavefile(filename);
 }
 
-Common::Error Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+Common::Error Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) {
 	assert(syst);
 	assert(engine);
 


Commit: 2564ce272a8f5c1c0510764af0a51bc64122c03c
    https://github.com/scummvm/scummvm/commit/2564ce272a8f5c1c0510764af0a51bc64122c03c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-11-29T01:50:03+01:00

Commit Message:
AD: Use hashmap for directory globs.

We truly were using quadratic computational complexity for no reason.

Changed paths:
    engines/advancedDetector.cpp
    engines/advancedDetector.h


diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index bf6c3a685e..20bfd02cde 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -468,21 +468,10 @@ void AdvancedMetaEngineDetection::composeFileHashMap(FileMap &allFiles, const Co
 		Common::String tstr = (_matchFullPaths && !parentName.empty() ? parentName + "/" : "") + file->getName();
 
 		if (file->isDirectory()) {
-			Common::FSList files;
-
-			if (!_directoryGlobs)
-				continue;
-
-			bool matched = false;
-			for (const char * const *glob = _directoryGlobs; *glob; glob++)
-				if (file->getName().matchString(*glob, true)) {
-					matched = true;
-					break;
-				}
-
-			if (!matched)
+			if (!_globsMap.contains(file->getName()))
 				continue;
 
+			Common::FSList files;
 			if (!file->getChildren(files, Common::FSNode::kListAll))
 				continue;
 
@@ -822,6 +811,12 @@ void AdvancedMetaEngineDetection::preprocessDescriptions() {
 
 	_hashMapsInited = true;
 
+	// Put all directory globs into a hashmap for faster usage
+	if (_directoryGlobs) {
+		for (auto glob = _directoryGlobs; *glob; glob++)
+			_globsMap.setVal(*glob, true);
+	}
+
 	// Check if the detection entries have only files from the blacklist
 	for (const byte *descPtr = _gameDescriptors; ((const ADGameDescription *)descPtr)->gameId != nullptr; descPtr += _descItemSize) {
 		const ADGameDescription *g = (const ADGameDescription *)descPtr;
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index 0a4e0ccb89..c9e560a947 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -404,6 +404,7 @@ private:
 
 private:
 	Common::HashMap<Common::String, bool, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _grayListMap;
+	Common::HashMap<Common::String, bool, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _globsMap;
 	bool _hashMapsInited;
 
 protected:




More information about the Scummvm-git-logs mailing list