[Scummvm-cvs-logs] SF.net SVN: scummvm: [24783] scummvm/trunk/engines/queen

cyx at users.sourceforge.net cyx at users.sourceforge.net
Fri Nov 24 19:37:43 CET 2006


Revision: 24783
          http://svn.sourceforge.net/scummvm/?rev=24783&view=rev
Author:   cyx
Date:     2006-11-24 10:37:43 -0800 (Fri, 24 Nov 2006)

Log Message:
-----------
simplification, removed some duplicated code

Modified Paths:
--------------
    scummvm/trunk/engines/queen/cutaway.cpp
    scummvm/trunk/engines/queen/graphics.cpp
    scummvm/trunk/engines/queen/logic.cpp
    scummvm/trunk/engines/queen/sound.cpp
    scummvm/trunk/engines/queen/sound.h
    scummvm/trunk/engines/queen/talk.cpp

Modified: scummvm/trunk/engines/queen/cutaway.cpp
===================================================================
--- scummvm/trunk/engines/queen/cutaway.cpp	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/cutaway.cpp	2006-11-24 18:37:43 UTC (rev 24783)
@@ -1242,7 +1242,7 @@
 			char voiceFileName[MAX_STRING_SIZE];
 			findCdCut(_basename, index, voiceFileName);
 			strcat(voiceFileName, "1");
-			_vm->sound()->playSfx(voiceFileName, true);
+			_vm->sound()->playSpeech(voiceFileName);
 		}
 
 		if (OBJECT_TYPE_TEXT_SPEAK == type && _vm->sound()->speechOn() && !_vm->subtitles())

Modified: scummvm/trunk/engines/queen/graphics.cpp
===================================================================
--- scummvm/trunk/engines/queen/graphics.cpp	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/graphics.cpp	2006-11-24 18:37:43 UTC (rev 24783)
@@ -380,7 +380,7 @@
 			if (pbs->animating) {
 				pbs->animOneStep();
 				if (pbs->frameNum > 500) { // SFX frame
-					_vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+					_vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
 					pbs->frameNum -= 500;
 				}
 			}
@@ -1125,7 +1125,7 @@
 	// this problem since its playSfx() function returns immediately
 	// if a sound is already being played.
 	if (_lastSoundIndex == 0 || _index - _lastSoundIndex >= SFX_SKIP) {
-		_vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+		_vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
 		_lastSoundIndex = _index;
 	}
 }

Modified: scummvm/trunk/engines/queen/logic.cpp
===================================================================
--- scummvm/trunk/engines/queen/logic.cpp	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/logic.cpp	2006-11-24 18:37:43 UTC (rev 24783)
@@ -1760,7 +1760,7 @@
 	lightningBob->x = 160;
 	lightningBob->y = 0;
 
-	_vm->sound()->playSfx(currentRoomSfx(), false);
+	_vm->sound()->playSfx(currentRoomSfx());
 
 	_vm->bankMan()->unpack(18, lightningBob->frameNum, 15);
 	_vm->bankMan()->unpack(4,  planeBob    ->frameNum, 15);

Modified: scummvm/trunk/engines/queen/sound.cpp
===================================================================
--- scummvm/trunk/engines/queen/sound.cpp	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/sound.cpp	2006-11-24 18:37:43 UTC (rev 24783)
@@ -82,39 +82,27 @@
 }
 
 void Sound::waitFinished(bool isSpeech) {
-	if (isSpeech)
-		while (_mixer->isSoundHandleActive(_speechHandle))
-			_vm->input()->delay(10);
-	else
-		while (_mixer->isSoundHandleActive(_sfxHandle))
-			_vm->input()->delay(10);
+	while (_mixer->isSoundHandleActive(isSpeech ? _speechHandle : _sfxHandle))
+		_vm->input()->delay(10);
 }
 
