ENGINES: Change targets to have an 'engine ID'

The engine ID identifies which engine should be used to launch the target.
Also remove the 'single ID' system. Different games from engines that used
that system now have different game IDs.

Also-By: Matthew Hoops <clone2727@gmail.com>
This commit is contained in:
Bastien Bouclet 2016-09-15 18:39:45 +02:00
parent 9c8bd056d6
commit bb813719b5
30 changed files with 247 additions and 231 deletions

View file

@ -108,39 +108,50 @@ static bool launcherDialog() {
}
static const Plugin *detectPlugin() {
const Plugin *plugin = nullptr;
// Figure out the engine ID and game ID
Common::String engineId = ConfMan.get("engineid");
Common::String gameId = ConfMan.get("gameid");
// Make sure the gameid is set in the config manager, and that it is lowercase.
Common::String gameid(ConfMan.getActiveDomainName());
assert(!gameid.empty());
if (ConfMan.hasKey("gameid")) {
gameid = ConfMan.get("gameid");
// Print text saying what's going on
printf("User picked target '%s' (engine ID '%s', game ID '%s')...\n", ConfMan.getActiveDomainName().c_str(), engineId.c_str(), gameId.c_str());
// Set last selected game, that the game will be highlighted
// on RTL
ConfMan.set("lastselectedgame", ConfMan.getActiveDomainName(), Common::ConfigManager::kApplicationDomain);
ConfMan.flushToDisk();
// At this point the engine ID and game ID must be known
if (engineId.empty()) {
warning("The engine ID is not set for target '%s'", ConfMan.getActiveDomainName().c_str());
return 0;
}
gameid.toLowercase();
ConfMan.set("gameid", gameid);
if (gameId.empty()) {
warning("The game ID is not set for target '%s'", ConfMan.getActiveDomainName().c_str());
return 0;
}
// Query the plugins and find one that will handle the specified gameid
printf("User picked target '%s' (gameid '%s')...\n", ConfMan.getActiveDomainName().c_str(), gameid.c_str());
printf(" Looking for a plugin supporting this gameid... ");
const Plugin *plugin = EngineMan.findPlugin(engineId);
if (!plugin) {
warning("'%s' is an invalid engine ID. Use the --list-engines command to list supported engine IDs", engineId.c_str());
return 0;
}
PlainGameDescriptor game = EngineMan.findGame(gameid, &plugin);
if (plugin == 0) {
printf("failed\n");
warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str());
} else {
printf("%s\n Starting '%s'\n", plugin->getName(), game.description);
// Query the plugin for the game descriptor
printf(" Looking for a plugin supporting this target... %s\n", plugin->getName());
PlainGameDescriptor game = plugin->get<MetaEngine>().findGame(gameId.c_str());
if (!game.gameId) {
warning("'%s' is an invalid game ID for the engine '%s'. Use the --list-games option to list supported game IDs", gameId.c_str(), engineId.c_str());
return 0;
}
return plugin;
}
void saveLastLaunchedTarget(const Common::String &target) {
if (ConfMan.hasGameDomain(target)) {
// Set the last selected game, so the game will be highlighted next time the user
// returns to the launcher.
ConfMan.set("lastselectedgame", target, Common::ConfigManager::kApplicationDomain);
ConfMan.flushToDisk();
}
}
// TODO: specify the possible return values here
static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common::String &edebuglevels) {
// Determine the game data path, for validation and error messages
@ -208,7 +219,7 @@ static Common::Error runGame(const Plugin *plugin, OSystem &system, const Common
Common::String caption(ConfMan.get("description"));
if (caption.empty()) {
PlainGameDescriptor game = EngineMan.findGame(ConfMan.get("gameid"));
PlainGameDescriptor game = EngineMan.findTarget(ConfMan.getActiveDomainName());
if (game.description) {
caption = game.description;
}
@ -532,6 +543,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
// work as well as it should. In theory everything should be destroyed
// cleanly, so this is now enabled to encourage people to fix bits :)
while (0 != ConfMan.getActiveDomain()) {
saveLastLaunchedTarget(ConfMan.getActiveDomainName());
// Try to find a plugin which feels responsible for the specified game.
const Plugin *plugin = detectPlugin();
if (plugin) {