aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2006-02-17 00:22:53 +0000
committerMax Horn2006-02-17 00:22:53 +0000
commit7967e30c731bdc21342ef10271578e2ac5b4e9bc (patch)
treeecb8fe39598810b33781aeddc0ba78e45dba961e
parenta96760a2fdf32a1dc3c6cb44cfd247e4b1b3ab79 (diff)
downloadscummvm-rg350-7967e30c731bdc21342ef10271578e2ac5b4e9bc.tar.gz
scummvm-rg350-7967e30c731bdc21342ef10271578e2ac5b4e9bc.tar.bz2
scummvm-rg350-7967e30c731bdc21342ef10271578e2ac5b4e9bc.zip
Added global toGameSettings() template function for convenience; simplified GameSettings usage in some engines
svn-id: r20739
-rw-r--r--base/gameDetector.h20
-rw-r--r--engines/gob/gob.cpp18
-rw-r--r--engines/kyra/kyra.cpp26
-rw-r--r--engines/lure/lure.cpp38
-rw-r--r--engines/sword2/sword2.cpp8
5 files changed, 43 insertions, 67 deletions
diff --git a/base/gameDetector.h b/base/gameDetector.h
index f8268f8bdf..0d7ceb2b33 100644
--- a/base/gameDetector.h
+++ b/base/gameDetector.h
@@ -43,10 +43,26 @@ enum {
struct GameSettings {
const char *gameid;
- const char *description;
- uint32 features;
+ const char *description; // TODO: Rename this to "title" or so
+ uint32 features; // TODO: Probably should get rid of this field
};
+/**
+ * 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, g.features };
+ return dummy;
+}
+
+
class GameDetector {
typedef Common::String String;
diff --git a/engines/gob/gob.cpp b/engines/gob/gob.cpp
index 7a8bbee3bb..ae48c4a2d4 100644
--- a/engines/gob/gob.cpp
+++ b/engines/gob/gob.cpp
@@ -107,15 +107,7 @@ static const Gob::GobGameSettings gob_games[] = {
};
// Keep list of different supported games
-static const struct GobGameList {
- const char *gameid;
- const char *description;
- uint32 features;
- GameSettings toGameSettings() const {
- GameSettings dummy = { gameid, description, features };
- return dummy;
- }
-} gob_list[] = {
+static const GameSettings gob_list[] = {
{"gob1", "Gobliiins", Gob::GF_GOB1},
{"gob2", "Gobliins 2", Gob::GF_GOB2},
{0, 0, 0}
@@ -124,10 +116,10 @@ static const struct GobGameList {
GameList Engine_GOB_gameList() {
GameList games;
- const GobGameList *g = gob_list;
+ const GameSettings *g = gob_list;
while (g->gameid) {
- games.push_back(g->toGameSettings());
+ games.push_back(*g);
g++;
}
@@ -167,9 +159,9 @@ DetectedGameList Engine_GOB_detectGames(const FSList &fslist) {
if (detectedGames.isEmpty()) {
printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str);
- const GobGameList *g1 = gob_list;
+ const GameSettings *g1 = gob_list;
while (g1->gameid) {
- detectedGames.push_back(g1->toGameSettings());
+ detectedGames.push_back(*g1);
g1++;
}
}
diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp
index 469cf3d652..d918b5a2a7 100644
--- a/engines/kyra/kyra.cpp
+++ b/engines/kyra/kyra.cpp
@@ -65,10 +65,6 @@ struct KyraGameSettings {
uint32 features;
const char *md5sum;
const char *checkFile;
- GameSettings toGameSettings() const {
- GameSettings dummy = { gameid, description, features };
- return dummy;
- }
};
// We could get rid of md5 detection at least for kyra 1 since we can locate all
@@ -100,17 +96,7 @@ static const KyraGameSettings kyra_games[] = {
};
// Keep list of different supported games
-struct KyraGameList {
- const char *gameid;
- const char *description;
- uint32 features;
- GameSettings toGameSettings() const {
- GameSettings dummy = { gameid, description, features };
- return dummy;
- }
-};
-
-static const KyraGameList kyra_list[] = {
+static const GameSettings kyra_list[] = {
{ "kyra1", "The Legend of Kyrandia", 0 },
{ 0, 0, 0 }
};
@@ -145,10 +131,10 @@ static Common::Language convertKyraLang(uint32 features) {
GameList Engine_KYRA_gameList() {
GameList games;
- const KyraGameList *g = kyra_list;
+ const GameSettings *g = kyra_list;
while (g->gameid) {
- games.push_back(g->toGameSettings());
+ games.push_back(*g);
g++;
}
return games;
@@ -185,15 +171,15 @@ DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) {
}
for (g = kyra_games; g->gameid; g++) {
if (strcmp(g->md5sum, (char *)md5str) == 0) {
- detectedGames.push_back(DetectedGame(g->toGameSettings(), convertKyraLang(g->features), Common::kPlatformUnknown));
+ detectedGames.push_back(DetectedGame(toGameSettings(*g), convertKyraLang(g->features), Common::kPlatformUnknown));
}
}
if (detectedGames.isEmpty()) {
printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str);
- const KyraGameList *g1 = kyra_list;
+ const GameSettings *g1 = kyra_list;
while (g1->gameid) {
- detectedGames.push_back(g1->toGameSettings());
+ detectedGames.push_back(*g1);
g1++;
}
}
diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp
index f5dcc49e3c..d7f2f932a0 100644
--- a/engines/lure/lure.cpp
+++ b/engines/lure/lure.cpp
@@ -51,16 +51,12 @@ enum {
};
struct LureGameSettings {
- const char *name;
+ const char *gameid;
const char *description;
byte id;
uint32 features;
const char *md5sum;
const char *checkFile;
- GameSettings toGameSettings() const {
- GameSettings dummy = { name, description, features };
- return dummy;
- }
};
//
@@ -72,27 +68,17 @@ static const LureGameSettings lure_games[] = {
// Keep list of different supported games
-struct LureGameList {
- const char *name;
- const char *description;
- uint32 features;
- GameSettings toGameSettings() const {
- GameSettings dummy = { name, description, features };
- return dummy;
- }
-};
-
-static const LureGameList lure_list[] = {
+static const GameSettings lure_list[] = {
{ "lure", "Lure of the Temptress", 0 },
{ 0, 0, 0 }
};
GameList Engine_LURE_gameList() {
GameList games;
- const LureGameList *g = lure_list;
+ const GameSettings *g = lure_list;
- while (g->name) {
- games.push_back(g->toGameSettings());
+ while (g->gameid) {
+ games.push_back(*g);
g++;
}
return games;
@@ -109,7 +95,7 @@ DetectedGameList Engine_LURE_detectGames(const FSList &fslist) {
if (file->isDirectory())
continue;
- for (g = lure_games; g->name; g++) {
+ for (g = lure_games; g->gameid; g++) {
if (scumm_stricmp(file->displayName().c_str(), g->checkFile) == 0)
isFound = true;
}
@@ -127,17 +113,17 @@ DetectedGameList Engine_LURE_detectGames(const FSList &fslist) {
for (int i = 0; i < 16; i++) {
sprintf(md5str + i * 2, "%02x", (int)md5sum[i]);
}
- for (g = lure_games; g->name; g++) {
+ for (g = lure_games; g->gameid; g++) {
if (strcmp(g->md5sum, (char *)md5str) == 0) {
- detectedGames.push_back(g->toGameSettings());
+ detectedGames.push_back(toGameSettings(*g));
}
}
if (detectedGames.isEmpty()) {
debug("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str);
- const LureGameList *g1 = lure_list;
- while (g1->name) {
- detectedGames.push_back(g1->toGameSettings());
+ const GameSettings *g1 = lure_list;
+ while (g1->gameid) {
+ detectedGames.push_back(*g1);
g1++;
}
}
@@ -212,7 +198,7 @@ void LureEngine::detectGame() {
*md5str = 0;
- for (g = lure_games; g->name; g++) {
+ for (g = lure_games; g->gameid; g++) {
if (!Common::File::exists(g->checkFile))
continue;
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp
index 5f4c11917e..a864ee9b79 100644
--- a/engines/sword2/sword2.cpp
+++ b/engines/sword2/sword2.cpp
@@ -51,10 +51,6 @@ struct Sword2GameSettings {
const char *description;
uint32 features;
const char *detectname;
- GameSettings toGameSettings() const {
- GameSettings dummy = { gameid, description, features };
- return dummy;
- }
};
static const Sword2GameSettings sword2_settings[] = {
@@ -69,7 +65,7 @@ GameList Engine_SWORD2_gameList() {
const Sword2GameSettings *g = sword2_settings;
GameList games;
while (g->gameid) {
- games.push_back(g->toGameSettings());
+ games.push_back(toGameSettings(*g));
g++;
}
return games;
@@ -91,7 +87,7 @@ DetectedGameList Engine_SWORD2_detectGames(const FSList &fslist) {
if (0 == scumm_stricmp(g->detectname, gameName)) {
// Match found, add to list of candidates, then abort inner loop.
- detectedGames.push_back(g->toGameSettings());
+ detectedGames.push_back(toGameSettings(*g));
break;
}
}