ALL: Sync with ScummVM rev: a4002bdeee

This commit is contained in:
Pawel Kolodziejski committed 2020-10-04 23:59:26 +02:00
1 parent e6516edf5e
commit 4631c0e2ed
121 files changed
+1977 -740

No files matched your search

+181 -35
View File
@@ -30,11 +30,15 @@
#include "common/fs.h"
#endif
#include "engines/detection.h"
// Plugin versioning
int pluginTypeVersions[PLUGIN_TYPE_MAX] = {
PLUGIN_TYPE_METAENGINE_VERSION,
PLUGIN_TYPE_ENGINE_VERSION,
PLUGIN_TYPE_MUSIC_VERSION,
PLUGIN_TYPE_DETECTION_VERSION,
};
@@ -48,22 +52,27 @@ const char *Plugin::getName() const {
return _pluginObject->getName();
}
class StaticPlugin : public Plugin {
public:
StaticPlugin(PluginObject *pluginobject, PluginType type) {
assert(pluginobject);
assert(type < PLUGIN_TYPE_MAX);
_pluginObject = pluginobject;
_type = type;
const char *Plugin::getEngineId() const {
if (_type == PLUGIN_TYPE_METAENGINE) {
return _pluginObject->getEngineId();
}
~StaticPlugin() {
delete _pluginObject;
}
return nullptr;
}
virtual bool loadPlugin() { return true; }
virtual void unloadPlugin() {}
};
StaticPlugin::StaticPlugin(PluginObject *pluginobject, PluginType type) {
assert(pluginobject);
assert(type < PLUGIN_TYPE_MAX);
_pluginObject = pluginobject;
_type = type;
}
StaticPlugin::~StaticPlugin() {
delete _pluginObject;
}
bool StaticPlugin::loadPlugin() { return true; }
void StaticPlugin::unloadPlugin() {}
class StaticPluginProvider : public PluginProvider {
public:
@@ -87,6 +96,11 @@ public:
// Engine plugins
#include "engines/plugins_table.h"
#ifdef DETECTION_STATIC
// Engine-detection plugins are included if we don't use uncached plugins.
#include "engines/detection_table.h"
#endif
// Music plugins
// TODO: Use defines to disable or enable each MIDI driver as a
// static/dynamic plugin, like it's done for the engines
@@ -257,15 +271,86 @@ void PluginManager::addPluginProvider(PluginProvider *pp) {
_providers.push_back(pp);
}
Plugin *PluginManager::getEngineFromMetaEngine(const Plugin *plugin) {
assert(plugin->getType() == PLUGIN_TYPE_METAENGINE);
Plugin *enginePlugin = nullptr;
bool found = false;
// Use the engineID from MetaEngine for comparasion.
Common::String metaEnginePluginName = plugin->getEngineId();
PluginMan.loadFirstPlugin();
do {
PluginList pl = PluginMan.getPlugins(PLUGIN_TYPE_ENGINE);
// Iterate over all engine plugins.
for (PluginList::const_iterator itr = pl.begin(); itr != pl.end(); itr++) {
// The getName() provides a name which is similiar to getEngineId.
// Because engines are engines themselves, this function is simply named getName.
Common::String enginePluginName((*itr)->getName());
if (metaEnginePluginName.equalsIgnoreCase(enginePluginName)) {
enginePlugin = (*itr);
found = true;
break;
}
}
} while (!found && PluginMan.loadNextPlugin());
if (enginePlugin) {
debug(9, "MetaEngine: %s \t matched to \t Engine: %s", plugin->getName(), enginePlugin->getFileName());
return enginePlugin;
}
debug(9, "MetaEngine: %s couldn't find a match for an engine plugin.", plugin->getName());
return nullptr;
}
Plugin *PluginManager::getMetaEngineFromEngine(const Plugin *plugin) {
assert(plugin->getType() == PLUGIN_TYPE_ENGINE);
Plugin *metaEngine = nullptr;
PluginList pl = PluginMan.getPlugins(PLUGIN_TYPE_METAENGINE);
// This will return a name of the Engine plugin, which will be identical to
// a getEngineID from a relevant MetaEngine.
Common::String enginePluginName(plugin->getName());
for (PluginList::const_iterator itr = pl.begin(); itr != pl.end(); itr++) {
Common::String metaEngineName = (*itr)->getEngineId();
if (metaEngineName.equalsIgnoreCase(enginePluginName)) {
metaEngine = (*itr);
break;
}
}
if (metaEngine) {
debug(9, "Engine: %s matched to MetaEngine: %s", plugin->getFileName(), metaEngine->getName());
return metaEngine;
}
debug(9, "Engine: %s couldn't find a match for an MetaEngine plugin.", plugin->getFileName());
return nullptr;
}
/**
* This should only be called once by main()
**/
void PluginManagerUncached::init() {
unloadAllPlugins();
_allEnginePlugins.clear();
ConfMan.setBool("always_run_fallback_detection_extern", false);
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false); // empty the engine plugins
Common::String detectPluginName = "detection";
#ifdef PLUGIN_SUFFIX
detectPluginName += PLUGIN_SUFFIX;
#endif
bool foundDetectPlugin = false;
for (ProviderList::iterator pp = _providers.begin();
pp != _providers.end();
++pp) {
@@ -276,6 +361,16 @@ void PluginManagerUncached::init() {
// file plugins. Currently this is the case. If it changes, we
// should find a fast way of detecting whether a plugin is a
// music or an engine plugin.
if (!foundDetectPlugin && (*pp)->isFilePluginProvider()) {
Common::String pName = (*p)->getFileName();
if (pName.hasSuffix(detectPluginName)) {
_detectionPlugin = (*p);
foundDetectPlugin = true;
debug(9, "Detection plugin found!");
continue;
}
}
if ((*pp)->isFilePluginProvider()) {
_allEnginePlugins.push_back(*p);
} else if ((*p)->loadPlugin()) { // and this is the proper method
@@ -348,6 +443,48 @@ void PluginManagerUncached::updateConfigWithFileName(const Common::String &engin
}
}
void PluginManagerUncached::loadDetectionPlugin() {
bool linkMetaEngines = false;
if (_isDetectionLoaded) {
debug(9, "Detection plugin is already loaded. Adding each available engines to the memory.");
linkMetaEngines = true;
} else {
if (_detectionPlugin) {
if (_detectionPlugin->loadPlugin()) {
assert((_detectionPlugin)->getType() == PLUGIN_TYPE_DETECTION);
linkMetaEngines = true;
_isDetectionLoaded = true;
} else {
debug(9, "Detection plugin was not loaded correctly.");
return;
}
} else {
debug(9, "Detection plugin not found.");
return;
}
}
if (linkMetaEngines) {
_pluginsInMem[PLUGIN_TYPE_METAENGINE].clear();
const Detection &detectionConnect = _detectionPlugin->get<Detection>();
const PluginList &pl = detectionConnect.getPlugins();
Common::for_each(pl.begin(), pl.end(), Common::bind1st(Common::mem_fun(&PluginManagerUncached::tryLoadPlugin), this));
}
}
void PluginManagerUncached::unloadDetectionPlugin() {
if (_isDetectionLoaded) {
_pluginsInMem[PLUGIN_TYPE_METAENGINE].clear();
_detectionPlugin->unloadPlugin();
_isDetectionLoaded = false;
} else {
debug(9, "Detection plugin is already unloaded.");
}
}
void PluginManagerUncached::loadFirstPlugin() {
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
@@ -424,8 +561,9 @@ void PluginManager::unloadPluginsExcept(PluginType type, const Plugin *plugin, b
found = *p;
} else {
(*p)->unloadPlugin();
if (deletePlugin)
if (deletePlugin) {
delete *p;
}
}
}
_pluginsInMem[type].clear();
@@ -498,7 +636,7 @@ QualifiedGameList EngineManager::findGamesMatching(const Common::String &engineI
// If we got an engine name, look for THE game only in that engine
const Plugin *p = EngineMan.findPlugin(engineId);
if (p) {
const MetaEngine &engine = p->get<MetaEngine>();
const MetaEngineStatic &engine = p->get<MetaEngineStatic>();
PlainGameDescriptor pluginResult = engine.findGame(gameId.c_str());
if (pluginResult.gameId) {
@@ -527,7 +665,7 @@ QualifiedGameList EngineManager::findGameInLoadedPlugins(const Common::String &g
PluginList::const_iterator iter;
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
const MetaEngine &engine = (*iter)->get<MetaEngine>();
const MetaEngineStatic &engine = (*iter)->get<MetaEngineStatic>();
PlainGameDescriptor pluginResult = engine.findGame(gameId.c_str());
if (pluginResult.gameId) {
@@ -542,29 +680,29 @@ DetectionResults EngineManager::detectGames(const Common::FSList &fslist) const
DetectedGames candidates;
PluginList plugins;
PluginList::const_iterator iter;
PluginMan.loadFirstPlugin();
do {
plugins = getPlugins();
// 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 MetaEngine &metaEngine = (*iter)->get<MetaEngine>();
DetectedGames engineCandidates = metaEngine.detectGames(fslist);
for (uint i = 0; i < engineCandidates.size(); i++) {
engineCandidates[i].path = fslist.begin()->getParent().getPath();
engineCandidates[i].shortPath = fslist.begin()->getParent().getDisplayName();
candidates.push_back(engineCandidates[i]);
}
// MetaEngines are always loaded into memory, so, get them and
// run detection for all of them.
plugins = getPlugins(PLUGIN_TYPE_METAENGINE);
// 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 MetaEngineStatic &metaEngine = (*iter)->get<MetaEngineStatic>();
DetectedGames engineCandidates = metaEngine.detectGames(fslist);
for (uint i = 0; i < engineCandidates.size(); i++) {
engineCandidates[i].path = fslist.begin()->getParent().getPath();
engineCandidates[i].shortPath = fslist.begin()->getParent().getDisplayName();
candidates.push_back(engineCandidates[i]);
}
} while (PluginMan.loadNextPlugin());
}
return DetectionResults(candidates);
}
const PluginList &EngineManager::getPlugins() const {
return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
const PluginList &EngineManager::getPlugins(const PluginType fetchPluginType) const {
return PluginManager::instance().getPlugins(fetchPluginType);
}
namespace {
@@ -628,7 +766,7 @@ const Plugin *EngineManager::findLoadedPlugin(const Common::String &engineId) co
const PluginList &plugins = getPlugins();
for (PluginList::const_iterator iter = plugins.begin(); iter != plugins.end(); iter++)
if (engineId == (*iter)->get<MetaEngine>().getEngineId())
if (engineId == (*iter)->get<MetaEngineStatic>().getEngineId())
return *iter;
return 0;
@@ -680,7 +818,7 @@ QualifiedGameDescriptor EngineManager::findTarget(const Common::String &target,
}
// Make sure it does support the game ID
const MetaEngine &engine = foundPlugin->get<MetaEngine>();
const MetaEngineStatic &engine = foundPlugin->get<MetaEngineStatic>();
PlainGameDescriptor desc = engine.findGame(domain->getVal("gameid").c_str());
if (!desc.gameId) {
return QualifiedGameDescriptor();
@@ -698,6 +836,14 @@ void EngineManager::upgradeTargetIfNecessary(const Common::String &target) const
if (!domain->contains("engineid")) {
upgradeTargetForEngineId(target);
} else {
if (domain->getVal("engineid").equals("fullpipe")) {
domain->setVal("engineid", "ngi");
debug("Upgrading engineid from 'fullpipe' to 'ngi'");
ConfMan.flushToDisk();
}
}
}
@@ -737,7 +883,7 @@ void EngineManager::upgradeTargetForEngineId(const Common::String &target) const
}
// Take the first detection entry
const MetaEngine &metaEngine = plugin->get<MetaEngine>();
const MetaEngineStatic &metaEngine = plugin->get<MetaEngineStatic>();
DetectedGames candidates = metaEngine.detectGames(files);
if (candidates.empty()) {
warning("No games supported by the engine '%s' were found in path '%s' when upgrading target '%s'",