COMPOSER: Added support for saving/loading in V1 games.
This commit is contained in:
parent
1f1928c9ac
commit
027bab88fb
5 changed files with 57 additions and 35 deletions
|
@ -378,7 +378,9 @@ void ComposerEngine::loadLibrary(uint id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::String filename;
|
Common::String filename;
|
||||||
|
#ifdef SAVING_ANYWHERE
|
||||||
|
Common::String oldGroup = _bookGroup;
|
||||||
|
#endif
|
||||||
if (getGameType() == GType_ComposerV1) {
|
if (getGameType() == GType_ComposerV1) {
|
||||||
if (!id || _bookGroup.empty())
|
if (!id || _bookGroup.empty())
|
||||||
filename = getStringFromConfig("Common", "StartPage");
|
filename = getStringFromConfig("Common", "StartPage");
|
||||||
|
@ -412,6 +414,9 @@ void ComposerEngine::loadLibrary(uint id) {
|
||||||
Library library;
|
Library library;
|
||||||
|
|
||||||
library._id = id;
|
library._id = id;
|
||||||
|
#ifdef SAVING_ANYWHERE
|
||||||
|
library._group = oldGroup;
|
||||||
|
#endif
|
||||||
library._archive = new ComposerArchive();
|
library._archive = new ComposerArchive();
|
||||||
if (!library._archive->openFile(filename))
|
if (!library._archive->openFile(filename))
|
||||||
error("failed to open '%s'", filename.c_str());
|
error("failed to open '%s'", filename.c_str());
|
||||||
|
|
|
@ -114,6 +114,9 @@ struct Library {
|
||||||
uint _id;
|
uint _id;
|
||||||
Archive *_archive;
|
Archive *_archive;
|
||||||
|
|
||||||
|
#ifdef SAVING_ANYWHERE
|
||||||
|
Common::String _group;
|
||||||
|
#endif
|
||||||
Common::List<Button> _buttons;
|
Common::List<Button> _buttons;
|
||||||
Common::List<KeyboardHandler> _keyboardHandlers;
|
Common::List<KeyboardHandler> _keyboardHandlers;
|
||||||
};
|
};
|
||||||
|
|
|
@ -263,10 +263,6 @@ Pipe::~Pipe() {
|
||||||
void Pipe::nextFrame() {
|
void Pipe::nextFrame() {
|
||||||
if (_offset == (uint)_stream->size())
|
if (_offset == (uint)_stream->size())
|
||||||
return;
|
return;
|
||||||
#ifdef SAVING_ANYWHERE
|
|
||||||
_bufferedResources.push_back(_currBufferedResources);
|
|
||||||
#endif
|
|
||||||
_currBufferedResources.clear();
|
|
||||||
|
|
||||||
_stream->seek(_offset, SEEK_SET);
|
_stream->seek(_offset, SEEK_SET);
|
||||||
|
|
||||||
|
@ -322,7 +318,11 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
|
||||||
if (buffering) {
|
if (buffering) {
|
||||||
_types[tag].erase(id);
|
_types[tag].erase(id);
|
||||||
#ifdef SAVING_ANYWHERE
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
return stream;
|
return stream;
|
||||||
|
@ -344,7 +344,11 @@ Common::SeekableReadStream *Pipe::getResource(uint32 tag, uint16 id, bool buffer
|
||||||
if (buffering) {
|
if (buffering) {
|
||||||
_types[tag].erase(id);
|
_types[tag].erase(id);
|
||||||
#ifdef SAVING_ANYWHERE
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
|
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
|
||||||
|
|
|
@ -118,10 +118,10 @@ public:
|
||||||
virtual const Common::Array<uint16> *getScripts() { return NULL; }
|
virtual const Common::Array<uint16> *getScripts() { return NULL; }
|
||||||
#ifdef SAVING_ANYWHERE
|
#ifdef SAVING_ANYWHERE
|
||||||
uint16 getPipeId() const { return _pipeId; }
|
uint16 getPipeId() const { return _pipeId; }
|
||||||
uint32 getOffset() const { return _offset; }
|
virtual uint32 getOffset() const { return _offset; }
|
||||||
void setOffset(uint32 offset) { while (_offset < offset) nextFrame(); }
|
virtual void setOffset(uint32 offset) { while (_offset < offset) nextFrame(); }
|
||||||
typedef Common::HashMap<uint32, Common::List<uint16> > DelMap;
|
typedef Common::HashMap<uint32, Common::List<uint16> > DelMap;
|
||||||
Common::Array<DelMap> _bufferedResources;
|
DelMap _bufferedResources;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -132,7 +132,6 @@ protected:
|
||||||
TypeMap _types;
|
TypeMap _types;
|
||||||
#ifdef SAVING_ANYWHERE
|
#ifdef SAVING_ANYWHERE
|
||||||
uint16 _pipeId;
|
uint16 _pipeId;
|
||||||
DelMap _currBufferedResources;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32 _offset;
|
uint32 _offset;
|
||||||
|
@ -144,6 +143,10 @@ public:
|
||||||
void nextFrame();
|
void nextFrame();
|
||||||
|
|
||||||
const Common::Array<uint16> *getScripts() { return &_scripts; }
|
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:
|
protected:
|
||||||
uint32 _currFrame, _numFrames;
|
uint32 _currFrame, _numFrames;
|
||||||
|
|
|
@ -62,7 +62,6 @@ Common::Error ComposerEngine::loadGameState(int slot) {
|
||||||
_currentTime += timeDelta;
|
_currentTime += timeDelta;
|
||||||
ser.syncAsUint32LE(_lastTime);
|
ser.syncAsUint32LE(_lastTime);
|
||||||
_lastTime += timeDelta;
|
_lastTime += timeDelta;
|
||||||
ser.syncString(_bookGroup);
|
|
||||||
Common::Array<uint16> libIds;
|
Common::Array<uint16> libIds;
|
||||||
for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
|
for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++)
|
||||||
libIds.push_back((*i)._id);
|
libIds.push_back((*i)._id);
|
||||||
|
@ -72,8 +71,10 @@ Common::Error ComposerEngine::loadGameState(int slot) {
|
||||||
for (uint32 i = tmp; i > 0; i--) {
|
for (uint32 i = tmp; i > 0; i--) {
|
||||||
uint16 id;
|
uint16 id;
|
||||||
ser.syncAsUint16LE(id);
|
ser.syncAsUint16LE(id);
|
||||||
|
ser.syncString(_bookGroup);
|
||||||
loadLibrary(id);
|
loadLibrary(id);
|
||||||
}
|
}
|
||||||
|
ser.syncString(_bookGroup);
|
||||||
|
|
||||||
_pendingPageChanges.clear();
|
_pendingPageChanges.clear();
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
|
@ -106,11 +107,13 @@ Common::Error ComposerEngine::loadGameState(int slot) {
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (uint32 i = tmp; i > 0; i--) {
|
for (uint32 i = tmp; i > 0; i--) {
|
||||||
uint16 id;
|
uint16 id;
|
||||||
uint32 delay;
|
uint32 pos, delay;
|
||||||
|
ser.syncAsUint32LE(pos);
|
||||||
ser.syncAsUint16LE(id);
|
ser.syncAsUint16LE(id);
|
||||||
ser.syncAsUint32LE(delay);
|
ser.syncAsUint32LE(delay);
|
||||||
OldScript *oTmp = new OldScript(id, getResource(ID_SCRP, id));
|
OldScript *oTmp = new OldScript(id, getResource(ID_SCRP, id));
|
||||||
oTmp->_currDelay = delay;
|
oTmp->_currDelay = delay;
|
||||||
|
oTmp->_stream->seek(pos, SEEK_SET);
|
||||||
_oldScripts.push_back(oTmp);
|
_oldScripts.push_back(oTmp);
|
||||||
}
|
}
|
||||||
_queuedScripts.clear();
|
_queuedScripts.clear();
|
||||||
|
@ -148,25 +151,29 @@ Common::Error ComposerEngine::loadGameState(int slot) {
|
||||||
uint32 offset;
|
uint32 offset;
|
||||||
ser.syncAsUint16LE(id);
|
ser.syncAsUint16LE(id);
|
||||||
ser.syncAsUint32LE(offset);
|
ser.syncAsUint32LE(offset);
|
||||||
Common::SeekableReadStream *stream = getResource(ID_ANIM, id);
|
Pipe *pipe;
|
||||||
Pipe *pipe = new Pipe(stream, id);
|
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);
|
_pipes.push_front(pipe);
|
||||||
_pipeStreams.push_back(stream);
|
_pipeStreams.push_back(stream);
|
||||||
|
pipe->setOffset(offset);
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (uint32 j = tmp; j > 0; j--) {
|
for (uint32 j = tmp; j > 0; j--) {
|
||||||
|
uint32 tag;
|
||||||
|
ser.syncAsUint32LE(tag);
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (uint32 k = tmp; k > 0; k--) {
|
for (uint32 k = tmp; k > 0; k--) {
|
||||||
uint32 tag;
|
ser.syncAsUint16LE(id);
|
||||||
ser.syncAsUint32LE(tag);
|
if (pipe->hasResource(tag, id))
|
||||||
ser.syncAsUint32LE(tmp);
|
|
||||||
for (uint32 l = tmp; l > 0; l--) {
|
|
||||||
ser.syncAsUint16LE(id);
|
|
||||||
pipe->getResource(tag, id, true);
|
pipe->getResource(tag, id, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pipe->nextFrame();
|
|
||||||
}
|
}
|
||||||
pipe->setOffset(offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Common::List<Animation *>::iterator i = _anims.begin(); i != _anims.end(); i++) {
|
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(tmp);
|
||||||
ser.syncAsUint32LE(_currentTime);
|
ser.syncAsUint32LE(_currentTime);
|
||||||
ser.syncAsUint32LE(_lastTime);
|
ser.syncAsUint32LE(_lastTime);
|
||||||
ser.syncString(_bookGroup);
|
|
||||||
tmp = _libraries.size();
|
tmp = _libraries.size();
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (Common::List<Library>::const_iterator i = _libraries.reverse_begin(); i != _libraries.end(); i--) {
|
for (Common::List<Library>::const_iterator i = _libraries.reverse_begin(); i != _libraries.end(); i--) {
|
||||||
uint16 tmp16 = (*i)._id;
|
uint16 tmp16 = (*i)._id;
|
||||||
|
Common::String tmps = (*i)._group;
|
||||||
ser.syncAsUint16LE(tmp16);
|
ser.syncAsUint16LE(tmp16);
|
||||||
|
ser.syncString(tmps);
|
||||||
}
|
}
|
||||||
|
ser.syncString(_bookGroup);
|
||||||
tmp = _pendingPageChanges.size();
|
tmp = _pendingPageChanges.size();
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (Common::Array<PendingPageChange>::const_iterator i = _pendingPageChanges.begin(); i != _pendingPageChanges.end(); i++) {
|
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();
|
tmp = _oldScripts.size();
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (Common::List<OldScript *>::const_iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++) {
|
for (Common::List<OldScript *>::const_iterator i = _oldScripts.begin(); i != _oldScripts.end(); i++) {
|
||||||
|
tmp = (*i)->_stream->pos();
|
||||||
|
ser.syncAsUint32LE(tmp);
|
||||||
uint16 tmp16 = (*i)->_id;
|
uint16 tmp16 = (*i)->_id;
|
||||||
tmp = (*i)->_currDelay;
|
tmp = (*i)->_currDelay;
|
||||||
ser.syncAsUint16LE(tmp16);
|
ser.syncAsUint16LE(tmp16);
|
||||||
|
@ -363,18 +374,14 @@ Common::Error ComposerEngine::saveGameState(int slot, const Common::String &desc
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
tmp = (*i)->_bufferedResources.size();
|
tmp = (*i)->_bufferedResources.size();
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (Common::Array<Pipe::DelMap>::const_iterator j = (*i)->_bufferedResources.begin(); j != (*i)->_bufferedResources.end(); j++) {
|
for (Pipe::DelMap::const_iterator j = (*i)->_bufferedResources.begin(); j != (*i)->_bufferedResources.end(); j++) {
|
||||||
tmp = (*j).size();
|
tmp = (*j)._key;
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint32LE(tmp);
|
||||||
for (Pipe::DelMap::const_iterator k = (*j).begin(); k != (*j).end(); k++) {
|
tmp = (*j)._value.size();
|
||||||
tmp = (*k)._key;
|
ser.syncAsUint32LE(tmp);
|
||||||
ser.syncAsUint32LE(tmp);
|
for (Common::List<uint16>::const_iterator k = (*j)._value.begin(); k != (*j)._value.end(); k++) {
|
||||||
tmp = (*k)._value.size();
|
tmp16 = (*k);
|
||||||
ser.syncAsUint32LE(tmp);
|
ser.syncAsUint16LE(tmp16);
|
||||||
for (Common::List<uint16>::const_iterator l = (*k)._value.begin(); l != (*k)._value.end(); l++) {
|
|
||||||
tmp16 = (*l);
|
|
||||||
ser.syncAsUint16LE(tmp16);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue