diff options
author | Oystein Eftevaag | 2006-04-27 00:39:10 +0000 |
---|---|---|
committer | Oystein Eftevaag | 2006-04-27 00:39:10 +0000 |
commit | 9ec94f6fcb2ac09c9d78e04b816fdb159d0a9286 (patch) | |
tree | 14deb1dd0d5ce0276ee7822889904143692c82e6 | |
parent | 9d5098e0f83a56c98adca8472468468a8ed1b0d0 (diff) | |
download | scummvm-rg350-9ec94f6fcb2ac09c9d78e04b816fdb159d0a9286.tar.gz scummvm-rg350-9ec94f6fcb2ac09c9d78e04b816fdb159d0a9286.tar.bz2 scummvm-rg350-9ec94f6fcb2ac09c9d78e04b816fdb159d0a9286.zip |
Move the detector code out of the constructor and into init() to do error handling (specifically the GUI error message if no game is found in the specified directory), and cleans up the constructor/destructor a bit to allow a clean exit.
svn-id: r22189
-rw-r--r-- | engines/kyra/kyra.cpp | 135 |
1 files changed, 79 insertions, 56 deletions
diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index 0f0595f6ec..a52acb74f2 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -241,44 +241,48 @@ KyraEngine::KyraEngine(OSystem *system) _drinkAnimationTable = _brandonToWispTable = _magicAnimationTable = _brandonStoneTable = 0; _drinkAnimationTableSize = _brandonToWispTableSize = _magicAnimationTableSize = _brandonStoneTableSize = 0; memset(&_specialPalettes, 0, sizeof(_specialPalettes)); + _debugger = 0; + _sprites = 0; + _animator = 0; + _screen = 0; + _res = 0; + _sound = 0; + _saveFileMan = 0; + _seq = 0; + _scriptInterpreter = 0; + _text = 0; + _npcScriptData = 0; + _scriptMain = 0; + _scriptClickData = 0; + _scriptClick = 0; + _characterList = 0; + _movFacingTable = 0; + memset(_shapes, 0, sizeof(_shapes)); + _scrollUpButton.process0PtrShape = _scrollUpButton.process1PtrShape = _scrollUpButton.process2PtrShape = 0; + _scrollDownButton.process0PtrShape = _scrollDownButton.process1PtrShape = _scrollDownButton.process2PtrShape = 0; + memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable)); +} - // Setup mixer - if (!_mixer->isReady()) { - warning("Sound initialization failed."); - } - - _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); - _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); - _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); - - // sets up all engine specific debug levels - Common::addSpecialDebugLevel(kDebugLevelScriptFuncs, "ScriptFuncs", "Script function debug level"); - Common::addSpecialDebugLevel(kDebugLevelScript, "Script", "Script interpreter debug level"); - Common::addSpecialDebugLevel(kDebugLevelSprites, "Sprites", "Sprite debug level"); - Common::addSpecialDebugLevel(kDebugLevelScreen, "Screen", "Screen debug level"); - Common::addSpecialDebugLevel(kDebugLevelSound, "Sound", "Sound debug level"); - Common::addSpecialDebugLevel(kDebugLevelAnimator, "Animator", "Animator debug level"); - Common::addSpecialDebugLevel(kDebugLevelMain, "Main", "Generic debug level"); - Common::addSpecialDebugLevel(kDebugLevelGUI, "GUI", "GUI debug level"); - Common::addSpecialDebugLevel(kDebugLevelSequence, "Sequence", "Sequence debug level"); - Common::addSpecialDebugLevel(kDebugLevelMovie, "Movie", "Movie debug level"); - +int KyraEngine::init() { // Detect game features based on MD5. Again brutally ripped from Gobliins. uint8 md5sum[16]; char md5str[32 + 1]; const GameSettings *g; - bool found = false; + bool versionFound = false; + bool fileFound = false; // TODO // Fallback. Maybe we will be able to determine game type from game // data contents _features = 0; - + memset(md5str, 0, sizeof(md5str)); for (g = kyra_games; g->gameid; g++) { if (!Common::File::exists(g->checkFile)) continue; + fileFound = true; + if (Common::md5_file(g->checkFile, md5sum, kMD5FileSizeLimit)) { for (int j = 0; j < 16; j++) { sprintf(md5str + j*2, "%02x", (int)md5sum[j]); @@ -293,44 +297,63 @@ KyraEngine::KyraEngine(OSystem *system) if (g->description) g_system->setWindowCaption(g->description); - found = true; + versionFound = true; break; } } - if (!found) { - printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str); - _features = 0; - _game = GI_KYRA1; - Common::File test; - if (test.open("INTRO.VRM")) { - _features |= GF_TALKIE; - } else { - _features |= GF_FLOPPY; - } + if (fileFound) { + if (!versionFound) { + printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str); + _features = 0; + _game = GI_KYRA1; + Common::File test; + if (test.open("INTRO.VRM")) { + _features |= GF_TALKIE; + } else { + _features |= GF_FLOPPY; + } - // tries to detect the language - const KyraLanguageTable *lang = kyra_languages; - for (; lang->file; ++lang) { - if (test.open(lang->file)) { - _features |= lang->language; - found = true; - break; + // tries to detect the language + const KyraLanguageTable *lang = kyra_languages; + for (; lang->file; ++lang) { + if (test.open(lang->file)) { + _features |= lang->language; + versionFound = true; + break; + } } - } - if (!found) { - _features |= GF_LNGUNK; + if (!versionFound) { + _features |= GF_LNGUNK; + } } + } else { + GUIErrorMessage("No version of Kyrandia found in specificed directory."); + return -1; } - // FIXME: TODO: - // Please, deal with a case when _no_ valid game is present - // in specified directory. Currently it just asserts() later - // in the code which is not nice. [sev] -} + // Setup mixer + if (!_mixer->isReady()) { + warning("Sound initialization failed."); + } + + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); + + // sets up all engine specific debug levels + Common::addSpecialDebugLevel(kDebugLevelScriptFuncs, "ScriptFuncs", "Script function debug level"); + Common::addSpecialDebugLevel(kDebugLevelScript, "Script", "Script interpreter debug level"); + Common::addSpecialDebugLevel(kDebugLevelSprites, "Sprites", "Sprite debug level"); + Common::addSpecialDebugLevel(kDebugLevelScreen, "Screen", "Screen debug level"); + Common::addSpecialDebugLevel(kDebugLevelSound, "Sound", "Sound debug level"); + Common::addSpecialDebugLevel(kDebugLevelAnimator, "Animator", "Animator debug level"); + Common::addSpecialDebugLevel(kDebugLevelMain, "Main", "Generic debug level"); + Common::addSpecialDebugLevel(kDebugLevelGUI, "GUI", "GUI debug level"); + Common::addSpecialDebugLevel(kDebugLevelSequence, "Sequence", "Sequence debug level"); + Common::addSpecialDebugLevel(kDebugLevelMovie, "Movie", "Movie debug level"); -int KyraEngine::init() { _system->beginGFXTransaction(); initCommonGFX(false); //for debug reasons (see Screen::updateScreen) @@ -521,10 +544,6 @@ int KyraEngine::init() { } KyraEngine::~KyraEngine() { - closeFinalWsa(); - _scriptInterpreter->unloadScript(_npcScriptData); - _scriptInterpreter->unloadScript(_scriptClickData); - delete _debugger; delete _sprites; delete _animator; @@ -567,8 +586,6 @@ KyraEngine::~KyraEngine() { for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) { free(_sceneAnimTable[i]); } - - Common::clearAllSpecialDebugLevels(); } void KyraEngine::errorString(const char *buf1, char *buf2) { @@ -744,6 +761,12 @@ void KyraEngine::quitGame() { _movieObjects[i] = 0; } + closeFinalWsa(); + _scriptInterpreter->unloadScript(_npcScriptData); + _scriptInterpreter->unloadScript(_scriptClickData); + + Common::clearAllSpecialDebugLevels(); + _system->quit(); } |