[Scummvm-git-logs] scummvm master -> f45aefcf2bda79864df384acfebd3a624a0e5482

SupSuper supsuper at gmail.com
Sat Jun 5 05:25:30 UTC 2021


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:
f45aefcf2b TRECISION: Move save listing to MetaEngine


Commit: f45aefcf2bda79864df384acfebd3a624a0e5482
    https://github.com/scummvm/scummvm/commit/f45aefcf2bda79864df384acfebd3a624a0e5482
Author: SupSuper (supsuper at gmail.com)
Date: 2021-06-05T06:24:30+01:00

Commit Message:
TRECISION: Move save listing to MetaEngine

Changed paths:
    engines/trecision/graphics.cpp
    engines/trecision/graphics.h
    engines/trecision/logic.cpp
    engines/trecision/metaengine.cpp
    engines/trecision/saveload.cpp
    engines/trecision/video.cpp


diff --git a/engines/trecision/graphics.cpp b/engines/trecision/graphics.cpp
index ed18278b78..5a414a577e 100644
--- a/engines/trecision/graphics.cpp
+++ b/engines/trecision/graphics.cpp
@@ -272,12 +272,9 @@ void GraphicsManager::loadData() {
 	_font = _vm->readData("nlfont.fnt");
 }
 
-void GraphicsManager::setSaveSlotThumbnail(byte iconSlot, Graphics::Surface *thumbnail) {
-	thumbnail->convertToInPlace(_screenFormat);
+void GraphicsManager::setSaveSlotThumbnail(byte iconSlot, const Graphics::Surface *thumbnail) {
 	Graphics::Surface *scaled = thumbnail->scale(ICONDX, ICONDY);
-
-	thumbnail->free();
-	delete thumbnail;
+	scaled->convertToInPlace(_screenFormat);
 
 	for (uint16 y = 0; y < ICONDY; ++y) {
 		memcpy(_saveSlotThumbnails.getBasePtr(ICONDX * iconSlot, y), scaled->getBasePtr(0, y), ICONDX * 2);
diff --git a/engines/trecision/graphics.h b/engines/trecision/graphics.h
index a4c5e8b873..16c37bb83f 100644
--- a/engines/trecision/graphics.h
+++ b/engines/trecision/graphics.h
@@ -87,7 +87,7 @@ public:
 	void drawRightInventoryArrow(byte startLine);
 	void drawInventoryIcon(byte iconIndex, byte iconSlot, byte startLine);
 	void drawSaveSlotThumbnail(byte iconIndex, byte iconSlot, byte startLine);
-	void setSaveSlotThumbnail(byte iconSlot, Graphics::Surface *thumbnail);
+	void setSaveSlotThumbnail(byte iconSlot, const Graphics::Surface *thumbnail);
 	void readSurface(Common::SeekableReadStream *stream, Graphics::Surface *surface, uint16 width, uint16 height, uint16 count = 1);
 
 	void updatePixelFormat(uint16 *p, uint32 len) const;
diff --git a/engines/trecision/logic.cpp b/engines/trecision/logic.cpp
index 54835a4b23..e7e17bcd58 100644
--- a/engines/trecision/logic.cpp
+++ b/engines/trecision/logic.cpp
@@ -4071,7 +4071,7 @@ void LogicManager::handleClickControlPanel(uint16 curObj) {
 		break;
 	}
 
-	g_engine->syncSoundSettings();
+	_vm->syncSoundSettings();
 	ConfMan.flushToDisk();
 }
 
diff --git a/engines/trecision/metaengine.cpp b/engines/trecision/metaengine.cpp
index ef02d631cb..0e751e7d45 100644
--- a/engines/trecision/metaengine.cpp
+++ b/engines/trecision/metaengine.cpp
@@ -23,6 +23,8 @@
 #include "base/plugins.h"
 #include "engines/advancedDetector.h"
 #include "graphics/surface.h"
+#include "common/system.h"
+#include "common/savefile.h"
 
 #include "trecision/trecision.h"
 
@@ -33,6 +35,7 @@ class TrecisionMetaEngine : public AdvancedMetaEngine {
 
 	Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
 	void getSavegameThumbnail(Graphics::Surface &thumb) override;
+	SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
 };
 
 Common::Error TrecisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
@@ -47,6 +50,39 @@ void TrecisionMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 	thumb.copyFrom(((Trecision::TrecisionEngine *)g_engine)->_thumbnail);
 }
 
+SaveStateDescriptor TrecisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
+	Common::ScopedPtr<Common::InSaveFile> saveFile(g_system->getSavefileManager()->openForLoading(
+		getSavegameFile(slot, target)));
+
+	if (saveFile) {
+		const byte version = saveFile->readByte();
+
+		if (version >= SAVE_VERSION_ORIGINAL_MIN && version <= SAVE_VERSION_ORIGINAL_MAX) {
+			// Original saved game, convert
+			Common::String saveName = saveFile->readString(0, 40);
+
+			SaveStateDescriptor desc(slot, saveName);
+			desc.setAutosave(false);
+			if (slot == getAutosaveSlot())
+				desc.setWriteProtectedFlag(true);
+
+			// This is freed inside SaveStateDescriptor
+			const Graphics::PixelFormat kImageFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
+			Graphics::Surface *thumbnail = new Graphics::Surface();
+			thumbnail->create(ICONDX, ICONDY, kImageFormat);
+			saveFile->read(thumbnail->getPixels(), ICONDX * ICONDY * kImageFormat.bytesPerPixel);
+			desc.setThumbnail(thumbnail);
+
+			return desc;
+		} else if (version >= SAVE_VERSION_SCUMMVM_MIN) {
+			saveFile->seek(0);
+			return MetaEngine::querySaveMetaInfos(target, slot);
+		}
+	}
+
+	return SaveStateDescriptor();
+}
+
 bool Trecision::TrecisionEngine::hasFeature(EngineFeature f) const {
 	return (f == kSupportsSubtitleOptions) ||
 		   (f == kSupportsReturnToLauncher) ||
diff --git a/engines/trecision/saveload.cpp b/engines/trecision/saveload.cpp
index bc93258fe4..606be10c24 100644
--- a/engines/trecision/saveload.cpp
+++ b/engines/trecision/saveload.cpp
@@ -37,48 +37,16 @@
 namespace Trecision {
 
 void TrecisionEngine::loadSaveSlots(Common::StringArray &saveNames) {
-	Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
-
 	for (uint i = 0; i < ICONSHOWN; ++i) {
-		Common::String saveFileName = getSaveStateName(i + 1);
-		Common::InSaveFile *saveFile = saveFileMan->openForLoading(saveFileName);
-		ExtendedSavegameHeader header;
-
-		if (!saveFile) {
+		SaveStateDescriptor saveState = getMetaEngine()->querySaveMetaInfos(_targetName.c_str(), i + 1);
+		if (saveState.getSaveSlot() == -1) {
 			saveNames.push_back(_sysText[kMessageEmptySpot]);
 			_inventory.push_back(EMPTYSLOT);
-			continue;
-		}
-
-		const byte version = saveFile->readByte();
-
-		if (version >= SAVE_VERSION_ORIGINAL_MIN && version <= SAVE_VERSION_ORIGINAL_MAX) {
-			// Original saved game, convert
-			Common::String saveName = saveFile->readString(0, 40);
-			saveNames.push_back(saveName);
-
-			_inventory.push_back(EMPTYSLOT + i + 1);
-
-			// This is freed inside setSaveSlotThumbnail()
-			Graphics::Surface *thumbnail = new Graphics::Surface();
-			_graphicsMgr->readSurface(saveFile, thumbnail, ICONDX, ICONDY);
-			_graphicsMgr->setSaveSlotThumbnail(i, thumbnail);
-		} else if (version >= SAVE_VERSION_SCUMMVM_MIN) {
-			const bool headerRead = MetaEngine::readSavegameHeader(saveFile, &header, false);
-			if (headerRead) {
-				saveNames.push_back(header.description);
-				_inventory.push_back(EMPTYSLOT + i + 1);
-				_graphicsMgr->setSaveSlotThumbnail(i, header.thumbnail);
-			} else {
-				saveNames.push_back(_sysText[kMessageEmptySpot]);
-				_inventory.push_back(EMPTYSLOT);
-			}
 		} else {
-			saveNames.push_back(_sysText[kMessageEmptySpot]);
-			_inventory.push_back(EMPTYSLOT);
+			saveNames.push_back(saveState.getDescription());
+			_inventory.push_back(EMPTYSLOT + i + 1);
+			_graphicsMgr->setSaveSlotThumbnail(i, saveState.getThumbnail());
 		}
-
-		delete saveFile;
 	}
 
 	_inventoryRefreshStartIconOld = _inventoryRefreshStartLineOld = _lightIconOld = 0xFF;
diff --git a/engines/trecision/video.cpp b/engines/trecision/video.cpp
index c420243c14..410e445b09 100644
--- a/engines/trecision/video.cpp
+++ b/engines/trecision/video.cpp
@@ -158,7 +158,7 @@ void AnimManager::playMovie(const Common::String &filename, int startFrame, int
 			drawFrame(smkDecoder, x, y, true);
 		}
 
-		while (g_engine->getEventManager()->pollEvent(event)) {
+		while (_vm->getEventManager()->pollEvent(event)) {
 			if (event.type == Common::EVENT_KEYUP && event.kbd.keycode == Common::KEYCODE_ESCAPE)
 				skipVideo = true;
 		}




More information about the Scummvm-git-logs mailing list