Skip to content

Commit

Permalink
COMPOSER: Added support for saving/loading in V1 games.
Browse files Browse the repository at this point in the history
  • Loading branch information
upthorn authored and angstsmurf committed Oct 18, 2016
1 parent 1f1928c commit 027bab8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 35 deletions.
7 changes: 6 additions & 1 deletion engines/composer/composer.cpp
Expand Up @@ -378,7 +378,9 @@ void ComposerEngine::loadLibrary(uint id) {
}

Common::String filename;

#ifdef SAVING_ANYWHERE
Common::String oldGroup = _bookGroup;
#endif
if (getGameType() == GType_ComposerV1) {
if (!id || _bookGroup.empty())
filename = getStringFromConfig("Common", "StartPage");
Expand Down Expand Up @@ -412,6 +414,9 @@ void ComposerEngine::loadLibrary(uint id) {
Library library;

library._id = id;
#ifdef SAVING_ANYWHERE
library._group = oldGroup;
#endif
library._archive = new ComposerArchive();
if (!library._archive->openFile(filename))
error("failed to open '%s'", filename.c_str());
Expand Down
3 changes: 3 additions & 0 deletions engines/composer/composer.h
Expand Up @@ -114,6 +114,9 @@ struct Library {
uint _id;
Archive *_archive;

#ifdef SAVING_ANYWHERE
Common::String _group;
#endif
Common::List<Button> _buttons;
Common::List<KeyboardHandler> _keyboardHandlers;
};
Expand Down
16 changes: 10 additions & 6 deletions engines/composer/resource.cpp
Expand Up @@ -263,10 +263,6 @@ Pipe::~Pipe() {
void Pipe::nextFrame() {
if (_offset == (uint)_stream->size())
return;
#ifdef SAVING_ANYWHERE
_bufferedResources.push_back(_currBufferedResources);
#endif
_currBufferedResources.clear();

_stream->seek(_offset, SEEK_SET);

Expand Down Expand Up @@ -322,7 +318,11 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
if (buffering) {
_types[tag].erase(id);
#ifdef SAVING_ANYWHERE
_currBufferedResources[tag].push_back(id);
bool found = false;
for (Common::List<uint16>::const_iterator i = _bufferedResources[tag].begin(); !found && (i != _bufferedResources[tag].end()); i++)
if ((*i) == id) found = true;
if (!found)
_bufferedResources[tag].push_back(id);
#endif
}
return stream;
Expand All @@ -344,7 +344,11 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
if (buffering) {
_types[tag].erase(id);
#ifdef SAVING_ANYWHERE
_currBufferedResources[tag].push_back(id);
bool found = false;
for (Common::List<uint16>::const_iterator i = _bufferedResources[tag].begin(); !found && (i != _bufferedResources[tag].end()); i++)
if ((*i) == id) found = true;
if (!found)
_bufferedResources[tag].push_back(id);
#endif
}
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
Expand Down
11 changes: 7 additions & 4 deletions engines/composer/resource.h
Expand Up @@ -118,10 +118,10 @@ class Pipe {
virtual const Common::Array<uint16> *getScripts() { return NULL; }
#ifdef SAVING_ANYWHERE
uint16 getPipeId() const { return _pipeId; }
uint32 getOffset() const { return _offset; }
void setOffset(uint32 offset) { while (_offset < offset) nextFrame(); }
virtual uint32 getOffset() const { return _offset; }
virtual void setOffset(uint32 offset) { while (_offset < offset) nextFrame(); }
typedef Common::HashMap<uint32, Common::List<uint16> > DelMap;
Common::Array<DelMap> _bufferedResources;
DelMap _bufferedResources;
#endif

protected:
Expand All @@ -132,7 +132,6 @@ class Pipe {
TypeMap _types;
#ifdef SAVING_ANYWHERE
uint16 _pipeId;
DelMap _currBufferedResources;
#endif

uint32 _offset;
Expand All @@ -144,6 +143,10 @@ class OldPipe : public Pipe {
void nextFrame();

const Common::Array<uint16> *getScripts() { return &_scripts; }
#ifdef SAVING_ANYWHERE
uint32 getOffset() const { return _currFrame; }
void setOffset(uint32 offset) { while (_currFrame < offset) nextFrame(); }
#endif

protected:
uint32 _currFrame, _numFrames;
Expand Down
55 changes: 31 additions & 24 deletions engines/composer/saveload.cpp
Expand Up @@ -62,7 +62,6 @@ Common::Error ComposerEngine::loadGameState(int slot) {
_currentTime += timeDelta;
ser.syncAsUint32LE(_lastTime);
_lastTime += timeDelta;
ser.syncString(_bookGroup);
Common::Array<uint16> libIds;
for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
libIds.push_back((*i)._id);
Expand All @@ -72,8 +71,10 @@ Common::Error ComposerEngine::loadGameState(int slot) {
for (uint32 i = tmp; i > 0; i--) {
uint16 id;
ser.syncAsUint16LE(id);
ser.syncString(_bookGroup);
loadLibrary(id);
}
ser.syncString(_bookGroup);

_pendingPageChanges.clear();
ser.syncAsUint32LE(tmp);
Expand Down Expand Up @@ -106,11 +107,13 @@ Common::Error ComposerEngine::loadGameState(int slot) {
ser.syncAsUint32LE(tmp);
for (uint32 i = tmp; i > 0; i--) {
uint16 id;
uint32 delay;
uint32 pos, delay;
ser.syncAsUint32LE(pos);
ser.syncAsUint16LE(id);
ser.syncAsUint32LE(delay);
OldScript *oTmp = new OldScript(id, getResource(ID_SCRP, id));
oTmp->_currDelay = delay;
oTmp->_stream->seek(pos, SEEK_SET);
_oldScripts.push_back(oTmp);
}
_queuedScripts.clear();
Expand Down Expand Up @@ -148,25 +151,29 @@ Common::Error ComposerEngine::loadGameState(int slot) {
uint32 offset;
ser.syncAsUint16LE(id);
ser.syncAsUint32LE(offset);
Common::SeekableReadStream *stream = getResource(ID_ANIM, id);
Pipe *pipe = new Pipe(stream, id);
Pipe *pipe;
Common::SeekableReadStream *stream;
if (getGameType() == GType_ComposerV1) {
stream = getResource(ID_PIPE, id);
pipe = new OldPipe(stream, id);
} else {
stream = getResource(ID_ANIM, id);
pipe = new Pipe(stream, id);
}
_pipes.push_front(pipe);
_pipeStreams.push_back(stream);
pipe->setOffset(offset);
ser.syncAsUint32LE(tmp);
for (uint32 j = tmp; j > 0; j--) {
uint32 tag;
ser.syncAsUint32LE(tag);
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);
ser.syncAsUint16LE(id);
if (pipe->hasResource(tag, id))
pipe->getResource(tag, id, true);
}
}
pipe->nextFrame();
}
pipe->setOffset(offset);
}

for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
Expand Down Expand Up @@ -298,13 +305,15 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
ser.syncAsUint32LE(tmp);
ser.syncAsUint32LE(_currentTime);
ser.syncAsUint32LE(_lastTime);
ser.syncString(_bookGroup);
tmp = _libraries.size();
ser.syncAsUint32LE(tmp);
for (Common::List<Library>::const_iterator i = _libraries.reverse_begin(); i != _libraries.end(); i--) {
uint16 tmp16 = (*i)._id;
Common::String tmps = (*i)._group;
ser.syncAsUint16LE(tmp16);
ser.syncString(tmps);
}
ser.syncString(_bookGroup);
tmp = _pendingPageChanges.size();
ser.syncAsUint32LE(tmp);
for (Common::Array<PendingPageChange>::const_iterator i = _pendingPageChanges.begin(); i != _pendingPageChanges.end(); i++) {
Expand All @@ -328,6 +337,8 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
tmp = _oldScripts.size();
ser.syncAsUint32LE(tmp);
for (Common::List<OldScript *>::const_iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++) {
tmp = (*i)->_stream->pos();
ser.syncAsUint32LE(tmp);
uint16 tmp16 = (*i)->_id;
tmp = (*i)->_currDelay;
ser.syncAsUint16LE(tmp16);
Expand Down Expand Up @@ -363,18 +374,14 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
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();
for (Pipe::DelMap::const_iterator j = (*i)->_bufferedResources.begin(); j != (*i)->_bufferedResources.end(); j++) {
tmp = (*j)._key;
ser.syncAsUint32LE(tmp);
tmp = (*j)._value.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);
}
for (Common::List<uint16>::const_iterator k = (*j)._value.begin(); k != (*j)._value.end(); k++) {
tmp16 = (*k);
ser.syncAsUint16LE(tmp16);
}
}
}
Expand Down

0 comments on commit 027bab8

Please sign in to comment.