[Scummvm-cvs-logs] SF.net SVN: scummvm: [22346] scummvm/trunk/gui

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu May 4 16:25:03 CEST 2006


Revision: 22346
Author:   fingolfin
Date:     2006-05-04 16:24:09 -0700 (Thu, 04 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22346&view=rev

Log Message:
-----------
Moved GameDetector::setTarget & findGame to the new namespace Base; moved their declaration to base/game.h, their implementation to base/main.cpp (both until we can come up with a better location). Also moved detectMain into main.cpp, where it now is a local static function

Modified Paths:
--------------
    scummvm/trunk/backends/dc/dcmain.cpp
    scummvm/trunk/base/game.h
    scummvm/trunk/base/gameDetector.cpp
    scummvm/trunk/base/gameDetector.h
    scummvm/trunk/base/main.cpp
    scummvm/trunk/common/system.cpp
    scummvm/trunk/gui/launcher.cpp
Modified: scummvm/trunk/backends/dc/dcmain.cpp
===================================================================
--- scummvm/trunk/backends/dc/dcmain.cpp	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/backends/dc/dcmain.cpp	2006-05-04 23:24:09 UTC (rev 22346)
@@ -24,7 +24,7 @@
 #include <common/stdafx.h>
 #include <common/scummsys.h>
 #include <base/engine.h>
-#include <base/gameDetector.h>
+#include <base/game.h>
 #include <base/main.h>
 #include <base/plugins.h>
 #include "dc.h"
@@ -224,7 +224,7 @@
     ConfMan.set("path", dir, base);
 
   // Set the target.
-  GameDetector::setTarget(base);
+  Base::setTarget(base);
 
   return 0;
 }

Modified: scummvm/trunk/base/game.h
===================================================================
--- scummvm/trunk/base/game.h	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/base/game.h	2006-05-04 23:24:09 UTC (rev 22346)
@@ -53,4 +53,18 @@
 		gameid(g.gameid), description(g.description) {}
 };
 
+
+class Plugin;
+
+namespace Base {
+
+// TODO: Find a better place for this function.
+GameDescriptor findGame(const Common::String &gameName, const Plugin **plugin = NULL);
+
+// TODO: Find a better place for this function.
+void setTarget(const Common::String &name);
+
+} // End of namespace Base
+
+
 #endif

Modified: scummvm/trunk/base/gameDetector.cpp
===================================================================
--- scummvm/trunk/base/gameDetector.cpp	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/base/gameDetector.cpp	2006-05-04 23:24:09 UTC (rev 22346)
@@ -252,26 +252,6 @@
 #endif // #ifdef DEFAULT_SAVE_PATH
 }
 
-GameDescriptor GameDetector::findGame(const String &gameName, const Plugin **plugin) {
-	// Find the GameDescriptor for this target
-	const PluginList &plugins = PluginManager::instance().getPlugins();
-	GameDescriptor result;
-
-	if (plugin)
-		*plugin = 0;
-
-	PluginList::const_iterator iter = plugins.begin();
-	for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
-		result = (*iter)->findGame(gameName.c_str());
-		if (!result.gameid.empty()) {
-			if (plugin)
-				*plugin = *iter;
-			break;
-		}
-	}
-	return result;
-}
-
 //
 // Various macros used by the command line parser.
 //
@@ -545,8 +525,8 @@
 	// domain (i.e. a target) matching this argument, or alternatively
 	// whether there is a gameid matching that name.
 	if (!target.empty()) {
-		if (ConfMan.hasGameDomain(target) || findGame(target).gameid.size() > 0) {
-			setTarget(target);
+		if (ConfMan.hasGameDomain(target) || Base::findGame(target).gameid.size() > 0) {
+			Base::setTarget(target);
 		} else {
 			usage("Unrecognized game target '%s'", target.c_str());
 		}
@@ -570,11 +550,11 @@
 
 	// Finally, store the command line settings into the config manager.
 	for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) {
-		String key(x->_key);
-		String value(x->_value);
+		Common::String key(x->_key);
+		Common::String value(x->_value);
 
 		// Replace any "-" in the key by "_" (e.g. change "save-slot" to "save_slot").
-		for (String::iterator c = key.begin(); c != key.end(); ++c)
+		for (Common::String::iterator c = key.begin(); c != key.end(); ++c)
 			if (*c == '-')
 				*c = '_';
 		
@@ -582,50 +562,3 @@
 		ConfMan.set(key, value, Common::ConfigManager::kTransientDomain);
 	}
 }
