[Scummvm-git-logs] scummvm master -> e41bcd193523ce2a87c19f0c297e0db1c755bb5c
dreammaster
paulfgilbert at gmail.com
Fri Jun 26 15:12:29 UTC 2020
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
93ef8e13a3 GLK: Reset currentStream when it's stream is freed
050dd920c7 GLK: Refactor quetzal chunk save/load into their own methods
f5af470386 GLK: GLULXE: Change dest_t to use ScummVM streams
e41bcd1935 GLK: ZCODE: Allow detection on .data files
Commit: 93ef8e13a354c9348cffaf05594e1ab317216f15
https://github.com/scummvm/scummvm/commit/93ef8e13a354c9348cffaf05594e1ab317216f15
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-26T08:12:11-07:00
Commit Message:
GLK: Reset currentStream when it's stream is freed
Changed paths:
engines/glk/streams.cpp
diff --git a/engines/glk/streams.cpp b/engines/glk/streams.cpp
index b09fce79d3..a2dbbab1ed 100644
--- a/engines/glk/streams.cpp
+++ b/engines/glk/streams.cpp
@@ -1407,6 +1407,9 @@ void Streams::removeStream(Stream *stream) {
if ((*i)->_echoStream == stream)
(*i)->_echoStream = nullptr;
}
+
+ if (_currentStream == stream)
+ _currentStream = nullptr;
}
Stream *Streams::getFirst(uint *rock) {
Commit: 050dd920c7f1db4327e2eaa639ad6005e19b2877
https://github.com/scummvm/scummvm/commit/050dd920c7f1db4327e2eaa639ad6005e19b2877
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-26T08:12:12-07:00
Commit Message:
GLK: Refactor quetzal chunk save/load into their own methods
This makes it easier for sub-engines to override the creation
of the Quetzal savefile to save and load extra chunks
Changed paths:
engines/glk/glk.cpp
engines/glk/glk.h
diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp
index 6441f44421..c6bb80edf5 100644
--- a/engines/glk/glk.cpp
+++ b/engines/glk/glk.cpp
@@ -35,7 +35,6 @@
#include "glk/debugger.h"
#include "glk/events.h"
#include "glk/picture.h"
-#include "glk/quetzal.h"
#include "glk/screen.h"
#include "glk/selection.h"
#include "glk/sound.h"
@@ -194,39 +193,9 @@ Common::Error GlkEngine::loadGameState(int slot) {
Common::ErrorCode errCode = Common::kNoError;
QuetzalReader r;
- if (r.open(*file, ID_IFSF)) {
- // First scan for a SCVM chunk. It has information of the game the save is for,
- // so if present we can validate the save is for this game
- for (QuetzalReader::Iterator it = r.begin(); it != r.end(); ++it) {
- if ((*it)._id == ID_SCVM) {
- // Skip over date/time & playtime
- Common::SeekableReadStream *rs = it.getStream();
- rs->skip(14);
-
- uint32 interpType = rs->readUint32BE();
- Common::String langCode = QuetzalReader::readString(rs);
- Common::String md5 = QuetzalReader::readString(rs);
- delete rs;
-
- if (interpType != QuetzalBase::getInterpreterTag(getInterpreterType()) ||
- parseLanguage(langCode) !=getLanguage() || md5 != getGameMD5())
- errCode = Common::kReadingFailed;
- }
- }
-
- if (errCode == Common::kNoError) {
- // Scan for an uncompressed memory chunk
- errCode = Common::kReadingFailed; // Presume we won't find chunk
- for (QuetzalReader::Iterator it = r.begin(); it != r.end(); ++it) {
- if ((*it)._id == ID_UMem) {
- Common::SeekableReadStream *rs = it.getStream();
- errCode = readSaveData(rs).getCode();
- delete rs;
- break;
- }
- }
- }
- }
+ if (r.open(*file, ID_IFSF))
+ // Load in the savegame chunks
+ errCode = loadGameChunks(r).getCode();
file->close();
return errCode;
@@ -240,14 +209,9 @@ Common::Error GlkEngine::saveGameState(int slot, const Common::String &desc, boo
if (file == nullptr)
return Common::kWritingFailed;
- Common::ErrorCode errCode = Common::kNoError;
+ // Write out savegame chunks
QuetzalWriter w;
-
- // Add the uncompressed memory chunk with the game's save data
- {
- Common::WriteStream &ws = w.add(ID_UMem);
- errCode = writeGameData(&ws).getCode();
- }
+ Common::ErrorCode errCode = saveGameChunks(w).getCode();
if (errCode == Common::kNoError) {
w.save(*file, desc);
@@ -257,6 +221,47 @@ Common::Error GlkEngine::saveGameState(int slot, const Common::String &desc, boo
return errCode;
}
+Common::Error GlkEngine::loadGameChunks(QuetzalReader &quetzal) {
+ // First scan for a SCVM chunk. It has information of the game the save is for,
+ // so if present we can validate the save is for this game
+ for (QuetzalReader::Iterator it = quetzal.begin(); it != quetzal.end(); ++it) {
+ if ((*it)._id == ID_SCVM) {
+ // Skip over date/time & playtime
+ Common::SeekableReadStream *rs = it.getStream();
+ rs->skip(14);
+
+ uint32 interpType = rs->readUint32BE();
+ Common::String langCode = QuetzalReader::readString(rs);
+ Common::String md5 = QuetzalReader::readString(rs);
+ delete rs;
+
+ if (interpType != QuetzalBase::getInterpreterTag(getInterpreterType()) ||
+ parseLanguage(langCode) != getLanguage() || md5 != getGameMD5())
+ return Common::kReadingFailed;
+ }
+ }
+
+ // Scan for an uncompressed memory chunk
+ for (QuetzalReader::Iterator it = quetzal.begin(); it != quetzal.end(); ++it) {
+ if ((*it)._id == ID_UMem) {
+ Common::SeekableReadStream *rs = it.getStream();
+ Common::Error err = readSaveData(rs);
+ delete rs;
+
+ return err;
+ }
+ }
+
+ // Couldn't find any data chunk, so reading failed
+ return Common::kReadingFailed;
+}
+
+Common::Error GlkEngine::saveGameChunks(QuetzalWriter &quetzal) {
+ // Add the uncompressed memory chunk with the game's save data
+ Common::WriteStream &ws = quetzal.add(ID_UMem);
+ return writeGameData(&ws);
+}
+
void GlkEngine::syncSoundSettings() {
Engine::syncSoundSettings();
diff --git a/engines/glk/glk.h b/engines/glk/glk.h
index 0593565914..9a3bf1b4cc 100644
--- a/engines/glk/glk.h
+++ b/engines/glk/glk.h
@@ -31,6 +31,7 @@
#include "glk/glk_types.h"
#include "glk/streams.h"
#include "glk/pc_speaker.h"
+#include "glk/quetzal.h"
namespace Glk {
@@ -208,6 +209,16 @@ public:
*/
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
+ /**
+ * Loads Quetzal chunks from the passed savegame
+ */
+ virtual Common::Error loadGameChunks(QuetzalReader &quetzal);
+
+ /**
+ * Writes out the Quetzal chunks within a savegame
+ */
+ virtual Common::Error saveGameChunks(QuetzalWriter &quetzal);
+
/**
* Load a savegame from the passed Quetzal file chunk stream
*/
Commit: f5af4703860b0ef4b993ea2297fcddb714822d29
https://github.com/scummvm/scummvm/commit/f5af4703860b0ef4b993ea2297fcddb714822d29
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-26T08:12:12-07:00
Commit Message:
GLK: GLULXE: Change dest_t to use ScummVM streams
Changed paths:
engines/glk/glulxe/glulxe_types.h
engines/glk/glulxe/serial.cpp
diff --git a/engines/glk/glulxe/glulxe_types.h b/engines/glk/glulxe/glulxe_types.h
index 45596bc009..64987fa00e 100644
--- a/engines/glk/glulxe/glulxe_types.h
+++ b/engines/glk/glulxe/glulxe_types.h
@@ -377,15 +377,19 @@ typedef heapblock_struct heapblock_t;
* This structure allows us to write either to a Glk stream or to a dynamically-allocated memory chunk.
*/
struct dest_struct {
- int ismem;
+ bool _isMem;
- /* If it's a Glk stream: */
- strid_t str;
+ /* If it's a raw stream */
+ Common::SeekableReadStream *_src;
+ Common::WriteStream *_dest;
/* If it's a block of memory: */
- byte *ptr;
- uint pos;
- uint size;
+ byte *_ptr;
+ uint _pos;
+ uint _size;
+
+ dest_struct() : _isMem(false), _src(nullptr), _dest(nullptr),
+ _ptr(nullptr), _pos(0), _size(0) {}
};
typedef dest_struct dest_t;
diff --git a/engines/glk/glulxe/serial.cpp b/engines/glk/glulxe/serial.cpp
index 74685fb61a..0fc9ab794f 100644
--- a/engines/glk/glulxe/serial.cpp
+++ b/engines/glk/glulxe/serial.cpp
@@ -87,42 +87,38 @@ uint Glulxe::perform_saveundo() {
if (undo_chain_size == 0)
return 1;
- dest.ismem = true;
- dest.size = 0;
- dest.pos = 0;
- dest.ptr = nullptr;
- dest.str = nullptr;
+ dest._isMem = true;
res = 0;
if (res == 0) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- memstart = dest.pos;
+ memstart = dest._pos;
res = write_memstate(&dest);
- memlen = dest.pos - memstart;
+ memlen = dest._pos - memstart;
}
if (res == 0) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- heapstart = dest.pos;
+ heapstart = dest._pos;
res = write_heapstate(&dest, false);
- heaplen = dest.pos - heapstart;
+ heaplen = dest._pos - heapstart;
}
if (res == 0) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- stackstart = dest.pos;
+ stackstart = dest._pos;
res = write_stackstate(&dest, false);
- stacklen = dest.pos - stackstart;
+ stacklen = dest._pos - stackstart;
}
if (res == 0) {
/* Trim it down to the perfect size. */
- dest.ptr = (byte *)glulx_realloc(dest.ptr, dest.pos);
- if (!dest.ptr)
+ dest._ptr = (byte *)glulx_realloc(dest._ptr, dest._pos);
+ if (!dest._ptr)
res = 1;
}
if (res == 0) {
@@ -153,15 +149,15 @@ uint Glulxe::perform_saveundo() {
if (undo_chain_size > 1)
memmove(undo_chain + 1, undo_chain,
(undo_chain_size - 1) * sizeof(unsigned char *));
- undo_chain[0] = dest.ptr;
+ undo_chain[0] = dest._ptr;
if (undo_chain_num < undo_chain_size)
undo_chain_num += 1;
- dest.ptr = nullptr;
+ dest._ptr = nullptr;
} else {
/* It didn't work. */
- if (dest.ptr) {
- glulx_free(dest.ptr);
- dest.ptr = nullptr;
+ if (dest._ptr) {
+ glulx_free(dest._ptr);
+ dest._ptr = nullptr;
}
}
@@ -183,11 +179,8 @@ uint Glulxe::perform_restoreundo() {
if (undo_chain_size == 0 || undo_chain_num == 0)
return 1;
- dest.ismem = true;
- dest.size = 0;
- dest.pos = 0;
- dest.ptr = undo_chain[0];
- dest.str = nullptr;
+ dest._isMem = true;
+ dest._ptr = undo_chain[0];
res = 0;
if (res == 0) {
@@ -222,11 +215,11 @@ uint Glulxe::perform_restoreundo() {
memmove(undo_chain, undo_chain + 1,
(undo_chain_size - 1) * sizeof(unsigned char *));
undo_chain_num -= 1;
- glulx_free(dest.ptr);
- dest.ptr = nullptr;
+ glulx_free(dest._ptr);
+ dest._ptr = nullptr;
} else {
/* It didn't work. */
- dest.ptr = nullptr;
+ dest._ptr = nullptr;
}
return res;
@@ -249,11 +242,11 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
if (ws == nullptr)
return Common::kUnknownError;
- dest.ismem = false;
- dest.size = 0;
- dest.pos = 0;
- dest.ptr = nullptr;
- dest.str = ws;
+ dest._isMem = false;
+ dest._size = 0;
+ dest._pos = 0;
+ dest._ptr = nullptr;
+ dest._str = ws;
res = 0;
@@ -263,7 +256,7 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
}
if (res == 0) {
res = write_long(&dest, 0); /* space for file length */
- filestart = dest.pos;
+ filestart = dest._pos;
}
if (res == 0) {
@@ -290,9 +283,9 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- memstart = dest.pos;
+ memstart = dest._pos;
res = write_memstate(&dest);
- memlen = dest.pos - memstart;
+ memlen = dest._pos - memstart;
}
if (res == 0 && (memlen & 1) != 0) {
res = write_byte(&dest, 0);
@@ -306,9 +299,9 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- heapstart = dest.pos;
+ heapstart = dest._pos;
res = write_heapstate(&dest, true);
- heaplen = dest.pos - heapstart;
+ heaplen = dest._pos - heapstart;
}
/* Always even, so no padding necessary. */
@@ -320,15 +313,15 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
res = write_long(&dest, 0); /* space for chunk length */
}
if (res == 0) {
- stackstart = dest.pos;
+ stackstart = dest._pos;
res = write_stackstate(&dest, true);
- stacklen = dest.pos - stackstart;
+ stacklen = dest._pos - stackstart;
}
if (res == 0 && (stacklen & 1) != 0) {
res = write_byte(&dest, 0);
}
- filelen = dest.pos - filestart;
+ filelen = dest._pos - filestart;
/* Okay, fill in all the lengths. */
if (res == 0) {
@@ -388,11 +381,11 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
if (str == 0)
return Common::kUnknownError;
- dest.ismem = false;
- dest.size = 0;
- dest.pos = 0;
- dest.ptr = nullptr;
- dest.str = str;
+ dest._isMem = false;
+ dest._size = 0;
+ dest._pos = 0;
+ dest._ptr = nullptr;
+ dest._str = str;
res = 0;
@@ -409,7 +402,7 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
if (res == 0) {
res = read_long(&dest, &filelen);
}
- filestart = dest.pos;
+ filestart = dest._pos;
if (res == 0) {
res = read_long(&dest, &val);
@@ -419,7 +412,7 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
return Common::kUnknownError;
}
- while (res == 0 && dest.pos < filestart + filelen) {
+ while (res == 0 && dest._pos < filestart + filelen) {
/* Read a chunk and deal with it. */
uint chunktype = 0, chunkstart = 0, chunklen = 0;
unsigned char dummy;
@@ -430,7 +423,7 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
if (res == 0) {
res = read_long(&dest, &chunklen);
}
- chunkstart = dest.pos;
+ chunkstart = dest._pos;
if (chunktype == IFFID('I', 'F', 'h', 'd')) {
for (ix = 0; res == 0 && ix < 128; ix++) {
@@ -453,7 +446,7 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
}
}
- if (chunkstart + chunklen != dest.pos) {
+ if (chunkstart + chunklen != dest._pos) {
/* ### funny chunk length */
return Common::kUnknownError;
}
@@ -481,34 +474,33 @@ Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
}
int Glulxe::reposition_write(dest_t *dest, uint pos) {
- if (dest->ismem) {
- dest->pos = pos;
+ if (dest->_isMem) {
+ dest->_pos = pos;
} else {
- glk_stream_set_position(dest->str, pos, seekmode_Start);
- dest->pos = pos;
+ error("Seeking a WriteStream isn't allowed");
}
return 0;
}
int Glulxe::write_buffer(dest_t *dest, const byte *ptr, uint len) {
- if (dest->ismem) {
- if (dest->pos + len > dest->size) {
- dest->size = dest->pos + len + 1024;
- if (!dest->ptr) {
- dest->ptr = (byte *)glulx_malloc(dest->size);
+ if (dest->_isMem) {
+ if (dest->_pos + len > dest->_size) {
+ dest->_size = dest->_pos + len + 1024;
+ if (!dest->_ptr) {
+ dest->_ptr = (byte *)glulx_malloc(dest->_size);
} else {
- dest->ptr = (byte *)glulx_realloc(dest->ptr, dest->size);
+ dest->_ptr = (byte *)glulx_realloc(dest->_ptr, dest->_size);
}
- if (!dest->ptr)
+ if (!dest->_ptr)
return 1;
}
- memcpy(dest->ptr + dest->pos, ptr, len);
+ memcpy(dest->_ptr + dest->_pos, ptr, len);
} else {
- glk_put_buffer_stream(dest->str, (const char *)ptr, len);
+ dest->_dest->write(ptr, len);
}
- dest->pos += len;
+ dest->_pos += len;
return 0;
}
@@ -516,15 +508,15 @@ int Glulxe::write_buffer(dest_t *dest, const byte *ptr, uint len) {
int Glulxe::read_buffer(dest_t *dest, byte *ptr, uint len) {
uint newlen;
- if (dest->ismem) {
- memcpy(ptr, dest->ptr + dest->pos, len);
+ if (dest->_isMem) {
+ memcpy(ptr, dest->_ptr + dest->_pos, len);
} else {
- newlen = glk_get_buffer_stream(dest->str, (char *)ptr, len);
+ newlen = dest->_src->read(ptr, len);
if (newlen != len)
return 1;
}
- dest->pos += len;
+ dest->_pos += len;
return 0;
}
@@ -631,7 +623,7 @@ uint Glulxe::write_memstate(dest_t *dest) {
}
uint Glulxe::read_memstate(dest_t *dest, uint chunklen) {
- uint chunkend = dest->pos + chunklen;
+ uint chunkend = dest->_pos + chunklen;
uint newlen;
uint res, pos;
int val;
@@ -675,7 +667,7 @@ uint Glulxe::read_memstate(dest_t *dest, uint chunklen) {
ch = 0;
}
- if (dest->pos >= chunkend) {
+ if (dest->_pos >= chunkend) {
/* we're into the final, unstored run. */
} else if (runlen) {
runlen--;
Commit: e41bcd193523ce2a87c19f0c297e0db1c755bb5c
https://github.com/scummvm/scummvm/commit/e41bcd193523ce2a87c19f0c297e0db1c755bb5c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-06-26T08:12:12-07:00
Commit Message:
GLK: ZCODE: Allow detection on .data files
Changed paths:
engines/glk/zcode/detection.cpp
diff --git a/engines/glk/zcode/detection.cpp b/engines/glk/zcode/detection.cpp
index 178b480214..0c19da7346 100644
--- a/engines/glk/zcode/detection.cpp
+++ b/engines/glk/zcode/detection.cpp
@@ -64,7 +64,7 @@ GameDescriptor ZCodeMetaEngine::findGame(const char *gameId) {
bool ZCodeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
const char *const EXTENSIONS[] = { ".z1", ".z2", ".z3", ".z4", ".z5", ".z6", ".z7", ".z8",
- ".dat", ".zip", nullptr };
+ ".dat", ".data", ".zip", nullptr };
// Loop through the files of the folder
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
More information about the Scummvm-git-logs
mailing list