[Scummvm-cvs-logs] SF.net SVN: scummvm: [25204] scummvm/trunk/engines/sword2

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Fri Jan 26 19:21:42 CET 2007


Revision: 25204
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25204&view=rev
Author:   eriktorbjorn
Date:     2007-01-26 10:21:41 -0800 (Fri, 26 Jan 2007)

Log Message:
-----------
Added separate function for playing cutscene lead-in/out sounds, and made sure
that these are stopped whenever the engine is going to do a mass killing of
game resources, e.g. when restoring or restarting the game. Should fix bug
#1645480. (This was a regression added during the rewrite to support DXA.)

Modified Paths:
--------------
    scummvm/trunk/engines/sword2/animation.cpp
    scummvm/trunk/engines/sword2/function.cpp
    scummvm/trunk/engines/sword2/layers.cpp
    scummvm/trunk/engines/sword2/logic.cpp
    scummvm/trunk/engines/sword2/mouse.cpp
    scummvm/trunk/engines/sword2/resman.cpp
    scummvm/trunk/engines/sword2/sound.cpp
    scummvm/trunk/engines/sword2/sound.h
    scummvm/trunk/engines/sword2/startup.cpp

Modified: scummvm/trunk/engines/sword2/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword2/animation.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/animation.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -308,9 +308,6 @@
 	bool terminate = false;
 	bool textVisible = false;
 	bool startNextText = false;
-	byte *data;
-	uint32 len;
-	Audio::SoundHandle leadInHandle, leadOutHandle;
 	uint32 flags = Audio::Mixer::FLAG_16BITS;
 
 	// This happens if the user quits during the "eye" cutscene.
@@ -318,14 +315,7 @@
 		return;
 
 	if (leadIn) {
-		data = _vm->_resman->openResource(leadIn);
-		len = _vm->_resman->fetchLen(leadIn) - ResHeader::size();
-
-		assert(_vm->_resman->fetchType(data) == WAV_FILE);
-
-		data += ResHeader::size();
-
-		_vm->_sound->playFx(&leadInHandle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
+		_vm->_sound->playMovieSound(leadIn, kLeadInSound);
 	}
 
 	savePalette();
@@ -377,14 +367,7 @@
 		}
 
 		if (leadOut && _currentFrame == _leadOutFrame) {
-			data = _vm->_resman->openResource(leadOut);
-			len = _vm->_resman->fetchLen(leadOut) - ResHeader::size();
-
-			assert(_vm->_resman->fetchType(data) == WAV_FILE);
-
-			data += ResHeader::size();
-
-			_vm->_sound->playFx(&leadOutHandle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
+			_vm->_sound->playMovieSound(leadOut, kLeadOutSound);
 		}
 
 		syncFrame();

Modified: scummvm/trunk/engines/sword2/function.cpp
===================================================================
--- scummvm/trunk/engines/sword2/function.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/function.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -2333,7 +2333,7 @@
 int32 Logic::fnStopAllFx(int32 *params) {
 	// params:	none
 
-	_vm->_sound->clearFxQueue();
+	_vm->_sound->clearFxQueue(false);
 	return IR_CONT;
 }
 

Modified: scummvm/trunk/engines/sword2/layers.cpp
===================================================================
--- scummvm/trunk/engines/sword2/layers.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/layers.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -52,7 +52,7 @@
 
 	assert(res);
 
-	_vm->_sound->clearFxQueue();
+	_vm->_sound->clearFxQueue(false);
 	waitForFade();
 
 	debug(1, "CHANGED TO LOCATION \"%s\"", _vm->_resman->fetchName(res));

Modified: scummvm/trunk/engines/sword2/logic.cpp
===================================================================
--- scummvm/trunk/engines/sword2/logic.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/logic.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -216,7 +216,7 @@
 
 	// Various clean-ups
 	_router->clearWalkGridList();
-	_vm->_sound->clearFxQueue();
+	_vm->_sound->clearFxQueue(false);
 	_router->freeAllRouteMem();
 }
 

Modified: scummvm/trunk/engines/sword2/mouse.cpp
===================================================================
--- scummvm/trunk/engines/sword2/mouse.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/mouse.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -1356,7 +1356,7 @@
 		_vm->_screen->setPalette(0, 1, white, RDPAL_INSTANT);
 
 		// Stops all fx & clears the queue - eg. when leaving a room
-		_vm->_sound->clearFxQueue();
+		_vm->_sound->clearFxQueue(false);
 
 		// Trash all object resources so they load in fresh & restart
 		// their logic scripts