-
-
-void GameDetector::setTarget(const String &target) {
-	ConfMan.setActiveDomain(target);
-
-	// Make sure the gameid is set in the config manager, and that it is lowercase.
-	String gameid(target);
-	if (ConfMan.hasKey("gameid"))
-		gameid = ConfMan.get("gameid");
-	gameid.toLowercase();
-	ConfMan.set("gameid", gameid);
-}
-
-const Plugin *GameDetector::detectMain() {
-	const Plugin *plugin = 0;
-	
-	if (ConfMan.getActiveDomainName().empty()) {
-		warning("No game was specified...");
-		return 0;
-	}
-
-	printf("Looking for %s\n", ConfMan.get("gameid").c_str());
-	GameDescriptor game = findGame(ConfMan.get("gameid"), &plugin);
-
-	if (plugin == 0) {
-		printf("Failed game detection\n");
-		warning("%s is an invalid target. Use the --list-targets option to list targets", ConfMan.getActiveDomainName().c_str());
-		return 0;
-	}
-
-	printf("Trying to start game '%s'\n", game.description.c_str());
-
-	String gameDataPath(ConfMan.get("path"));
-	if (gameDataPath.empty()) {
-		warning("No path was provided. Assuming the data files are in the current directory");
-		gameDataPath = "./";
-	} else if (gameDataPath.lastChar() != '/'
-#if defined(__MORPHOS__) || defined(__amigaos4__)
-					&& gameDataPath.lastChar() != ':'
-#endif
-					&& gameDataPath.lastChar() != '\\') {
-		gameDataPath += '/';
-		ConfMan.set("path", gameDataPath, Common::ConfigManager::kTransientDomain);
-	}
-
-	return plugin;
-}

Modified: scummvm/trunk/base/gameDetector.h
===================================================================
--- scummvm/trunk/base/gameDetector.h	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/base/gameDetector.h	2006-05-04 23:24:09 UTC (rev 22346)
@@ -28,24 +28,11 @@
 #include "common/config-manager.h"
 #include "base/game.h"
 
-class Plugin;
-
-
 class GameDetector {
-	typedef Common::String String;
-
 public:
 	static void registerDefaults();
-	
 	static Common::String parseCommandLine(Common::StringMap &settings, int argc, char **argv);
 	static void processSettings(Common::String &target, Common::StringMap &settings);
-	static const Plugin *detectMain();
-
-public:
-	static GameDescriptor findGame(const String &gameName, const Plugin **plugin = NULL);
-
-//protected:
-	static void setTarget(const String &name);	// TODO: This should be protected
 };
 
 #endif

Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/base/main.cpp	2006-05-04 23:24:09 UTC (rev 22346)
@@ -65,6 +65,45 @@
 #include "gui/Actions.h"
 #endif
 
+
+namespace Base {
+
+// TODO: Find a better place for this function.
+GameDescriptor findGame(const Common::String &gameName, const Plugin **plugin) {
+	// Find the GameDescriptor for this target
+	const PluginList &plugins = PluginManager::instance().getPlugins();
+	GameDescriptor result;
+
+	if (plugin)
+		*plugin = 0;
+
+	PluginList::const_iterator iter = plugins.begin();
+	for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
+		result = (*iter)->findGame(gameName.c_str());
+		if (!result.gameid.empty()) {
+			if (plugin)
+				*plugin = *iter;
+			break;
+		}
+	}
+	return result;
+}
+
+// TODO: Find a better place for this function.
+void setTarget(const Common::String &target) {
+	ConfMan.setActiveDomain(target);
+
+	// Make sure the gameid is set in the config manager, and that it is lowercase.
+	Common::String gameid(target);
+	if (ConfMan.hasKey("gameid"))
+		gameid = ConfMan.get("gameid");
+	gameid.toLowercase();
+	ConfMan.set("gameid", gameid);
+}
+
+} // End of namespace Base
+
+
 /** List all supported game IDs, i.e. all games which any loaded plugin supports. */
 void listGames() {
 	const PluginList &plugins = PluginManager::instance().getPlugins();
@@ -99,7 +138,7 @@
 			// to find the proper desc. In fact, the platform probably should
 			// be taken into account, too.
 			Common::String gameid(name);
-			GameDescriptor g = GameDetector::findGame(gameid);
+			GameDescriptor g = Base::findGame(gameid);
 			if (g.description.size() > 0)
 				description = g.description;
 		}
