[Scummvm-git-logs] scummvm master -> 1f25347dd57942e1c50ddfeb51b660df52934c6f

dreammaster paulfgilbert at gmail.com
Thu Oct 8 05:00:16 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1f25347dd5 GLK: GLULX: Implement savegame logic


Commit: 1f25347dd57942e1c50ddfeb51b660df52934c6f
    https://github.com/scummvm/scummvm/commit/1f25347dd57942e1c50ddfeb51b660df52934c6f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-10-07T21:59:41-07:00

Commit Message:
GLK: GLULX: Implement savegame logic

Changed paths:
    engines/glk/glulx/exec.cpp
    engines/glk/glulx/glkop.cpp
    engines/glk/glulx/glulx.h
    engines/glk/glulx/serial.cpp
    engines/glk/quetzal.h
    engines/glk/window_graphics.cpp


diff --git a/engines/glk/glulx/exec.cpp b/engines/glk/glulx/exec.cpp
index fc1d202aae..eecd47adb6 100644
--- a/engines/glk/glulx/exec.cpp
+++ b/engines/glk/glulx/exec.cpp
@@ -680,22 +680,18 @@ PerformJump: /* goto label for successful jumping... ironic, no? */
 				protectend = val1;
 				break;
 
-			case op_save:
+			case op_save: {
 				push_callstub(inst[1].desttype, inst[1].value);
-#ifdef TODO
-				value = saveGameData(find_stream_by_id(inst[0].value), "Savegame").getCode() == Common::kNoError ? 0 : 1;
-#else
-				error("TODO");
-#endif
+				strid_t saveStream = find_stream_by_id(inst[0].value);
+				value = writeGameData(*saveStream).getCode() == Common::kNoError ? 0 : 1;
 				pop_callstub(value);
 				break;
+			}
+
+			case op_restore: {
+				strid_t stream = find_stream_by_id(inst[0].value);
+				value = readSaveData(*stream).getCode() == Common::kNoError ? 0 : 1;
 
-			case op_restore:
-#ifdef TODO
-				value = loadGameData(find_stream_by_id(inst[0].value)).getCode() == Common::kNoError ? 0 : 1;
-#else
-				error("TODO");
-#endif
 				if (value == 0) {
 					/* We've succeeded, and the stack now contains the callstub
 					   saved during saveundo. Ignore this opcode's operand. */
@@ -707,6 +703,7 @@ PerformJump: /* goto label for successful jumping... ironic, no? */
 					store_operand(inst[1].desttype, inst[1].value, value);
 				}
 				break;
+			}
 
 			case op_saveundo:
 				push_callstub(inst[0].desttype, inst[0].value);
diff --git a/engines/glk/glulx/glkop.cpp b/engines/glk/glulx/glkop.cpp
index 136c57e0f4..a7dfb36d4b 100644
--- a/engines/glk/glulx/glkop.cpp
+++ b/engines/glk/glulx/glkop.cpp
@@ -215,6 +215,14 @@ FullDispatcher:
 		/* Phase 2. */
 		gidispatch_call(funcnum, argnum, splot.garglist);
 
+		// WORKAROUND: For stream_open_file calls, for savegame handling
+		// we need to store a copy of what the savegame description was,
+		// for use when we actually generate the savefile contents
+		if (funcnum == 0x42) {
+			frefid_t fref = (frefid_t)splot.garglist[0]._opaqueref;
+			_savegameDescription = fref->_description;
+		}
+
 		/* Phase 3. */
 		argnum2 = 0;
 		cx = proto;
diff --git a/engines/glk/glulx/glulx.h b/engines/glk/glulx/glulx.h
index 19de42ed29..c89fe14d3a 100644
--- a/engines/glk/glulx/glulx.h
+++ b/engines/glk/glulx/glulx.h
@@ -189,6 +189,7 @@ private:
 
 	/**@}*/
 
+	Common::String _savegameDescription;
 protected:
 	/**
 	 * \defgroup glkop fields
@@ -423,19 +424,13 @@ public:
 	/**
 	 * Load a savegame from the passed Quetzal file chunk stream
 	 */
-	Common::Error readSaveData(Common::SeekableReadStream *rs) override {
-		// Unused
-		return Common::kUnknownError;
-	}
+	Common::Error readSaveData(Common::SeekableReadStream *rs) override;
 
 	/**
 	 * Save the game. The passed write stream represents access to the UMem chunk
 	 * in the Quetzal save file that will be created
 	 */
-	Common::Error writeGameData(Common::WriteStream *ws) override {
-		// Unused
-		return Common::kUnknownError;
-	}
+	Common::Error writeGameData(Common::WriteStream *ws) override;
 
 	/**
 	 * \defgroup Main access methods
diff --git a/engines/glk/glulx/serial.cpp b/engines/glk/glulx/serial.cpp
index fca41e98c1..22e0a2a326 100644
--- a/engines/glk/glulx/serial.cpp
+++ b/engines/glk/glulx/serial.cpp
@@ -225,6 +225,27 @@ uint Glulx::perform_restoreundo() {
 	return res;
 }
 
+Common::Error Glulx::readSaveData(Common::SeekableReadStream *rs) {
+	Common::ErrorCode errCode = Common::kNoError;
+	QuetzalReader r;
+	if (r.open(rs, ID_IFSF))
+		// Load in the savegame chunks
+		errCode = loadGameChunks(r).getCode();
+
+	return errCode;
+}
+
+Common::Error Glulx::writeGameData(Common::WriteStream *ws) {
+	QuetzalWriter w;
+	Common::ErrorCode errCode = saveGameChunks(w).getCode();
+
+	if (errCode == Common::kNoError) {
+		w.save(ws, _savegameDescription);
+	}
+
+	return errCode;
+}
+
 Common::Error Glulx::loadGameChunks(QuetzalReader &quetzal) {
 	uint res = 0;
 	uint heapsumlen = 0;
diff --git a/engines/glk/quetzal.h b/engines/glk/quetzal.h
index b7468a5676..802d4ade6c 100644
--- a/engines/glk/quetzal.h
+++ b/engines/glk/quetzal.h
@@ -108,7 +108,9 @@ public:
 		 */
 		Common::SeekableReadStream *getStream() {
 			_stream->seek(_chunks[_index]._offset);
-			return _stream->readStream(_chunks[_index]._size);
+			return (_chunks[_index]._size == 0) ?
+				new Common::MemoryReadStream((byte *)malloc(0), 0, DisposeAfterUse::YES) :
+				_stream->readStream(_chunks[_index]._size);
 		}
 	};
 private:
diff --git a/engines/glk/window_graphics.cpp b/engines/glk/window_graphics.cpp
index e39dd0a9e8..7efa23570c 100644
--- a/engines/glk/window_graphics.cpp
+++ b/engines/glk/window_graphics.cpp
@@ -247,8 +247,10 @@ void GraphicsWindow::drawPicture(const Graphics::Surface &image, uint transColor
 }
 
 void GraphicsWindow::getSize(uint *width, uint *height) const {
-	*width = _bbox.width();
-	*height = _bbox.height();
+	if (width)
+		*width = _bbox.width();
+	if (height)
+		*height = _bbox.height();
 }
 
 void GraphicsWindow::setBackgroundColor(uint color) {




More information about the Scummvm-git-logs mailing list