[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_sndmgr.cpp,1.51,1.52

Max Horn fingolfin at users.sourceforge.net
Sat Aug 28 07:21:01 CEST 2004


Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12986

Modified Files:
	dimuse_sndmgr.cpp 
Log Message:
Reduce code duplication

Index: dimuse_sndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_sndmgr.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- dimuse_sndmgr.cpp	4 Jul 2004 06:14:18 -0000	1.51
+++ dimuse_sndmgr.cpp	28 Aug 2004 14:19:56 -0000	1.52
@@ -305,83 +305,58 @@
 		error("ImuseDigiSndMgr::openSound() can't alloc free sound slot");
 	}
 
+	const bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO));
 	bool result = false;
 	byte *ptr = NULL;
+	
+	switch (soundType) {
+	case IMUSE_RESOURCE:
+		assert(soundName[0] == 0);	// Paranoia check
 
-	if (soundName[0] == 0) {
-		sound->name[0] = 0;
-		if ((soundType == IMUSE_RESOURCE)) {
-			_vm->ensureResourceLoaded(rtSound, soundId);
-			_vm->lock(rtSound, soundId);
-			ptr = _vm->getResourceAddress(rtSound, soundId);
-			if (ptr == NULL) {
-				closeSound(sound);
-				return NULL;
-			}
-			sound->resPtr = ptr;
-			sound->soundId = soundId;
-			sound->type = soundType;
-			sound->volGroupId = volGroupId;
-			result = true;
-		} else if (soundType == IMUSE_BUNDLE) {
-			bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO));
-			if (volGroupId == IMUSE_VOLGRP_VOICE)
-				result = openVoiceBundle(sound, disk);
-			else if (volGroupId == IMUSE_VOLGRP_MUSIC)
-				result = openMusicBundle(sound, disk);
-			else
-				error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
-			if (!result) {
-				closeSound(sound);
-				return NULL;
-			}
-			if (sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside) == 0) {
-				closeSound(sound);
-				return NULL;
-			}
-			sound->soundId = soundId;
-			sound->type = soundType;
-			sound->volGroupId = volGroupId;
-		} else {
+		_vm->ensureResourceLoaded(rtSound, soundId);
+		_vm->lock(rtSound, soundId);
+		ptr = _vm->getResourceAddress(rtSound, soundId);
+		if (ptr == NULL) {
+			closeSound(sound);
+			return NULL;
+		}
+		sound->resPtr = ptr;
+		break;
+	case IMUSE_BUNDLE:
+		if (volGroupId == IMUSE_VOLGRP_VOICE)
+			result = openVoiceBundle(sound, disk);
+		else if (volGroupId == IMUSE_VOLGRP_MUSIC)
+			result = openMusicBundle(sound, disk);
+		else
 			error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
+		if (!result) {
+			closeSound(sound);
+			return NULL;
 		}
-	} else {
-		if (soundType == IMUSE_BUNDLE) {
-			bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO));
-			if (volGroupId == IMUSE_VOLGRP_VOICE)
-				result = openVoiceBundle(sound, disk);
-			else if (volGroupId == IMUSE_VOLGRP_MUSIC)
-				result = openMusicBundle(sound, disk);
-			else
-				error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
-			if (!result) {
+		if (soundName[0] == 0) {
+			if (sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside) == 0 || ptr == NULL) {
 				closeSound(sound);
 				return NULL;
 			}
-			if (sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside) == 0) {
+		} else {
+			if (sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside) == 0 || ptr == NULL) {
 				closeSound(sound);
 				return NULL;
 			}
-			strcpy(sound->name, soundName);
-			sound->soundId = soundId;
-			sound->type = soundType;
-			sound->volGroupId = volGroupId;
-		} else {
-			error("ImuseDigiSndMgr::openSound() Don't know how load sound: %s", soundName);
 		}
+		sound->resPtr = 0;
+		break;
+	default:
+		error("ImuseDigiSndMgr::openSound() Unknown soundType %d (trying to load sound %d)", soundType, soundId);
 	}
 
-	if (result) {
-		if (ptr == NULL) {
-			closeSound(sound);
-			return NULL;
-		}
-		sound->disk = _disk;
-		prepareSound(ptr, sound);
-		return sound;
-	}
-
-	return NULL;
+	strcpy(sound->name, soundName);
+	sound->soundId = soundId;
+	sound->type = soundType;
+	sound->volGroupId = volGroupId;
+	sound->disk = _disk;
+	prepareSound(ptr, sound);
+	return sound;
 }
 
 void ImuseDigiSndMgr::closeSound(soundStruct *soundHandle) {





More information about the Scummvm-git-logs mailing list