GLK: FROTZ: Move creation of Quetzal ANNO chunk into base Quetzal writer

This commit is contained in:
Paul Gilbert 2019-06-16 08:41:10 -07:00
parent dbc0a5ff09
commit 3acba22cba
3 changed files with 38 additions and 10 deletions

View File

@ -65,13 +65,6 @@ bool Quetzal::save(Common::WriteStream *svf, Processor *proc, const Common::Stri
ws.writeByte(pc & 0xff);
}
// Write 'ANNO' chunk
{
Common::WriteStream &ws = _writer.add(ID_ANNO);
ws.write(desc.c_str(), desc.size());
ws.writeByte(0);
}
// Write `CMem' chunk.
{
Common::WriteStream &ws = _writer.add(ID_CMem);
@ -166,7 +159,7 @@ bool Quetzal::save(Common::WriteStream *svf, Processor *proc, const Common::Stri
}
// Write the save data out
_writer.save(svf, ID_IFZS);
_writer.save(svf, desc, ID_IFZS);
// After all that, still nothing went wrong!
return true;

View File

@ -21,7 +21,10 @@
*/
#include "glk/quetzal.h"
#include "glk/glk_api.h"
#include "glk/events.h"
#include "common/memstream.h"
#include "common/system.h"
namespace Glk {
@ -85,7 +88,10 @@ Common::WriteStream &QuetzalWriter::add(uint32 chunkId) {
return _chunks.back()._stream;
}
void QuetzalWriter::save(Common::WriteStream *out, uint32 formType) {
void QuetzalWriter::save(Common::WriteStream *out, const Common::String &saveName, uint32 formType) {
// Add chunks common to all Glk savegames
addCommonChunks(saveName);
// Calculate the size of the chunks
uint size = 4;
for (uint idx = 0; idx < _chunks.size(); ++idx)
@ -108,4 +114,28 @@ void QuetzalWriter::save(Common::WriteStream *out, uint32 formType) {
}
}
void QuetzalWriter::addCommonChunks(const Common::String &saveName) {
// Write 'ANNO' chunk
{
Common::WriteStream &ws = add(ID_ANNO);
ws.write(saveName.c_str(), saveName.size());
ws.writeByte(0);
}
// Write 'SCVM' chunk with gameplay statistics
{
Common::WriteStream &ws = add(ID_SCVM);
// Write out the save date/time
TimeDate td;
g_system->getTimeAndDate(td);
ws.writeSint16LE(td.tm_year + 1900);
ws.writeSint16LE(td.tm_mon + 1);
ws.writeSint16LE(td.tm_mday);
ws.writeSint16LE(td.tm_hour);
ws.writeSint16LE(td.tm_min);
ws.writeUint32LE(g_vm->_events->getTotalPlayTicks());
}
}
} // End of namespace Glk

View File

@ -157,6 +157,11 @@ class QuetzalWriter {
};
private:
Common::Array<Chunk> _chunks;
/**
* Add chunks common to all Glk savegames
*/
void addCommonChunks(const Common::String &saveName);
public:
/**
* Clear
@ -171,7 +176,7 @@ public:
/**
* Save the added chunks to file
*/
void save(Common::WriteStream *out, uint32 formType = ID_IFSF);
void save(Common::WriteStream *out, const Common::String &saveName, uint32 formType = ID_IFSF);
};
} // End of namespace Glk