Removed GameDetector::_gameid in favor of using a config manager entry

svn-id: r21915
This commit is contained in:
Max Horn 2006-04-15 17:39:14 +00:00
parent dc5f513bcf
commit ad45318328
14 changed files with 72 additions and 78 deletions

View file

@ -62,8 +62,8 @@ const int ACTIONS_DEFAULT[ACTION_LAST] = { 0, 0, 0, 0, 0x11a, 0x11b, SDLK_MENU,
#endif #endif
// creator function according to Factory Pattern // creator function according to Factory Pattern
void SymbianActions::init(const Common::String &gameid) { void SymbianActions::init() {
_instance = new SymbianActions(gameid); _instance = new SymbianActions();
} }
@ -83,8 +83,8 @@ int SymbianActions::version() {
return ACTION_VERSION; return ACTION_VERSION;
} }
SymbianActions::SymbianActions(const Common::String &gameid) : SymbianActions::SymbianActions()
Actions(gameid) { : Actions() {
int i; int i;
for (i = 0; i < ACTION_LAST; i++) { for (i = 0; i < ACTION_LAST; i++) {
@ -121,17 +121,18 @@ void SymbianActions::initInstanceMain(OSystem *mainSystem) {
} }
void SymbianActions::initInstanceGame() { void SymbianActions::initInstanceGame() {
bool is_simon = (strncmp(_gameid.c_str(), "simon", 5) == 0); String gameid(ConfMan.get("gameid"));
bool is_sky = (_gameid == "sky"); bool is_simon = (strncmp(gameid.c_str(), "simon", 5) == 0);
bool is_queen = (_gameid == "queen"); bool is_sky = (gameid == "sky");
bool is_gob = (strncmp(_gameid.c_str(), "gob", 3) == 0); bool is_queen = (gameid == "queen");
bool is_ite = ((strncmp(_gameid.c_str(), "ite", 3) == 0) || bool is_gob = (strncmp(gameid.c_str(), "gob", 3) == 0);
(strncmp(_gameid.c_str(), "ihnm", 4) == 0)); bool is_ite = ((strncmp(gameid.c_str(), "ite", 3) == 0) ||
(strncmp(gameid.c_str(), "ihnm", 4) == 0));
Actions::initInstanceGame(); Actions::initInstanceGame();
// See if a right click mapping could be needed // See if a right click mapping could be needed
if (is_sky || _gameid == "samnmax" || is_gob) if (is_sky || gameid == "samnmax" || is_gob)
_right_click_needed = true; _right_click_needed = true;
// Initialize keys for different actions // Initialize keys for different actions

View file

@ -377,7 +377,7 @@ void OSystem_SDL_Symbian::setWindowCaption(const char *caption) {
} }
void OSystem_SDL_Symbian::check_mappings() { void OSystem_SDL_Symbian::check_mappings() {
if (!GUI::Actions::Instance()->_gameid.size() || GUI::Actions::Instance()->initialized()) if (ConfMan.get("gameid").empty() || GUI::Actions::Instance()->initialized())
return; return;
GUI::Actions::Instance()->initInstanceGame(); GUI::Actions::Instance()->initInstanceGame();

View file

@ -98,21 +98,22 @@ void CEActionsPocket::initInstanceMain(OSystem *mainSystem) {
} }
void CEActionsPocket::initInstanceGame() { void CEActionsPocket::initInstanceGame() {
bool is_simon = (strncmp(_gameid.c_str(), "simon", 5) == 0); String gameid(ConfMan.get("gameid"));
bool is_sword1 = (_gameid == "sword1"); bool is_simon = (strncmp(gameid.c_str(), "simon", 5) == 0);
bool is_sword2 = (strcmp(_gameid.c_str(), "sword2") == 0); bool is_sword1 = (gameid == "sword1");
bool is_queen = (_gameid == "queen"); bool is_sword2 = (strcmp(gameid.c_str(), "sword2") == 0);
bool is_sky = (_gameid == "sky"); bool is_queen = (gameid == "queen");
bool is_comi = (strncmp(_gameid.c_str(), "comi", 4) == 0); bool is_sky = (gameid == "sky");
bool is_gob = (strncmp(_gameid.c_str(), "gob", 3) == 0); bool is_comi = (strncmp(gameid.c_str(), "comi", 4) == 0);
bool is_ite = ((strncmp(_gameid.c_str(), "ite", 3) == 0) || bool is_gob = (strncmp(gameid.c_str(), "gob", 3) == 0);
(strncmp(_gameid.c_str(), "ihnm", 4) == 0)); bool is_ite = ((strncmp(gameid.c_str(), "ite", 3) == 0) ||
(strncmp(gameid.c_str(), "ihnm", 4) == 0));
GUI_Actions::initInstanceGame(); GUI_Actions::initInstanceGame();
// See if a right click mapping could be needed // See if a right click mapping could be needed
if (is_sword1 || is_sword2 || is_sky || is_queen || is_comi || is_gob || if (is_sword1 || is_sword2 || is_sky || is_queen || is_comi || is_gob ||
_gameid == "samnmax") gameid == "samnmax")
_right_click_needed = true; _right_click_needed = true;
// See if a "hide toolbar" mapping could be needed // See if a "hide toolbar" mapping could be needed

View file

@ -60,8 +60,8 @@ const int ACTIONS_SMARTPHONE_DEFAULT[] = { 0x111, 0x112, 0x114, 0x113, 0x11a, 0x
const int ACTIONS_SMARTPHONE_DEFAULT[] = { '4', '6', '8', '2', 0x11a, 0x11b, '0', VK_ESCAPE, '9', 0, VK_RETURN }; const int ACTIONS_SMARTPHONE_DEFAULT[] = { '4', '6', '8', '2', 0x11a, 0x11b, '0', VK_ESCAPE, '9', 0, VK_RETURN };
#endif #endif
void CEActionsSmartphone::init(const Common::String &gameid) { void CEActionsSmartphone::init() {
_instance = new CEActionsSmartphone(gameid); _instance = new CEActionsSmartphone();
} }
@ -81,9 +81,8 @@ int CEActionsSmartphone::version() {
return SMARTPHONE_ACTION_VERSION; return SMARTPHONE_ACTION_VERSION;
} }
CEActionsSmartphone::CEActionsSmartphone(const Common::String &gameid) : CEActionsSmartphone::CEActionsSmartphone()
GUI::Actions(gameid) : GUI::Actions() {
{
int i; int i;
for (i=0; i<SMARTPHONE_ACTION_LAST; i++) { for (i=0; i<SMARTPHONE_ACTION_LAST; i++) {
@ -112,17 +111,18 @@ void CEActionsSmartphone::initInstanceMain(OSystem *mainSystem) {
} }
void CEActionsSmartphone::initInstanceGame() { void CEActionsSmartphone::initInstanceGame() {
bool is_simon = (strncmp(_gameid.c_str(), "simon", 5) == 0); String gameid(ConfMan.get("gameid"));
bool is_sky = (_gameid == "sky"); bool is_simon = (strncmp(gameid.c_str(), "simon", 5) == 0);
bool is_queen = (_gameid == "queen"); bool is_sky = (gameid == "sky");
bool is_gob = (strncmp(_gameid.c_str(), "gob", 3) == 0); bool is_queen = (gameid == "queen");
bool is_ite = ((strncmp(_gameid.c_str(), "ite", 3) == 0) || bool is_gob = (strncmp(gameid.c_str(), "gob", 3) == 0);
(strncmp(_gameid.c_str(), "ihnm", 4) == 0)); bool is_ite = ((strncmp(gameid.c_str(), "ite", 3) == 0) ||
(strncmp(gameid.c_str(), "ihnm", 4) == 0));
GUI_Actions::initInstanceGame(); GUI_Actions::initInstanceGame();
// See if a right click mapping could be needed // See if a right click mapping could be needed
if (is_sky || _gameid == "samnmax" || is_gob) if (is_sky || gameid == "samnmax" || is_gob)
_right_click_needed = true; _right_click_needed = true;
// Initialize keys for different actions // Initialize keys for different actions

View file

@ -522,7 +522,7 @@ bool OSystem_WINCE3::checkOggHighSampleRate() {
void OSystem_WINCE3::get_sample_rate() { void OSystem_WINCE3::get_sample_rate() {
// Force at least medium quality FM synthesis for FOTAQ // Force at least medium quality FM synthesis for FOTAQ
Common::String gameid(GUI::Actions::Instance()->_gameid); Common::String gameid(ConfMan.get("gameid"));
if (gameid == "queen") { if (gameid == "queen") {
if (!((ConfMan.hasKey("FM_high_quality") && ConfMan.getBool("FM_high_quality")) || if (!((ConfMan.hasKey("FM_high_quality") && ConfMan.getBool("FM_high_quality")) ||
(ConfMan.hasKey("FM_medium_quality") && ConfMan.getBool("FM_medium_quality")))) { (ConfMan.hasKey("FM_medium_quality") && ConfMan.getBool("FM_medium_quality")))) {
@ -653,9 +653,9 @@ bool OSystem_WINCE3::setSoundCallback(SoundProc proc, void *param) {
void OSystem_WINCE3::check_mappings() { void OSystem_WINCE3::check_mappings() {
CEActionsPocket *instance; CEActionsPocket *instance;
Common::String gameid(GUI::Actions::Instance()->_gameid); Common::String gameid(ConfMan.get("gameid"));
if (!gameid.size() || GUI_Actions::Instance()->initialized()) if (gameid.empty() || GUI_Actions::Instance()->initialized())
return; return;
GUI_Actions::Instance()->initInstanceGame(); GUI_Actions::Instance()->initInstanceGame();
@ -707,10 +707,10 @@ void OSystem_WINCE3::check_mappings() {
} }
void OSystem_WINCE3::update_game_settings() { void OSystem_WINCE3::update_game_settings() {
Common::String gameid(GUI::Actions::Instance()->_gameid); Common::String gameid(ConfMan.get("gameid"));
// Finish panel initialization // Finish panel initialization
if (!_panelInitialized && gameid.size()) { if (!_panelInitialized && !gameid.empty()) {
Panel *panel; Panel *panel;
_panelInitialized = true; _panelInitialized = true;
// Add the main panel // Add the main panel

View file

@ -261,7 +261,7 @@ GameDescriptor GameDetector::findGame(const String &gameName, const Plugin **plu
PluginList::const_iterator iter = plugins.begin(); PluginList::const_iterator iter = plugins.begin();
for (iter = plugins.begin(); iter != plugins.end(); ++iter) { for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
result = (*iter)->findGame(gameName.c_str()); result = (*iter)->findGame(gameName.c_str());
if (result.gameid.size() > 0) { if (!result.gameid.empty()) {
if (plugin) if (plugin)
*plugin = *iter; *plugin = *iter;
break; break;
@ -581,14 +581,12 @@ void GameDetector::setTarget(const String &target) {
_targetName = target; _targetName = target;
ConfMan.setActiveDomain(target); ConfMan.setActiveDomain(target);
// Make sure the gameid is set in the config manager, and that it is lowercase.
String gameid(_targetName);
if (ConfMan.hasKey("gameid")) if (ConfMan.hasKey("gameid"))
_gameid = ConfMan.get("gameid"); gameid = ConfMan.get("gameid");
else gameid.toLowercase();
_gameid = _targetName; ConfMan.set("gameid", gameid);
// TODO: In the future, simply insert the gameid into the transient domain.
// That way, all code (including backends) can reliably access it.
//ConfMan.set("gameid", _gameid, Common::ConfigManager::kTransientDomain);
} }
const Plugin *GameDetector::detectMain() { const Plugin *GameDetector::detectMain() {
@ -599,8 +597,8 @@ const Plugin *GameDetector::detectMain() {
return 0; return 0;
} }
printf("Looking for %s\n", _gameid.c_str()); printf("Looking for %s\n", ConfMan.get("gameid").c_str());
GameDescriptor game = findGame(_gameid, &plugin); GameDescriptor game = findGame(ConfMan.get("gameid"), &plugin);
if (plugin == 0) { if (plugin == 0) {
printf("Failed game detection\n"); printf("Failed game detection\n");

View file

@ -70,7 +70,6 @@ public:
const Plugin *detectMain(); const Plugin *detectMain();
String _targetName; String _targetName;
String _gameid;
public: public:
static GameDescriptor findGame(const String &gameName, const Plugin **plugin = NULL); static GameDescriptor findGame(const String &gameName, const Plugin **plugin = NULL);

View file

@ -181,7 +181,7 @@ static int runGame(const Plugin *plugin, GameDetector &detector, OSystem &system
// Set the window caption to the game name // Set the window caption to the game name
Common::String caption(ConfMan.get("description", detector._targetName)); Common::String caption(ConfMan.get("description", detector._targetName));
Common::String desc = GameDetector::findGame(detector._gameid).description; Common::String desc = GameDetector::findGame(ConfMan.get("gameid")).description;
if (caption.empty() && !desc.empty()) if (caption.empty() && !desc.empty())
caption = desc; caption = desc;
if (caption.empty()) if (caption.empty())
@ -292,7 +292,7 @@ extern "C" int scummvm_main(int argc, char *argv[]) {
#if defined(__SYMBIAN32__) || defined(_WIN32_WCE) #if defined(__SYMBIAN32__) || defined(_WIN32_WCE)
// init keymap support here: we wanna move this somewhere else? // init keymap support here: we wanna move this somewhere else?
GUI::Actions::init(detector._gameid); GUI::Actions::init(ConfMan.get("gameid"));
#endif #endif
#ifdef PALMOS_68K #ifdef PALMOS_68K

View file

@ -1620,15 +1620,15 @@ DetectedGameList Engine_SCUMM_detectGames(const FSList &fslist) {
*/ */
Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) { Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) {
Engine *engine; Engine *engine;
const char *gameid = ConfMan.get("gameid").c_str();
// We start by checking whether the specified game ID is obsolete. // We start by checking whether the specified game ID is obsolete.
// If that is the case, we automatically upgrade the target to use // If that is the case, we automatically upgrade the target to use
// the correct new game ID (and platform, if specified). // the correct new game ID (and platform, if specified).
const ObsoleteGameID *o = obsoleteGameIDsTable; for (const ObsoleteGameID *o = obsoleteGameIDsTable; o->from; ++o) {
while (o->from) { if (!scumm_stricmp(gameid, o->from)) {
if (!scumm_stricmp(detector->_gameid.c_str(), o->from)) {
// Match found, perform upgrade // Match found, perform upgrade
detector->_gameid = o->to; gameid = o->to;
ConfMan.set("gameid", o->to); ConfMan.set("gameid", o->to);
if (o->platform != Common::kPlatformUnknown) if (o->platform != Common::kPlatformUnknown)
@ -1638,14 +1638,13 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) {
ConfMan.flushToDisk(); ConfMan.flushToDisk();
break; break;
} }
o++;
} }
// Lookup the game ID in our database. If this lookup fails, then // Lookup the game ID in our database. If this lookup fails, then
// the game ID is unknown, and we have to abort. // the game ID is unknown, and we have to abort.
const GameSettings *g = gameVariantsTable; const GameSettings *g = gameVariantsTable;
while (g->gameid) { while (g->gameid) {
if (!scumm_stricmp(detector->_gameid.c_str(), g->gameid)) if (!scumm_stricmp(gameid, g->gameid))
break; break;
g++; g++;
} }
@ -1655,7 +1654,7 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) {
// We now want to calculate the MD5 of the games detection file, so that we // We now want to calculate the MD5 of the games detection file, so that we
// can store it in savegames etc.. // can store it in savegames etc..
const char *gameid = g->gameid; gameid = g->gameid;
char detectName[256], tempName[256]; char detectName[256], tempName[256];
uint8 md5sum[16]; uint8 md5sum[16];
SubstResFileNames subst = { 0, 0, kGenAsIs }; SubstResFileNames subst = { 0, 0, kGenAsIs };

View file

@ -113,11 +113,12 @@ DetectedGameList Engine_SIMON_detectGames(const FSList &fslist) {
} }
Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst) { Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst) {
const ObsoleteGameID *o = obsoleteGameIDsTable; const char *gameid = ConfMan.get("gameid").c_str();
while (o->from) {
if (!scumm_stricmp(detector->_gameid.c_str(), o->from)) {
detector->_gameid = o->to;
for (const ObsoleteGameID *o = obsoleteGameIDsTable; o->from; ++o) {
if (!scumm_stricmp(gameid, o->from)) {
// Match found, perform upgrade
gameid = o->to;
ConfMan.set("gameid", o->to); ConfMan.set("gameid", o->to);
if (o->platform != Common::kPlatformUnknown) if (o->platform != Common::kPlatformUnknown)
@ -127,7 +128,6 @@ Engine *Engine_SIMON_create(GameDetector *detector, OSystem *syst) {
ConfMan.flushToDisk(); ConfMan.flushToDisk();
break; break;
} }
o++;
} }
return new Simon::SimonEngine(syst); return new Simon::SimonEngine(syst);

View file

@ -134,7 +134,7 @@ void SwordEngine::errorString(const char *buf1, char *buf2) {
SwordEngine::SwordEngine(GameDetector *detector, OSystem *syst) SwordEngine::SwordEngine(GameDetector *detector, OSystem *syst)
: Engine(syst) { : Engine(syst) {
if (0 == scumm_stricmp(detector->_gameid.c_str(), "sword1demo")) if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword1demo"))
_features = GF_DEMO; _features = GF_DEMO;
else else
_features = 0; _features = 0;

View file

@ -129,7 +129,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) : Engine(syst)
Common::File::addDefaultDirectory(_gameDataPath + "sword2/"); Common::File::addDefaultDirectory(_gameDataPath + "sword2/");
Common::File::addDefaultDirectory(_gameDataPath + "video/"); Common::File::addDefaultDirectory(_gameDataPath + "video/");
if (0 == scumm_stricmp(detector->_gameid.c_str(), "sword2demo")) if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo"))
_features = GF_DEMO; _features = GF_DEMO;
else else
_features = 0; _features = 0;

View file

@ -39,8 +39,8 @@ Actions* Actions::Instance() {
return _instance; return _instance;
} }
Actions::Actions(const Common::String &gameid) : Actions::Actions() :
_gameid(gameid), _mapping_active(false), _initialized(false) _mapping_active(false), _initialized(false)
{ {
} }
@ -49,15 +49,15 @@ Actions::~Actions() {
} }
// call the correct object creator function according to the Factory Pattern // call the correct object creator function according to the Factory Pattern
void Actions::init(const Common::String &gameid) { void Actions::init() {
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
// For WinCE: now use software + Factory pattern to create correct objects // For WinCE: now use software + Factory pattern to create correct objects
if (!CEDevice::isSmartphone()) if (!CEDevice::isSmartphone())
CEActionsPocket::init(gameid); CEActionsPocket::init();
else else
CEActionsSmartphone::init(gameid); CEActionsSmartphone::init();
#elif defined(__SYMBIAN32__) #elif defined(__SYMBIAN32__)
SymbianActions::init(gameid); SymbianActions::init();
#endif #endif
} }

View file

@ -37,7 +37,7 @@ class Actions {
public: public:
static Actions* Instance(); static Actions* Instance();
static void init(const Common::String &gameid); static void init();
virtual void initInstanceMain(OSystem *mainSystem); virtual void initInstanceMain(OSystem *mainSystem);
virtual void initInstanceGame(); virtual void initInstanceGame();
bool initialized(); bool initialized();
@ -65,12 +65,8 @@ public:
virtual ~Actions(); virtual ~Actions();
public:
// Since _gameid is const it's safe to let the public read it.
const Common::String _gameid;
protected: protected:
Actions(const Common::String &gameid); Actions();
protected: protected:
static Actions* _instance; static Actions* _instance;