aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorMax Horn2006-03-09 02:52:51 +0000
committerMax Horn2006-03-09 02:52:51 +0000
commit86565fcca57454e91124410cfd6864ef1e202dc0 (patch)
tree83cc82217179d56f23836628520b7f63b4a0607d /base
parentd2f78184af00cd91f3f1f251199a436b53f4ae64 (diff)
downloadscummvm-rg350-86565fcca57454e91124410cfd6864ef1e202dc0.tar.gz
scummvm-rg350-86565fcca57454e91124410cfd6864ef1e202dc0.tar.bz2
scummvm-rg350-86565fcca57454e91124410cfd6864ef1e202dc0.zip
- Renamed GameSettings to PlainGameDescriptor
- Added new GameDescriptor struct (similar to PlainGameDescriptor but with Common::String members instead of const char * ones) - Changed DetectedGame to subclass GameDescriptor - Removed toGameSettings() in favor of new (template) constructors in DetectedGame and GameDescriptor - Fixed a bug in the obsolete gameid handling in the SCUMM & SIMON engines svn-id: r21150
Diffstat (limited to 'base')
-rw-r--r--base/gameDetector.cpp22
-rw-r--r--base/gameDetector.h39
-rw-r--r--base/main.cpp4
-rw-r--r--base/plugins.cpp6
-rw-r--r--base/plugins.h34
5 files changed, 53 insertions, 52 deletions
diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp
index d787f257e1..b5b2854d39 100644
--- a/base/gameDetector.cpp
+++ b/base/gameDetector.cpp
@@ -239,7 +239,7 @@ void listGames() {
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
GameList list = (*iter)->getSupportedGames();
for (GameList::iterator v = list.begin(); v != list.end(); ++v) {
- printf("%-20s %s\n", v->gameid, v->description);
+ printf("%-20s %s\n", v->gameid.c_str(), v->description.c_str());
}
}
}
@@ -262,8 +262,8 @@ void listTargets() {
// to find the proper desc. In fact, the platform probably should
// be taken into account, too.
String gameid(name);
- GameSettings g = GameDetector::findGame(gameid);
- if (g.description)
+ GameDescriptor g = GameDetector::findGame(gameid);
+ if (g.description.size() > 0)
description = g.description;
}
@@ -271,15 +271,15 @@ void listTargets() {
}
}
-GameSettings GameDetector::findGame(const String &gameName, const Plugin **plugin) {
- // Find the GameSettings for this target
+GameDescriptor GameDetector::findGame(const String &gameName, const Plugin **plugin) {
+ // Find the GameDescriptor for this target
const PluginList &plugins = PluginManager::instance().getPlugins();
- GameSettings result = {NULL, NULL};
+ GameDescriptor result;
PluginList::const_iterator iter = plugins.begin();
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
result = (*iter)->findGame(gameName.c_str());
- if (result.gameid) {
+ if (result.gameid.size() > 0) {
if (plugin)
*plugin = *iter;
break;
@@ -384,7 +384,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) {
// To verify this, check if there is either a game domain (i.e.
// a configured target) matching this argument, or if we can
// find any target with that name.
- if (i == (argc - 1) && (ConfMan.hasGameDomain(s) || findGame(s).gameid)) {
+ if (i == (argc - 1) && (ConfMan.hasGameDomain(s) || findGame(s).gameid.size() > 0)) {
setTarget(s);
} else {
if (current_option == NULL)
@@ -641,15 +641,15 @@ bool GameDetector::detectMain() {
_gameid = _targetName;
printf("Looking for %s\n", _gameid.c_str());
- GameSettings game = findGame(_gameid, &_plugin);
+ GameDescriptor game = findGame(_gameid, &_plugin);
- if (!game.gameid) {
+ if (game.gameid.size() == 0) {
printf("Failed game detection\n");
warning("%s is an invalid target. Use the --list-targets option to list targets", _targetName.c_str());
return false;
}
- printf("Trying to start game '%s'\n", game.description);
+ printf("Trying to start game '%s'\n", game.description.c_str());
String gameDataPath(ConfMan.get("path"));
if (gameDataPath.isEmpty()) {
diff --git a/base/gameDetector.h b/base/gameDetector.h
index 0cada3e597..6eb9c5c231 100644
--- a/base/gameDetector.h
+++ b/base/gameDetector.h
@@ -34,25 +34,32 @@ namespace Audio {
class Mixer;
}
-struct GameSettings {
+struct PlainGameDescriptor {
const char *gameid;
const char *description; // TODO: Rename this to "title" or so
};
-/**
- * This template function allows to easily convert structs that mimic GameSettings
- * to a GameSettings instance.
- *
- * Normally, one would just subclass GameSettings to get this effect much easier.
- * However, subclassing a struct turns it into a non-POD type. One of the
- * consequences is that you can't have inline intialized arrays of that type.
- * But we heavily rely on those, hence we can't subclass GameSettings...
- */
-template <class T>
-GameSettings toGameSettings(const T &g) {
- GameSettings dummy = { g.gameid, g.description };
- return dummy;
-}
+struct GameDescriptor {
+ Common::String gameid;
+ Common::String description; // TODO: Rename this to "title" or so
+
+ GameDescriptor() {}
+ GameDescriptor(Common::String g, Common::String d) :
+ gameid(g), description(d) {}
+
+ /**
+ * This template constructor allows to easily convert structs that mimic GameDescriptor
+ * to a GameDescriptor instance.
+ *
+ * Normally, one would just subclass GameDescriptor to get this effect much easier.
+ * However, subclassing a struct turns it into a non-POD type. One of the
+ * consequences is that you can't have inline intialized arrays of that type.
+ * But we heavily rely on those, hence we can't subclass GameDescriptor...
+ */
+ template <class T>
+ GameDescriptor(const T &g) :
+ gameid(g.gameid), description(g.description) {}
+};
class GameDetector {
@@ -78,7 +85,7 @@ public:
static Audio::Mixer *createMixer();
- static GameSettings findGame(const String &gameName, const Plugin **plugin = NULL);
+ static GameDescriptor findGame(const String &gameName, const Plugin **plugin = NULL);
//protected:
void setTarget(const String &name); // TODO: This should be protected
diff --git a/base/main.cpp b/base/main.cpp
index 50a4c9f4e5..d32849dfb0 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -291,8 +291,8 @@ static int runGame(GameDetector &detector, OSystem &system, const Common::String
// Set the window caption to the game name
Common::String caption(ConfMan.get("description", detector._targetName));
- const char *desc = GameDetector::findGame(detector._gameid).description;
- if (caption.isEmpty() && desc)
+ Common::String desc = GameDetector::findGame(detector._gameid).description;
+ if (caption.isEmpty() && !desc.isEmpty())
caption = desc;
if (caption.isEmpty())
caption = detector._targetName;
diff --git a/base/plugins.cpp b/base/plugins.cpp
index 802b2f8d9d..0f1fc62b18 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -32,7 +32,7 @@
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
typedef const char *(*NameFunc)();
-typedef GameSettings (*GameIDQueryFunc)(const char *gameid);
+typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid);
typedef GameList (*GameIDListFunc)();
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);
@@ -93,7 +93,7 @@ public:
GameList getSupportedGames() const { return _plugin->_games; }
- GameSettings findGame(const char *gameid) const {
+ GameDescriptor findGame(const char *gameid) const {
assert(_plugin->_qf);
return (*_plugin->_qf)(gameid);
}
@@ -134,7 +134,7 @@ public:
GameList getSupportedGames() const { return _games; }
- GameSettings findGame(const char *gameid) const {
+ GameDescriptor findGame(const char *gameid) const {
assert(_qf);
return (*_qf)(gameid);
}
diff --git a/base/plugins.h b/base/plugins.h
index 4ac93baaf3..5cc362ca58 100644
--- a/base/plugins.h
+++ b/base/plugins.h
@@ -27,7 +27,7 @@
#include "common/array.h"
#include "common/singleton.h"
#include "common/util.h"
-#include "base/gameDetector.h" // For GameSettings
+#include "base/gameDetector.h" // For GameDescriptor
class Engine;
class FSList;
@@ -35,33 +35,27 @@ class GameDetector;
class OSystem;
/** List of games. */
-typedef Common::Array<GameSettings> GameList;
+typedef Common::Array<GameDescriptor> GameList;
/**
- * A detected game. Carries the GameSettings, but also (optionally)
+ * A detected game. Carries the GameDescriptor, but also (optionally)
* information about the language and platform of the detected game.
*/
-struct DetectedGame {
- const char *gameid;
- const char *description;
+struct DetectedGame : public GameDescriptor {
Common::Language language;
Common::Platform platform;
DetectedGame(const char *g = 0, const char *d = 0,
Common::Language l = Common::UNK_LANG,
Common::Platform p = Common::kPlatformUnknown)
- : gameid(g), description(d), language(l), platform(p) {}
- DetectedGame(const GameSettings &game,
+ : GameDescriptor(g, d), language(l), platform(p) {}
+
+ template <class T>
+ DetectedGame(const T &game,
Common::Language l = Common::UNK_LANG,
Common::Platform p = Common::kPlatformUnknown)
- : gameid(game.gameid), description(game.description), language(l), platform(p) {}
+ : GameDescriptor(game.gameid, game.description), language(l), platform(p) {}
};
-template <class T>
-DetectedGame toDetectedGame(const T &g) {
- DetectedGame dummy(g.gameid, g.description);
- return dummy;
-}
-
/** List of detected games. */
typedef Common::Array<DetectedGame> DetectedGameList;
@@ -83,7 +77,7 @@ public:
virtual int getVersion() const { return 0; } // TODO!
virtual GameList getSupportedGames() const = 0;
- virtual GameSettings findGame(const char *gameid) const = 0;
+ virtual GameDescriptor findGame(const char *gameid) const = 0;
virtual DetectedGameList detectGames(const FSList &fslist) const = 0;
virtual Engine *createInstance(GameDetector *detector, OSystem *syst) const = 0;
@@ -99,8 +93,8 @@ public:
* Each plugin has to define the following functions:
* - GameList Engine_##ID##_gameIDList()
* -> returns a list of gameid/desc pairs. Only used to implement '--list-games'.
- * - GameSettings Engine_##ID##_findGameID(const char *gameid)
- * -> asks the Engine for a GameSettings matching the gameid. If that is not
+ * - GameDescriptor Engine_##ID##_findGameID(const char *gameid)
+ * -> asks the Engine for a GameDescriptor matching the gameid. If that is not
* possible, the engine MUST set the gameid of the returned value to 0.
* Note: This MUST succeed for every gameID on the list returned by
* gameIDList(), but MAY also work for additional gameids (e.g. to support
@@ -130,7 +124,7 @@ public:
extern "C" { \
PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \
PLUGIN_EXPORT GameList PLUGIN_gameIDList() { return Engine_##ID##_gameIDList(); } \
- PLUGIN_EXPORT GameSettings PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \
+ PLUGIN_EXPORT GameDescriptor PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \
PLUGIN_EXPORT Engine *PLUGIN_createEngine(GameDetector *detector, OSystem *syst) { return Engine_##ID##_create(detector, syst); } \
PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
}
@@ -144,7 +138,7 @@ public:
class PluginRegistrator {
friend class StaticPlugin;
public:
- typedef GameSettings (*GameIDQueryFunc)(const char *gameid);
+ typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid);
typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst);
typedef DetectedGameList (*DetectFunc)(const FSList &fslist);