aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2011-11-21 23:47:47 +0200
committerFilippos Karapetis2011-11-21 23:47:47 +0200
commit18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06 (patch)
tree6f56dd7ca1cda13c5cfc2350dc16741839bf9f0b
parente2bc38ea914d171c790c3853a9dcb26911c973c0 (diff)
downloadscummvm-rg350-18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06.tar.gz
scummvm-rg350-18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06.tar.bz2
scummvm-rg350-18fd59939ff6ae8caf17b3bb5178d0cfa4c5bf06.zip
TOLTECS: Sync scene sounds when saving/loading
-rw-r--r--engines/toltecs/saveload.cpp9
-rw-r--r--engines/toltecs/sound.cpp42
-rw-r--r--engines/toltecs/sound.h3
3 files changed, 49 insertions, 5 deletions
diff --git a/engines/toltecs/saveload.cpp b/engines/toltecs/saveload.cpp
index 3e1be75a88..af78c8b975 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 47d52637fb..c9ef00e31b 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 e4580effa1..e292d22c0f 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;