-void Sound::playSfx(uint16 sfx, bool isSpeech) {
-	if (isSpeech && !speechOn()) return;
-	else if (!sfxOn()) return;
-
-	if (sfx != 0) {
-		char name[13];
+void Sound::playSfx(uint16 sfx) {
+	if (sfxOn() && sfx != 0) {
 #ifndef PALMOS_68K
-		strcpy(name, _sfxName[sfx - 1]);
+		playSound(_sfxName[sfx - 1], false);
 #else
-		strncpy(name, _sfxName + 10 * (sfx - 1), 10);	// saved as 8char + /0/0
+		playSound(_sfxName + 10 * (sfx - 1), false);	// saved as 8char + /0/0
 #endif
-		strcat(name, ".SB");
-		waitFinished(isSpeech);
-		if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
-			_speechSfxExists = isSpeech;
-		} else {
-			_speechSfxExists = false;
-		}
 	}
 }
 
-void Sound::playSfx(const char *base, bool isSpeech) {
-	if (isSpeech && !speechOn()) return;
-	else if (!sfxOn()) return;
+void Sound::playSpeech(const char *base) {
+	if (speechOn()) {
+		playSound(base, true);
+	}
+}
 
+void Sound::playSound(const char *base, bool isSpeech) {
 	char name[13];
 	strcpy(name, base);
 	// alter filename to add zeros and append ".SB"
@@ -124,7 +112,10 @@
 	}
 	strcat(name, ".SB");
 	waitFinished(isSpeech);
-	if (sfxPlay(name, isSpeech ? &_speechHandle : &_sfxHandle)) {
+	uint32 size;
+	Common::File *f = _vm->resource()->giveSound(name, &size);
+	if (f) {
+		playSoundData(f, size, isSpeech ? &_speechHandle : &_sfxHandle);
 		_speechSfxExists = isSpeech;
 	} else {
 		_speechSfxExists = false;
@@ -149,8 +140,7 @@
 	}
 
 	if (_tune[newTune].sfx[0]) {
-		if (sfxOn())
-			playSfx(_tune[newTune].sfx[0], false);
+		playSfx(_tune[newTune].sfx[0]);
 		return;
 	}
 
@@ -167,7 +157,6 @@
 		_vm->music()->toggleVChange();
 	default:
 		return;
-		break;
 	}
 
 	_lastOverride = songNum;
@@ -184,75 +173,50 @@
 	_lastOverride = (int16)READ_BE_INT16(ptr); ptr += 2;
 }
 
-bool SilentSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
-	return false;
+void SilentSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
 }
 
-bool SBSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
-	uint32 size;
-	Common::File *f = _vm->resource()->giveSound(name, &size);
-	if (f) {
-		int headerSize;
-		f->seek(2, SEEK_CUR);
-		uint16 version = f->readUint16LE();
-		switch (version) {
-		case 104:
-			headerSize = SB_HEADER_SIZE_V104;
-			break;
-		case 110:
-			headerSize = SB_HEADER_SIZE_V110;
-			break;
-		default:
-			warning("Unhandled SB file version %d, defaulting to 104\n", version);
-			headerSize = SB_HEADER_SIZE_V104;
-			break;
-		}
-		f->seek(headerSize - 4, SEEK_CUR);
-		size -= headerSize;
-		uint8 *sound = (uint8 *)malloc(size);
-		if (sound) {
-			f->read(sound, size);
-			byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
-			_mixer->playRaw(soundHandle, sound, size, 11025, flags);
-			return true;
-		}
+void SBSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+	int headerSize;
+	f->seek(2, SEEK_CUR);
+	uint16 version = f->readUint16LE();
+	switch (version) {
+	case 104:
+		headerSize = SB_HEADER_SIZE_V104;
+		break;
+	case 110:
+		headerSize = SB_HEADER_SIZE_V110;
+		break;
+	default:
+		warning("Unhandled SB file version %d, defaulting to 104\n", version);
+		headerSize = SB_HEADER_SIZE_V104;
+		break;
 	}
-	return false;
+	f->seek(headerSize - 4, SEEK_CUR);
+	size -= headerSize;
+	uint8 *sound = (uint8 *)malloc(size);
+	if (sound) {
+		f->read(sound, size);
+		byte flags = Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE;
+		_mixer->playRaw(soundHandle, sound, size, 11025, flags);
+	}
 }
 
 #ifdef USE_MAD
-bool MP3Sound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
-	uint32 size;
-	Common::File *f = _vm->resource()->giveSound(name, &size);
-	if (f) {
-		_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeMP3Stream(f, size));
-		return true;
-	}
-	return false;
+void MP3Sound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeMP3Stream(f, size));
 }
 #endif
 
 #ifdef USE_VORBIS
-bool OGGSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
-	uint32 size;
-	Common::File *f = _vm->resource()->giveSound(name, &size);
-	if (f) {
-		_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeVorbisStream(f, size));
-		return true;
-	}
-	return false;
+void OGGSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeVorbisStream(f, size));
 }
 #endif
 
 #ifdef USE_FLAC
