[Scummvm-cvs-logs] scummvm master -> 18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06

bluegr md5 at scummvm.org
Mon Nov 21 22:49:15 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
18fd59939f TOLTECS: Sync scene sounds when saving/loading


Commit: 18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06
    https://github.com/scummvm/scummvm/commit/18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2011-11-21T13:47:47-08:00

Commit Message:
TOLTECS: Sync scene sounds when saving/loading

Changed paths:
    engines/toltecs/saveload.cpp
    engines/toltecs/sound.cpp
    engines/toltecs/sound.h



diff --git a/engines/toltecs/saveload.cpp b/engines/toltecs/saveload.cpp
index 3e1be75..af78c8b 100644
--- a/engines/toltecs/saveload.cpp
+++ b/engines/toltecs/saveload.cpp
@@ -30,6 +30,7 @@
 #include "toltecs/palette.h"
 #include "toltecs/script.h"
 #include "toltecs/screen.h"
+#include "toltecs/sound.h"
 
 namespace Toltecs {
 
@@ -39,7 +40,7 @@ namespace Toltecs {
 	- Maybe switch to SCUMM/Tinsel serialization approach?
 */
 
-#define TOLTECS_SAVEGAME_VERSION 1
+#define TOLTECS_SAVEGAME_VERSION 2
 
 ToltecsEngine::kReadSaveHeaderError ToltecsEngine::readSaveHeader(Common::SeekableReadStream *in, bool loadThumbnail, SaveHeader &header) {
 
@@ -62,7 +63,7 @@ ToltecsEngine::kReadSaveHeaderError ToltecsEngine::readSaveHeader(Common::Seekab
 	header.gameID = in->readByte();
 	header.flags = in->readUint32LE();
 
-	if (header.version > 0) {
+	if (header.version >= 1) {
 		header.saveDate = in->readUint32LE();
 		header.saveTime = in->readUint32LE();
 		header.playTime = in->readUint32LE();
@@ -131,6 +132,7 @@ void ToltecsEngine::savegame(const char *filename, const char *description) {
 	_script->saveState(out);
 	_anim->saveState(out);
 	_screen->saveState(out);
+	_sound->saveState(out);
 
 	out->finalize();
 	delete out;
@@ -153,6 +155,7 @@ void ToltecsEngine::loadgame(const char *filename) {
 		return;
 	}
 	
+	_sound->stopAll();
 	g_engine->setTotalPlayTime(header.playTime * 1000);
 
 	_cameraX = in->readUint16LE();
@@ -184,6 +187,8 @@ void ToltecsEngine::loadgame(const char *filename) {
 	_script->loadState(in);
 	_anim->loadState(in);
 	_screen->loadState(in);
+	if (header.version >= 2)
+		_sound->loadState(in);
 
 	delete in;
 
diff --git a/engines/toltecs/sound.cpp b/engines/toltecs/sound.cpp
index 47d5263..c9ef00e 100644
--- a/engines/toltecs/sound.cpp
+++ b/engines/toltecs/sound.cpp
@@ -131,11 +131,12 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa
 		
 		// If all channels are in use no new sound will be played
 		if (freeChannel >= 0) {
-
 			Resource *soundResource = _vm->_res->load(resIndex);
 
 			Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
-								Audio::makeRawStream(soundResource->data, soundResource->size, 22050, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO),
+								Audio::makeRawStream(soundResource->data,
+								soundResource->size, 22050, Audio::FLAG_UNSIGNED,
+								DisposeAfterUse::NO),
 								type == kChannelTypeBackground ? 0 : 1);
 
 			channels[freeChannel].type = type;
@@ -149,7 +150,6 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa
 
 			_vm->_mixer->playStream(soundType, &channels[freeChannel].handle,
 				stream, -1, volume, panning);
-			
 		}
 
 	}
@@ -185,4 +185,40 @@ void Sound::stopAll() {
 	}
 }
 
+void Sound::saveState(Common::WriteStream *out) {
+	for (int i = 0; i < kMaxChannels; i++) {
+		out->writeSint16LE(channels[i].type);
+		out->writeSint16LE(channels[i].resIndex);
+	}
+}
+
+void Sound::loadState(Common::ReadStream *in) {
+	for (int i = 0; i < kMaxChannels; i++) {
+		channels[i].type = in->readSint16LE();
+		channels[i].resIndex = in->readSint16LE();
+
+		if (channels[i].type != kChannelTypeEmpty) {
+			Resource *soundResource = _vm->_res->load(channels[i].resIndex);
+
+			Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
+								Audio::makeRawStream(soundResource->data,
+								soundResource->size, 22050, Audio::FLAG_UNSIGNED,
+								DisposeAfterUse::NO),
+								channels[i].type == kChannelTypeBackground ? 0 : 1);
+
+			Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType;
+			/*
+			switch (type) {
+			}
+			*/
+
+			// TODO: Volume and panning
+			int16 volume = (channels[i].type == kChannelTypeBackground) ? 50 : 100;
+
+			_vm->_mixer->playStream(soundType, &channels[i].handle,
+				stream, -1, volume, /*panning*/0);
+		}
+	}
+}
+
 } // End of namespace Toltecs
diff --git a/engines/toltecs/sound.h b/engines/toltecs/sound.h
index e4580ef..e292d22 100644
--- a/engines/toltecs/sound.h
+++ b/engines/toltecs/sound.h
@@ -59,6 +59,9 @@ public:
 	void stopSpeech();
 	void stopAll();
 
+	void saveState(Common::WriteStream *out);
+	void loadState(Common::ReadStream *in);
+
 protected:
 	ToltecsEngine *_vm;
 






More information about the Scummvm-git-logs mailing list