aboutsummaryrefslogtreecommitdiff
path: root/engines/composer
diff options
context:
space:
mode:
Diffstat (limited to 'engines/composer')
-rw-r--r--engines/composer/resource.cpp14
-rw-r--r--engines/composer/resource.h9
-rw-r--r--engines/composer/saveload.cpp66
3 files changed, 68 insertions, 21 deletions
diff --git a/engines/composer/resource.cpp b/engines/composer/resource.cpp
index 0bb7e8a779..b433cd6c2a 100644
--- a/engines/composer/resource.cpp
+++ b/engines/composer/resource.cpp
@@ -248,12 +248,12 @@ bool ComposerArchive::openStream(Common::SeekableReadStream *stream) {
return true;
}
-Pipe::Pipe(Common::SeekableReadStream *stream, uint16 pipeId) {
+Pipe::Pipe(Common::SeekableReadStream *stream, uint16 id) {
_offset = 0;
_stream = stream;
_anim = NULL;
#ifdef SAVING_ANYWHERE
- _pipeId = pipeId;
+ _pipeId = id;
#endif
}
@@ -263,6 +263,8 @@ Pipe::~Pipe() {
void Pipe::nextFrame() {
if (_offset == (uint)_stream->size())
return;
+ _bufferedResources.push_back(_currBufferedResources);
+ _currBufferedResources.clear();
_stream->seek(_offset, SEEK_SET);
@@ -315,8 +317,10 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
if (res.entries.size() == 1) {
Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(_stream,
res.entries[0].offset, res.entries[0].offset + res.entries[0].size);
- if (buffering)
+ if (buffering) {
_types[tag].erase(id);
+ _currBufferedResources[tag].push_back(id);
+ }
return stream;
}
@@ -333,8 +337,10 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
_stream->read(buffer + offset, res.entries[i].size);
offset += res.entries[i].size;
}
- if (buffering)
+ if (buffering) {
_types[tag].erase(id);
+ _currBufferedResources[tag].push_back(id);
+ }
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
}
diff --git a/engines/composer/resource.h b/engines/composer/resource.h
index 52748bacd2..55d7c20cc4 100644
--- a/engines/composer/resource.h
+++ b/engines/composer/resource.h
@@ -106,7 +106,7 @@ struct PipeResource {
class Pipe {
public:
- Pipe(Common::SeekableReadStream *stream, uint16 pipeId);
+ Pipe(Common::SeekableReadStream *stream, uint16 id);
virtual ~Pipe();
virtual void nextFrame();
@@ -117,9 +117,11 @@ public:
virtual const Common::Array<uint16> *getScripts() { return NULL; }
#ifdef SAVING_ANYWHERE
- uint16 id() const { return _pipeId; }
+ uint16 pipeId() const { return _pipeId; }
uint32 offset() const { return _offset; }
- void setOffset(uint32 offset) { while (_offset < offset) nextFrame(); }
+ void setOffset(uint32 off) { while (_offset < off) nextFrame(); }
+ typedef Common::HashMap<uint32, Common::List<uint16>> DelMap;
+ Common::Array<DelMap> _bufferedResources;
#endif
protected:
@@ -130,6 +132,7 @@ protected:
TypeMap _types;
#ifdef SAVING_ANYWHERE
uint16 _pipeId;
+ DelMap _currBufferedResources;
#endif
uint32 _offset;
diff --git a/engines/composer/saveload.cpp b/engines/composer/saveload.cpp
index 0cbf749f92..ca23b6155c 100644
--- a/engines/composer/saveload.cpp
+++ b/engines/composer/saveload.cpp
@@ -150,9 +150,23 @@ Common::Error ComposerEngine::loadGameState(int slot) {
ser.syncAsUint32LE(offset);
Common::SeekableReadStream *stream = getResource(ID_ANIM, id);
Pipe *pipe = new Pipe(stream, id);
- pipe->setOffset(offset);
_pipes.push_front(pipe);
_pipeStreams.push_back(stream);
+ ser.syncAsUint32LE(tmp);
+ for (uint32 j = tmp; j > 0; j--) {
+ ser.syncAsUint32LE(tmp);
+ for (uint32 k = tmp; k > 0; k--) {
+ uint32 tag;
+ ser.syncAsUint32LE(tag);
+ ser.syncAsUint32LE(tmp);
+ for (uint32 l = tmp; l > 0; l--) {
+ ser.syncAsUint16LE(id);
+ pipe->getResource(tag, id, true);
+ }
+ }
+ pipe->nextFrame();
+ }
+ pipe->setOffset(offset);
}
for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
@@ -162,7 +176,8 @@ Common::Error ComposerEngine::loadGameState(int slot) {
ser.syncAsUint32LE(tmp);
for (uint32 i = tmp; i > 0; i--) {
uint16 animId, x, y;
- uint32 offset, state, param, size;
+ uint32 offset, state, param;
+ int32 size;
ser.syncAsUint16LE(animId);
ser.syncAsUint32LE(offset);
ser.syncAsUint16LE(x);
@@ -252,15 +267,18 @@ Common::Error ComposerEngine::loadGameState(int slot) {
_mixer->stopAll();
_audioStream = NULL;
- ser.syncAsUint32LE(tmp);
- tmp <<= 1;
- byte *audioBuf = (byte *)malloc(tmp);
- ser.syncBytes(audioBuf, tmp);
+
+ ser.syncAsSint16LE(_currSoundPriority);
+ int32 numSamples;
+ ser.syncAsSint32LE(numSamples);
+ int16 *audioBuffer = (int16 *)malloc(numSamples * 2);
+ for (int32 i = 0; i < numSamples; i++)
+ ser.syncAsSint16LE(audioBuffer[i]);
_audioStream = Audio::makeQueuingAudioStream(22050, false);
- _audioStream->queueBuffer(audioBuf, tmp, DisposeAfterUse::YES, Audio::FLAG_UNSIGNED);
- _currSoundPriority = 0;
+ _audioStream->queueBuffer((byte *)audioBuffer, numSamples * 2, DisposeAfterUse::YES, Audio::FLAG_16BITS);
if (!_mixer->isSoundHandleActive(_soundHandle))
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream);
+
return Common::kNoError;
}
@@ -339,10 +357,26 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
tmp = _pipes.size();
ser.syncAsUint32LE(tmp);
for (Common::List<Pipe *>::const_iterator i = _pipes.reverse_begin(); i != _pipes.end(); i--) {
- uint16 tmp16 = (*i)->id();
+ uint16 tmp16 = (*i)->pipeId();
tmp = (*i)->offset();
ser.syncAsUint16LE(tmp16);
ser.syncAsUint32LE(tmp);
+ tmp = (*i)->_bufferedResources.size();
+ ser.syncAsUint32LE(tmp);
+ for (Common::Array<Pipe::DelMap>::const_iterator j = (*i)->_bufferedResources.begin(); j != (*i)->_bufferedResources.end(); j++) {
+ tmp = (*j).size();
+ ser.syncAsUint32LE(tmp);
+ for (Pipe::DelMap::const_iterator k = (*j).begin(); k != (*j).end(); k++) {
+ tmp = (*k)._key;
+ ser.syncAsUint32LE(tmp);
+ tmp = (*k)._value.size();
+ ser.syncAsUint32LE(tmp);
+ for (Common::List<uint16>::const_iterator l = (*k)._value.begin(); l != (*k)._value.end(); l++) {
+ tmp16 = (*l);
+ ser.syncAsUint16LE(tmp16);
+ }
+ }
+ }
}
tmp = _anims.size();
@@ -396,11 +430,15 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
byte paletteBuffer[256 * 3];
_system->getPaletteManager()->grabPalette(paletteBuffer, 0, 256);
ser.syncBytes(paletteBuffer, 256 * 3);
- byte *audioBuffer = (byte *)malloc(22050 * 60 * 2);
- int32 numSamples = _audioStream->readBuffer((int16 *)audioBuffer, 22050 * 60);
- if (numSamples == -1) numSamples = 0;
- ser.syncAsUint32LE(numSamples);
- ser.syncBytes((byte *)audioBuffer, numSamples * 2);
+
+ ser.syncAsSint16LE(_currSoundPriority);
+ int16 audioBuffer[22050];
+ int32 numSamples = _audioStream->readBuffer(audioBuffer, 22050);
+ if (numSamples == -1) numSamples = 0;
+ ser.syncAsSint32LE(numSamples);
+ for (int32 i = 0; i < numSamples; i++)
+ ser.syncAsSint16LE(audioBuffer[i]);
+
out->finalize();
return Common::kNoError;
}