2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
2006-02-11 09:53:21 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-05-29 23:13:15 +00:00
|
|
|
/*! \mainpage %ScummVM Source Reference
|
|
|
|
*
|
|
|
|
* These pages contains a cross referenced documentation for the %ScummVM source code,
|
|
|
|
* generated with Doxygen (http://www.doxygen.org) directly from the source.
|
|
|
|
* Currently not much is actually properly documented, but at least you can get an overview
|
|
|
|
* of almost all the classes, methods and variables, and how they interact.
|
|
|
|
*/
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2006-09-23 00:42:35 +00:00
|
|
|
#include "engines/engine.h"
|
2006-05-09 14:16:43 +00:00
|
|
|
#include "base/commandLine.h"
|
2003-09-17 22:41:01 +00:00
|
|
|
#include "base/plugins.h"
|
2004-02-09 01:27:27 +00:00
|
|
|
#include "base/version.h"
|
2006-06-24 09:53:45 +00:00
|
|
|
|
2003-10-08 21:59:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2004-08-05 11:13:00 +00:00
|
|
|
#include "common/file.h"
|
2006-06-24 08:07:48 +00:00
|
|
|
#include "common/fs.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2002-09-26 12:29:10 +00:00
|
|
|
#include "gui/newgui.h"
|
|
|
|
#include "gui/message.h"
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2006-04-02 09:56:11 +00:00
|
|
|
#if defined(_WIN32_WCE)
|
2006-08-04 17:47:57 +00:00
|
|
|
#include "backends/platform/wince/CELauncherDialog.h"
|
2006-04-02 09:56:11 +00:00
|
|
|
#elif defined(__DC__)
|
2006-06-30 21:58:40 +00:00
|
|
|
#include "backends/platform/dc/DCLauncherDialog.h"
|
2006-04-02 09:56:11 +00:00
|
|
|
#else
|
|
|
|
#include "gui/launcher.h"
|
2004-08-26 21:51:26 +00:00
|
|
|
#endif
|
|
|
|
|
2005-09-03 16:05:28 +00:00
|
|
|
#ifdef PALMOS_68K
|
2004-11-09 10:37:28 +00:00
|
|
|
#include "args.h"
|
|
|
|
#endif
|
|
|
|
|
2006-05-04 23:24:09 +00:00
|
|
|
|
2006-05-04 22:52:18 +00:00
|
|
|
static bool launcherDialog(OSystem &system) {
|
2005-01-08 18:37:28 +00:00
|
|
|
|
|
|
|
system.beginGFXTransaction();
|
|
|
|
// Set the user specified graphics mode (if any).
|
|
|
|
system.setGraphicsMode(ConfMan.get("gfx_mode").c_str());
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-05-17 23:52:45 +00:00
|
|
|
system.initSize(320, 200);
|
2005-01-08 18:37:28 +00:00
|
|
|
system.endGFXTransaction();
|
|
|
|
|
2007-04-18 20:59:51 +00:00
|
|
|
// Set initial window caption
|
|
|
|
system.setWindowCaption(gScummVMFullVersion);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-01-08 18:37:28 +00:00
|
|
|
// Clear the main screen
|
|
|
|
system.clearScreen();
|
|
|
|
|
2004-08-26 21:51:26 +00:00
|
|
|
#if defined(_WIN32_WCE)
|
2006-05-04 22:52:18 +00:00
|
|
|
CELauncherDialog dlg;
|
2004-08-26 21:51:26 +00:00
|
|
|
#elif defined(__DC__)
|
2006-05-04 22:52:18 +00:00
|
|
|
DCLauncherDialog dlg;
|
2004-08-26 21:51:26 +00:00
|
|
|
#else
|
2006-05-04 22:52:18 +00:00
|
|
|
GUI::LauncherDialog dlg;
|
2004-01-26 07:32:25 +00:00
|
|
|
#endif
|
2004-12-25 22:13:44 +00:00
|
|
|
return (dlg.runModal() != -1);
|
2002-09-30 00:55:47 +00:00
|
|
|
}
|
|
|
|
|
2006-05-04 23:24:09 +00:00
|
|
|
static const Plugin *detectMain() {
|
|
|
|
const Plugin *plugin = 0;
|
|
|
|
|
2006-05-05 00:26:03 +00:00
|
|
|
// 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");
|
|
|
|
gameid.toLowercase();
|
|
|
|
ConfMan.set("gameid", gameid);
|
|
|
|
|
|
|
|
// Query the plugins and find one that will handle the specified gameid
|
|
|
|
printf("Looking for %s\n", gameid.c_str());
|
|
|
|
GameDescriptor game = Base::findGame(gameid, &plugin);
|
2006-05-04 23:24:09 +00:00
|
|
|
|
|
|
|
if (plugin == 0) {
|
|
|
|
printf("Failed game detection\n");
|
2006-05-05 00:28:26 +00:00
|
|
|
warning("%s is an invalid gameid. Use the --list-games option to list supported gameid", gameid.c_str());
|
2006-05-04 23:24:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
// FIXME: Do we really need this one?
|
2007-01-20 21:27:57 +00:00
|
|
|
printf("Trying to start game '%s'\n", game.description().c_str());
|
2006-05-04 23:24:09 +00:00
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int runGame(const Plugin *plugin, OSystem &system, const Common::String &edebuglevels) {
|
2006-05-04 23:24:09 +00:00
|
|
|
Common::String gameDataPath(ConfMan.get("path"));
|
|
|
|
if (gameDataPath.empty()) {
|
|
|
|
} else if (gameDataPath.lastChar() != '/'
|
|
|
|
#if defined(__MORPHOS__) || defined(__amigaos4__)
|
|
|
|
&& gameDataPath.lastChar() != ':'
|
|
|
|
#endif
|
|
|
|
&& gameDataPath.lastChar() != '\\') {
|
|
|
|
gameDataPath += '/';
|
|
|
|
ConfMan.set("path", gameDataPath, Common::ConfigManager::kTransientDomain);
|
|
|
|
}
|
|
|
|
|
2006-03-25 04:17:17 +00:00
|
|
|
// We add it here, so MD5-based detection will be able to
|
|
|
|
// read mixed case files
|
2006-11-12 03:21:44 +00:00
|
|
|
Common::String path;
|
2006-04-25 23:07:59 +00:00
|
|
|
if (ConfMan.hasKey("path")) {
|
2006-11-12 03:21:44 +00:00
|
|
|
path = ConfMan.get("path");
|
2006-04-26 08:36:55 +00:00
|
|
|
FilesystemNode dir(path);
|
2006-05-03 20:49:33 +00:00
|
|
|
if (!dir.isDirectory()) {
|
2006-04-26 08:36:55 +00:00
|
|
|
warning("Game directory does not exist (%s)", path.c_str());
|
2006-04-25 23:07:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-12 03:21:44 +00:00
|
|
|
path = ".";
|
2006-05-12 21:41:54 +00:00
|
|
|
warning("No path was provided. Assuming the data files are in the current directory");
|
2006-04-25 23:07:59 +00:00
|
|
|
}
|
2006-11-12 03:21:44 +00:00
|
|
|
Common::File::addDefaultDirectory(path);
|
2006-03-25 04:17:17 +00:00
|
|
|
|
2005-05-05 12:03:40 +00:00
|
|
|
// Create the game engine
|
2006-04-29 00:27:20 +00:00
|
|
|
Engine *engine = 0;
|
|
|
|
PluginError err = plugin->createInstance(&system, &engine);
|
|
|
|
if (!engine || err != kNoError) {
|
2005-05-05 12:03:40 +00:00
|
|
|
// TODO: Show an error dialog or so?
|
2006-04-29 00:27:20 +00:00
|
|
|
// TODO: Also take 'err' into consideration...
|
2005-05-05 12:03:40 +00:00
|
|
|
//GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
|
|
|
|
//alert.runModal();
|
2006-11-12 03:21:44 +00:00
|
|
|
const char *errMsg = 0;
|
|
|
|
switch (err) {
|
|
|
|
case kInvalidPathError:
|
|
|
|
errMsg = "Invalid game path";
|
|
|
|
break;
|
|
|
|
case kNoGameDataFoundError:
|
|
|
|
errMsg = "Unable to locate game data";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errMsg = "Unknown error";
|
|
|
|
}
|
|
|
|
|
|
|
|
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
|
|
|
|
plugin->getName(),
|
|
|
|
errMsg,
|
|
|
|
ConfMan.getActiveDomainName().c_str(),
|
|
|
|
path.c_str()
|
|
|
|
);
|
2005-05-05 12:03:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-15 14:01:57 +00:00
|
|
|
// Set the window caption to the game name
|
2006-04-15 20:36:41 +00:00
|
|
|
Common::String caption(ConfMan.get("description"));
|
2004-01-15 14:01:57 +00:00
|
|
|
|
2007-01-20 21:27:57 +00:00
|
|
|
Common::String desc = Base::findGame(ConfMan.get("gameid")).description();
|
2006-03-28 09:42:54 +00:00
|
|
|
if (caption.empty() && !desc.empty())
|
2006-02-18 12:50:48 +00:00
|
|
|
caption = desc;
|
2006-03-28 09:42:54 +00:00
|
|
|
if (caption.empty())
|
2006-04-15 20:36:41 +00:00
|
|
|
caption = ConfMan.getActiveDomainName(); // Use the domain (=target) name
|
2006-03-28 09:42:54 +00:00
|
|
|
if (!caption.empty()) {
|
2005-01-01 18:53:47 +00:00
|
|
|
system.setWindowCaption(caption.c_str());
|
2004-01-15 14:01:57 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-04-04 23:30:41 +00:00
|
|
|
if (ConfMan.hasKey("path"))
|
2007-03-02 12:57:38 +00:00
|
|
|
Common::File::addDefaultDirectory(ConfMan.get("path"));
|
2006-04-04 23:30:41 +00:00
|
|
|
else
|
2006-04-05 06:58:18 +00:00
|
|
|
Common::File::addDefaultDirectory(".");
|
2006-03-25 04:17:17 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
// Add extrapath (if any) to the directory search list
|
|
|
|
if (ConfMan.hasKey("extrapath"))
|
2006-03-25 04:17:17 +00:00
|
|
|
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
|
2004-11-23 00:03:25 +00:00
|
|
|
|
|
|
|
if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain))
|
2006-03-25 04:17:17 +00:00
|
|
|
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
|
|
|
|
|
2006-11-13 12:03:08 +00:00
|
|
|
// On creation the engine should've set up all debug levels so we can use
|
|
|
|
// the command line arugments here
|
|
|
|
Common::enableSpecialDebugLevelList(edebuglevels);
|
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
int result;
|
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
// Init the engine (this might change the screen parameters
|
2006-04-15 20:36:41 +00:00
|
|
|
result = engine->init();
|
2004-02-25 08:03:31 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
// Run the game engine if the initialization was successful.
|
|
|
|
if (result == 0) {
|
|
|
|
result = engine->go();
|
|
|
|
}
|
2004-01-15 14:01:57 +00:00
|
|
|
|
2006-02-14 23:31:25 +00:00
|
|
|
// We clear all debug levels again even though the engine should do it
|
|
|
|
Common::clearAllSpecialDebugLevels();
|
|
|
|
|
2004-01-15 14:01:57 +00:00
|
|
|
// Free up memory
|
|
|
|
delete engine;
|
2004-06-20 19:23:04 +00:00
|
|
|
|
2006-04-01 21:52:33 +00:00
|
|
|
// Reset the file/directory mappings
|
|
|
|
Common::File::resetDefaultDirectories();
|
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return result;
|
2004-03-16 23:51:41 +00:00
|
|
|
}
|
2004-01-15 14:01:57 +00:00
|
|
|
|
2006-10-21 12:03:43 +00:00
|
|
|
|
2006-04-02 00:08:22 +00:00
|
|
|
extern "C" int scummvm_main(int argc, char *argv[]) {
|
2006-04-02 20:27:56 +00:00
|
|
|
Common::String specialDebug;
|
2006-04-02 21:06:49 +00:00
|
|
|
Common::String command;
|
2002-05-14 11:32:16 +00:00
|
|
|
|
2006-04-02 20:27:56 +00:00
|
|
|
// Verify that the backend has been initialized (i.e. g_system has been set).
|
2006-04-02 14:16:31 +00:00
|
|
|
assert(g_system);
|
|
|
|
OSystem &system = *g_system;
|
2006-05-04 22:55:15 +00:00
|
|
|
|
|
|
|
// Register config manager defaults
|
2006-05-04 23:37:50 +00:00
|
|
|
Base::registerDefaults();
|
2006-04-02 14:16:31 +00:00
|
|
|
|
2006-04-02 20:27:56 +00:00
|
|
|
// Parse the command line
|
|
|
|
Common::StringMap settings;
|
2006-05-04 23:37:50 +00:00
|
|
|
command = Base::parseCommandLine(settings, argc, argv);
|
2006-05-05 00:00:39 +00:00
|
|
|
#ifdef PALMOS_68K
|
|
|
|
ArgsFree(argv);
|
|
|
|
#endif
|
2006-04-02 14:16:31 +00:00
|
|
|
|
2006-04-02 20:27:56 +00:00
|
|
|
// Load the config file (possibly overriden via command line):
|
|
|
|
if (settings.contains("config")) {
|
|
|
|
ConfMan.loadConfigFile(settings["config"]);
|
|
|
|
settings.erase("config");
|
|
|
|
} else {
|
2004-12-25 19:03:13 +00:00
|
|
|
ConfMan.loadDefaultConfigFile();
|
2006-04-02 20:27:56 +00:00
|
|
|
}
|
2004-02-07 04:53:59 +00:00
|
|
|
|
2006-04-02 21:38:36 +00:00
|
|
|
// Update the config file
|
|
|
|
ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain);
|
|
|
|
|
2006-05-05 00:03:21 +00:00
|
|
|
|
|
|
|
// Load and setup the debuglevel and the debug flags. We do this at the
|
|
|
|
// soonest possible moment to ensure debug output starts early on, if
|
|
|
|
// requested.
|
2006-04-02 21:32:23 +00:00
|
|
|
if (settings.contains("debuglevel")) {
|
|
|
|
gDebugLevel = (int)strtol(settings["debuglevel"].c_str(), 0, 10);
|
|
|
|
printf("Debuglevel (from command line): %d\n", gDebugLevel);
|
|
|
|
settings.erase("debuglevel"); // This option should not be passed to ConfMan.
|
|
|
|
} else if (ConfMan.hasKey("debuglevel"))
|
2005-04-23 13:52:27 +00:00
|
|
|
gDebugLevel = ConfMan.getInt("debuglevel");
|
2004-12-27 21:54:20 +00:00
|
|
|
|
2006-04-02 20:27:56 +00:00
|
|
|
if (settings.contains("debugflags")) {
|
|
|
|
specialDebug = settings["debugflags"];
|
|
|
|
settings.erase("debugflags");
|
2006-02-14 23:31:25 +00:00
|
|
|
}
|
|
|
|
|
2006-05-05 00:03:21 +00:00
|
|
|
// Load the plugins.
|
2003-10-08 22:10:59 +00:00
|
|
|
PluginManager::instance().loadPlugins();
|
2006-04-02 21:06:49 +00:00
|
|
|
|
2006-05-04 23:57:49 +00:00
|
|
|
// Process the remaining command line settings. Must be done after the
|
|
|
|
// config file and the plugins have been loaded.
|
|
|
|
if (!Base::processSettings(command, settings))
|
2006-04-25 21:31:55 +00:00
|
|
|
return 0;
|
2005-07-05 20:22:56 +00:00
|
|
|
|
2005-04-19 20:22:50 +00:00
|
|
|
// Init the backend. Must take place after all config data (including
|
|
|
|
// the command line params) was read.
|
|
|
|
system.initBackend();
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2002-09-30 00:55:47 +00:00
|
|
|
// Unless a game was specified, show the launcher dialog
|
2006-05-05 00:26:03 +00:00
|
|
|
if (0 == ConfMan.getActiveDomain()) {
|
|
|
|
launcherDialog(system);
|
2006-04-15 13:21:02 +00:00
|
|
|
|
2006-04-15 13:12:03 +00:00
|
|
|
// Discard any command line options. Those that affect the graphics
|
|
|
|
// mode etc. already have should have been handled by the backend at
|
|
|
|
// this point. And the others (like bootparam etc.) should not
|
|
|
|
// blindly be passed to the first game launched from the launcher.
|
|
|
|
ConfMan.getDomain(Common::ConfigManager::kTransientDomain)->clear();
|
|
|
|
}
|
2002-09-30 00:55:47 +00:00
|
|
|
|
2004-10-10 16:31:15 +00:00
|
|
|
// FIXME: We're now looping the launcher. This, of course, doesn't
|
|
|
|
// work as well as it should. In theory everything should be destroyed
|
|
|
|
// cleanly, so this is now enabled to encourage people to fix bits :)
|
2006-05-05 00:26:03 +00:00
|
|
|
while (0 != ConfMan.getActiveDomain()) {
|
2004-01-15 14:01:57 +00:00
|
|
|
// Verify the given game name is a valid supported game
|
2006-05-04 23:24:09 +00:00
|
|
|
const Plugin *plugin = detectMain();
|
2006-04-15 16:37:48 +00:00
|
|
|
if (plugin) {
|
2004-08-29 19:08:08 +00:00
|
|
|
// Unload all plugins not needed for this game,
|
|
|
|
// to save memory
|
2006-04-15 16:37:48 +00:00
|
|
|
PluginManager::instance().unloadPluginsExcept(plugin);
|
2004-08-29 19:08:08 +00:00
|
|
|
|
2006-04-15 20:36:41 +00:00
|
|
|
int result = runGame(plugin, system, specialDebug);
|
2004-12-05 17:35:24 +00:00
|
|
|
if (result == 0)
|
|
|
|
break;
|
2003-10-05 14:37:16 +00:00
|
|
|
|
2006-04-15 13:12:03 +00:00
|
|
|
// Discard any command line options. It's unlikely that the user
|
|
|
|
// wanted to apply them to *all* games ever launched.
|
|
|
|
ConfMan.getDomain(Common::ConfigManager::kTransientDomain)->clear();
|
|
|
|
|
2006-05-05 00:26:03 +00:00
|
|
|
// Clear the active config domain
|
|
|
|
ConfMan.setActiveDomain("");
|
2004-10-13 08:49:33 +00:00
|
|
|
|
2004-08-29 19:08:08 +00:00
|
|
|
// PluginManager::instance().unloadPlugins();
|
2004-11-11 14:01:11 +00:00
|
|
|
PluginManager::instance().loadPlugins();
|
2003-10-05 14:37:16 +00:00
|
|
|
}
|
2004-11-11 14:01:11 +00:00
|
|
|
|
2006-05-05 00:26:03 +00:00
|
|
|
launcherDialog(system);
|
2004-10-10 16:31:15 +00:00
|
|
|
}
|
2003-08-19 15:03:27 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|