COMPOSER: Added support for saving/loading in V1 games.

This commit is contained in:
upthorn 2012-05-29 12:49:03 -07:00 committed by angstsmurf
parent 1f1928c9ac
commit 027bab88fb
5 changed files with 57 additions and 35 deletions

View file

@ -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");
@ -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());

View file

@ -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;
};

View file

@ -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);
@ -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;
@ -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);

View file

@ -118,10 +118,10 @@ public:
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:
@ -132,7 +132,6 @@ protected:
TypeMap _types;
#ifdef SAVING_ANYWHERE
uint16 _pipeId;
DelMap _currBufferedResources;
#endif
uint32 _offset;
@ -144,6 +143,10 @@ public:
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;

View file

@ -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);
@ -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);
@ -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();
@ -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--) {
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--) {
for (uint32 k = tmp; k > 0; k--) {
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++) {
@ -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++) {
@ -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);
@ -363,21 +374,17 @@ 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);
for (Pipe::DelMap::const_iterator k = (*j).begin(); k != (*j).end(); k++) {
tmp = (*k)._key;
tmp = (*j)._value.size();
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);
for (Common::List<uint16>::const_iterator k = (*j)._value.begin(); k != (*j)._value.end(); k++) {
tmp16 = (*k);
ser.syncAsUint16LE(tmp16);
}
}
}
}
tmp = _anims.size();
ser.syncAsUint32LE(tmp);