[Scummvm-cvs-logs] SF.net SVN: scummvm: [22189] scummvm/trunk/engines/kyra/kyra.cpp

vinterstum at users.sourceforge.net vinterstum at users.sourceforge.net
Wed Apr 26 17:40:03 CEST 2006


Revision: 22189
Author:   vinterstum
Date:     2006-04-26 17:39:10 -0700 (Wed, 26 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22189&view=rev

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/kyra.cpp
Modified: scummvm/trunk/engines/kyra/kyra.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra.cpp	2006-04-27 00:02:06 UTC (rev 22188)
+++ scummvm/trunk/engines/kyra/kyra.cpp	2006-04-27 00:39:10 UTC (rev 22189)
@@ -241,44 +241,48 @@
 	_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 @@
 			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.");
+	}
 
-int KyraEngine::init() {
+	_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");
+
 	_system->beginGFXTransaction();
 		initCommonGFX(false);
 		//for debug reasons (see Screen::updateScreen)
@@ -521,10 +544,6 @@
 }
 
 KyraEngine::~KyraEngine() {
-	closeFinalWsa();
-	_scriptInterpreter->unloadScript(_npcScriptData);
-	_scriptInterpreter->unloadScript(_scriptClickData);
-
 	delete _debugger;
 	delete _sprites;
 	delete _animator;
@@ -567,8 +586,6 @@
 	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 @@
 		_movieObjects[i] = 0;
 	}
 
+	closeFinalWsa();
+	_scriptInterpreter->unloadScript(_npcScriptData);
+	_scriptInterpreter->unloadScript(_scriptClickData);
+
+	Common::clearAllSpecialDebugLevels();
+
 	_system->quit();
 }
 


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