-bool FLACSound::sfxPlay(const char *name, Audio::SoundHandle *soundHandle) {
-	uint32 size;
-	Common::File *f = _vm->resource()->giveSound(name, &size);
-	if (f) {
-		_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeFlacStream(f, size));
-		return true;
-	}
-	return false;
+void FLACSound::playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) {
+	_mixer->playInputStream(Audio::Mixer::kSFXSoundType, soundHandle, Audio::makeFlacStream(f, size));
 }
 #endif
 

Modified: scummvm/trunk/engines/queen/sound.h
===================================================================
--- scummvm/trunk/engines/queen/sound.h	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/sound.h	2006-11-24 18:37:43 UTC (rev 24783)
@@ -27,6 +27,10 @@
 #include "sound/mixer.h"
 #include "queen/defs.h"
 
+namespace Common {
+	class File;
+}
+
 namespace Queen {
 
 class Input;
@@ -54,10 +58,9 @@
 public:
 	Sound(Audio::Mixer *mixer, QueenEngine *vm);
 	virtual ~Sound();
-	virtual bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle) = 0;
 	static Sound *giveSound(Audio::Mixer *mixer, QueenEngine *vm, uint8 compression);
-	void playSfx(uint16 sfx, bool isSpeech);
-	void playSfx(const char *base, bool isSpeech);
+	void playSfx(uint16 sfx);
+	void playSpeech(const char *base);
 	void playSong(int16 songNum);
 	void playLastSong()		{ playSong(_lastOverride); }
 	void stopSpeech()		{ _mixer->stopHandle(_speechHandle); }
@@ -103,6 +106,8 @@
 
 protected:
 	void waitFinished(bool isSpeech);
+	void playSound(const char *base, bool isSpeech);
+	virtual void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) = 0;
 
 	Audio::Mixer *_mixer;
 	QueenEngine *_vm;
@@ -120,20 +125,23 @@
 class SilentSound : public Sound {
 public:
 	SilentSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
-	bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+	void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
 };
 
 class SBSound : public Sound {
 public:
 	SBSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
-	bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+	void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
 };
 
 #ifdef USE_MAD
 class MP3Sound : public Sound {
 public:
 	MP3Sound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
-	bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+	void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
 };
 #endif
 
@@ -141,7 +149,8 @@
 class OGGSound : public Sound {
 public:
 	OGGSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
-	bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+	void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle);
 };
 #endif
 
@@ -149,7 +158,8 @@
 class FLACSound : public Sound {
 public:
 	FLACSound(Audio::Mixer *mixer, QueenEngine *vm) : Sound(mixer, vm) {};
-	bool sfxPlay(const char *name, Audio::SoundHandle *soundHandle);
+protected:
+	void playSoundData(const char *name, Audio::SoundHandle *soundHandle);
 };
 #endif // #ifdef USE_FLAC
 

Modified: scummvm/trunk/engines/queen/talk.cpp
===================================================================
--- scummvm/trunk/engines/queen/talk.cpp	2006-11-24 18:24:45 UTC (rev 24782)
+++ scummvm/trunk/engines/queen/talk.cpp	2006-11-24 18:37:43 UTC (rev 24783)
@@ -677,7 +677,7 @@
 
 		if (frame > 500) {
 			frame -= 500;
-			_vm->sound()->playSfx(_vm->logic()->currentRoomSfx(), false);
+			_vm->sound()->playSfx(_vm->logic()->currentRoomSfx());
 		}
 
 		if (torso) {
@@ -798,9 +798,8 @@
 
 	// French talkie version has a useless voice file ;	c30e_102 file is the same as c30e_101,
 	// so there is no need to play it. This voice was used in room 30 (N8) when talking to Klunk.
-	if (!(_vm->resource()->getLanguage() == Common::FR_FRA && !strcmp(voiceFileName, "c30e_102"))
-		&& _vm->sound()->speechOn())
-		_vm->sound()->playSfx(voiceFileName, true);
+	if (!(_vm->resource()->getLanguage() == Common::FR_FRA && !strcmp(voiceFileName, "c30e_102")))
+		_vm->sound()->playSpeech(voiceFileName);
 
 	int faceDirectionCommand = 0;
 


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