@@ -164,6 +203,41 @@
 	return (dlg.runModal() != -1);
 }
 
+static const Plugin *detectMain() {
+	const Plugin *plugin = 0;
+	
+	if (ConfMan.getActiveDomainName().empty()) {
+		warning("No game was specified...");
+		return 0;
+	}
+
+	printf("Looking for %s\n", ConfMan.get("gameid").c_str());
+	GameDescriptor game = Base::findGame(ConfMan.get("gameid"), &plugin);
+
+	if (plugin == 0) {
+		printf("Failed game detection\n");
+		warning("%s is an invalid target. Use the --list-targets option to list targets", ConfMan.getActiveDomainName().c_str());
+		return 0;
+	}
+
+	printf("Trying to start game '%s'\n", game.description.c_str());
+
+	Common::String gameDataPath(ConfMan.get("path"));
+	if (gameDataPath.empty()) {
+		warning("No path was provided. Assuming the data files are in the current directory");
+		gameDataPath = "./";
+	} else if (gameDataPath.lastChar() != '/'
+#if defined(__MORPHOS__) || defined(__amigaos4__)
+					&& gameDataPath.lastChar() != ':'
+#endif
+					&& gameDataPath.lastChar() != '\\') {
+		gameDataPath += '/';
+		ConfMan.set("path", gameDataPath, Common::ConfigManager::kTransientDomain);
+	}
+
+	return plugin;
+}
+
 static int runGame(const Plugin *plugin, OSystem &system, const Common::String &edebuglevels) {
 	// We add it here, so MD5-based detection will be able to
 	// read mixed case files
@@ -197,7 +271,7 @@
 	// Set the window caption to the game name
 	Common::String caption(ConfMan.get("description"));
 
-	Common::String desc = GameDetector::findGame(ConfMan.get("gameid")).description;
+	Common::String desc = Base::findGame(ConfMan.get("gameid")).description;
 	if (caption.empty() && !desc.empty())
 		caption = desc;
 	if (caption.empty())
@@ -424,7 +498,7 @@
 	// cleanly, so this is now enabled to encourage people to fix bits :)
 	while (running) {
 		// Verify the given game name is a valid supported game
-		const Plugin *plugin = GameDetector::detectMain();
+		const Plugin *plugin = detectMain();
 		if (plugin) {
 			// Unload all plugins not needed for this game,
 			// to save memory

Modified: scummvm/trunk/common/system.cpp
===================================================================
--- scummvm/trunk/common/system.cpp	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/common/system.cpp	2006-05-04 23:24:09 UTC (rev 22346)
@@ -25,8 +25,6 @@
 
 #include "backends/intern.h"
 
-#include "base/gameDetector.h"
-
 #include "gui/message.h"
 
 #include "common/config-manager.h"

Modified: scummvm/trunk/gui/launcher.cpp
===================================================================
--- scummvm/trunk/gui/launcher.cpp	2006-05-04 22:55:15 UTC (rev 22345)
+++ scummvm/trunk/gui/launcher.cpp	2006-05-04 23:24:09 UTC (rev 22346)
@@ -24,7 +24,7 @@
 #include "backends/fs/fs.h"
 
 #include "base/engine.h"
-#include "base/gameDetector.h"
+#include "base/game.h"
 #include "base/plugins.h"
 #include "base/version.h"
 
@@ -538,7 +538,7 @@
 		if (gameid.empty())
 			gameid = iter->_key;
 		if (description.empty()) {
-			GameDescriptor g = GameDetector::findGame(gameid);
+			GameDescriptor g = Base::findGame(gameid);
 			if (!g.description.empty())
 				description = g.description;
 		}
@@ -696,7 +696,7 @@
 	String gameId(ConfMan.get("gameid", _domains[item]));
 	if (gameId.empty())
 		gameId = _domains[item];
-	EditGameDialog editDialog(_domains[item], GameDetector::findGame(gameId).description);
+	EditGameDialog editDialog(_domains[item], Base::findGame(gameId).description);
 	if (editDialog.runModal() > 0) {
 		// User pressed OK, so make changes permanent
 
@@ -737,7 +737,7 @@
 	case kListItemDoubleClickedCmd:
 		// Print out what was selected
 		assert(item >= 0);
-		GameDetector::setTarget(_domains[item]);
+		Base::setTarget(_domains[item]);
 		close();
 		break;
 	case kListSelectionChangedCmd:


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list