Modified: scummvm/trunk/engines/sword2/resman.cpp
===================================================================
--- scummvm/trunk/engines/sword2/resman.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/resman.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -538,10 +538,10 @@
 
 void ResourceManager::removeAll() {
 	// We need to clear the FX queue, because otherwise the sound system
-	// will still believe that the sound resources are in memory, and that
-	// it's ok to close them.
+	// will still believe that the sound resources are in memory. We also
+ 	// need to kill the movie lead-in/out.
 
-	_vm->_sound->clearFxQueue();
+	_vm->_sound->clearFxQueue(false);
 
 	for (uint i = 0; i < _totalResFiles; i++)
 		remove(i);
@@ -555,10 +555,10 @@
 	int nuked = 0;
 
 	// We need to clear the FX queue, because otherwise the sound system
-	// will still believe that the sound resources are in memory, and that
-	// it's ok to close them.
+	// will still believe that the sound resources are in memory. We also
+	// need to kill the movie lead-in/out.
 
-	_vm->_sound->clearFxQueue();
+	_vm->_sound->clearFxQueue(true);
 
 	for (uint i = 0; i < _totalResFiles; i++) {
 		// Don't nuke the global variables or the player object!

Modified: scummvm/trunk/engines/sword2/sound.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sound.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/sound.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -89,7 +89,7 @@
 Sound::~Sound() {
 	_vm->_mixer->setupPremix(0);
 
-	clearFxQueue();
+	clearFxQueue(true);
 	stopMusic(true);
 	stopSpeech();
 
@@ -121,15 +121,25 @@
 }
 
 /**
- * Stop all sounds, close their resources and clear the FX queue.
+ * Stop all sounds, close their resources and clear the FX queue. This is used
+ * when going from one room to another, among other things.
  */
 
-void Sound::clearFxQueue() {
+void Sound::clearFxQueue(bool killMovieSounds) {
 	for (int i = 0; i < FXQ_LENGTH; i++) {
 		if (_fxQueue[i].resource) {
 			stopFx(i);
 		}
 	}
+
+	// We aren't just going to change rooms or anything like that, we are
+	// killing off resources (e.g. when restoring or restarting). We need
+	// to also kill any movie lead-in/out sounds.
+
+	if (killMovieSounds) {
+		_vm->_mixer->stopHandle(_leadInHandle);
+		_vm->_mixer->stopHandle(_leadOutHandle);
+	}
 }
 
 /**
@@ -175,6 +185,33 @@
 }
 
 /**
+ * This function is used by the cutscene player to play the movie lead-in/out.
+ * @param res The sound resource to play
+ * @param type Either kLeadInSound or kLeadOutSound
+ */
+
+void Sound::playMovieSound(int32 res, int type) {
+	Audio::SoundHandle *handle;
+
+	if (type == kLeadInSound)
+		handle = &_leadInHandle;
+	else
+		handle = &_leadOutHandle;
+
+	if (_vm->_mixer->isSoundHandleActive(*handle)) {
+		_vm->_mixer->stopHandle(*handle);
+	}
+
+	byte *data = _vm->_resman->openResource(res);
+	uint32 len = _vm->_resman->fetchLen(res) - ResHeader::size();
+
+	assert(_vm->_resman->fetchType(data) == WAV_FILE);
+	data += ResHeader::size();
+
+	_vm->_sound->playFx(handle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
+}
+
+/**
  * Queue a sound effect for playing later.
  * @param res the sound resource number
  * @param type the type of sound effect

Modified: scummvm/trunk/engines/sword2/sound.h
===================================================================
--- scummvm/trunk/engines/sword2/sound.h	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/sound.h	2007-01-26 18:21:41 UTC (rev 25204)
@@ -54,6 +54,11 @@
 };
 
 enum {
+	kLeadInSound,
+	kLeadOutSound
+};
+
+enum {
 	// These three types correspond to types set by the scripts
 	FX_SPOT		= 0,
 	FX_LOOP		= 1,
@@ -171,6 +176,9 @@
 
 	Common::Mutex _mutex;
 
+	Audio::SoundHandle _leadInHandle;
+	Audio::SoundHandle _leadOutHandle;
+
 	struct FxQueueEntry {
 		Audio::SoundHandle handle;	// sound handle
 		uint32 resource;		// resource id of sample
@@ -220,7 +228,7 @@
 
 	// End of AudioStream API
 
-	void clearFxQueue();
+	void clearFxQueue(bool killMovieSounds);
 	void processFxQueue();
 
 	void setReverseStereo(bool reverse);
@@ -250,6 +258,8 @@
 	void pauseAllSound();
 	void unpauseAllSound();
 
+	void playMovieSound(int32 res, int type);
+
 	void queueFx(int32 res, int32 type, int32 delay, int32 volume, int32 pan);
 	int32 playFx(FxQueueEntry *fx);
 	int32 playFx(Audio::SoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, Audio::Mixer::SoundType soundType);

Modified: scummvm/trunk/engines/sword2/startup.cpp
===================================================================
--- scummvm/trunk/engines/sword2/startup.cpp	2007-01-26 17:15:12 UTC (rev 25203)
+++ scummvm/trunk/engines/sword2/startup.cpp	2007-01-26 18:21:41 UTC (rev 25204)
@@ -134,7 +134,7 @@
 void Sword2Engine::runStart(int start) {
 	// Restarting - stop sfx, music & speech!
 
-	_sound->clearFxQueue();
+	_sound->clearFxQueue(true);
 	_logic->fnStopMusic(NULL);
 	_sound->unpauseSpeech();
 	_sound->stopSpeech();


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