[Scummvm-git-logs] scummvm master -> 719c2b83742495f1619d62088d14f8b63fd50aaa

bgK bastien.bouclet at gmail.com
Sat May 19 17:57:17 CEST 2018


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:
719c2b8374 MOHAWK: MYST: Autosave to Slot 0


Commit: 719c2b83742495f1619d62088d14f8b63fd50aaa
    https://github.com/scummvm/scummvm/commit/719c2b83742495f1619d62088d14f8b63fd50aaa
Author: David Fioramonti (dafioram at gmail.com)
Date: 2018-05-19T17:56:05+02:00

Commit Message:
MOHAWK: MYST: Autosave to Slot 0

The game will autosave to slot 0 using the save
period given in the scummvm config file
or when the user exits using the GMM.

Autosaves are only allowed when an autosave is
in slot 0 or there is no save in slot 0.

This will not override any saves the player
has previously put in save slot 0. If there
is a save in slot 0 that is not an autosave
then there will be no autosaving.

Changed paths:
    engines/mohawk/myst.cpp
    engines/mohawk/myst.h
    engines/mohawk/myst_state.cpp
    engines/mohawk/myst_state.h


diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index f324c8c..7171373 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -72,6 +72,7 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
 	_showResourceRects = false;
 	_curStack = 0;
 	_curCard = 0;
+	_lastSaveTime = 0;
 
 	_hoverResource = nullptr;
 	_activeResource = nullptr;
@@ -395,6 +396,11 @@ void MohawkEngine_Myst::doFrame() {
 		_waitingOnBlockingOperation = false;
 	}
 
+	if (shouldPerformAutoSave(_lastSaveTime) && canSaveGameStateCurrently() && _gameState->isAutoSaveAllowed()) {
+		autoSave();
+		_lastSaveTime = _system->getMillis();
+	}
+
 	Common::Event event;
 	while (_system->getEventManager()->pollEvent(event)) {
 		switch (event.type) {
@@ -447,6 +453,11 @@ void MohawkEngine_Myst::doFrame() {
 
 						if (_needsShowCredits) {
 							if (isInteractive()) {
+								if (canSaveGameStateCurrently() && _gameState->isAutoSaveAllowed()) {
+									// Attempt to autosave before exiting
+									autoSave();
+								}
+
 								_cursor->hideCursor();
 								changeToStack(kCreditsStack, 10000, 0, 0);
 								_needsShowCredits = false;
@@ -474,6 +485,13 @@ void MohawkEngine_Myst::doFrame() {
 						break;
 				}
 				break;
+			case Common::EVENT_QUIT:
+			case Common::EVENT_RTL:
+				if (canSaveGameStateCurrently() && _gameState->isAutoSaveAllowed()) {
+					// Attempt to autosave before exiting
+					autoSave();
+				}
+				break;
 			default:
 				break;
 		}
@@ -1158,7 +1176,12 @@ Common::Error MohawkEngine_Myst::loadGameState(int slot) {
 }
 
 Common::Error MohawkEngine_Myst::saveGameState(int slot, const Common::String &desc) {
-	return _gameState->save(slot, desc) ? Common::kNoError : Common::kUnknownError;
+	return _gameState->save(slot, desc, false) ? Common::kNoError : Common::kUnknownError;
+}
+
+void MohawkEngine_Myst::autoSave() {
+	if (!_gameState->save(Mohawk::kAutoSaveSlot, Mohawk::kAutoSaveName, true))
+		warning("Attempt to autosave has failed.");
 }
 
 bool MohawkEngine_Myst::hasGameSaveSupport() const {
diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h
index fcbdafa..beefdb0 100644
--- a/engines/mohawk/myst.h
+++ b/engines/mohawk/myst.h
@@ -96,6 +96,8 @@ enum TransitionType {
 };
 
 const uint16 kMasterpieceOnly = 0xFFFF;
+const int kAutoSaveSlot = 0;
+const Common::String kAutoSaveName = "Autosave";
 
 struct MystCondition {
 	uint16 var;
@@ -247,6 +249,7 @@ public:
 	bool canSaveGameStateCurrently() override;
 	Common::Error loadGameState(int slot) override;
 	Common::Error saveGameState(int slot, const Common::String &desc) override;
+	void autoSave();
 	bool hasFeature(EngineFeature f) const override;
 
 private:
@@ -258,6 +261,7 @@ private:
 
 	uint16 _curStack;
 	uint16 _curCard;
+	uint32 _lastSaveTime;
 	MystView _view;
 
 	bool _runExitScript;
diff --git a/engines/mohawk/myst_state.cpp b/engines/mohawk/myst_state.cpp
index ab98da1..5de336a 100644
--- a/engines/mohawk/myst_state.cpp
+++ b/engines/mohawk/myst_state.cpp
@@ -41,10 +41,11 @@ MystSaveMetadata::MystSaveMetadata() {
 	saveHour = 0;
 	saveMinute = 0;
 	totalPlayTime = 0;
+	autoSave = false;
 }
 
 bool MystSaveMetadata::sync(Common::Serializer &s) {
-	static const Common::Serializer::Version kCurrentVersion = 1;
+	static const Common::Serializer::Version kCurrentVersion = 2;
 
 	if (!s.syncVersion(kCurrentVersion)) {
 		return false;
@@ -57,6 +58,7 @@ bool MystSaveMetadata::sync(Common::Serializer &s) {
 	s.syncAsByte(saveMinute);
 	s.syncString(saveDescription);
 	s.syncAsUint32LE(totalPlayTime);
+	s.syncAsByte(autoSave, 2);
 
 	return true;
 }
@@ -180,12 +182,12 @@ void MystGameState::loadMetadata(int slot) {
 	delete metadataFile;
 }
 
-bool MystGameState::save(int slot, const Common::String &desc) {
+bool MystGameState::save(int slot, const Common::String &desc, bool autoSave) {
 	if (!saveState(slot)) {
 		return false;
 	}
 
-	updateMetadateForSaving(desc);
+	updateMetadateForSaving(desc, autoSave);
 
 	return saveMetadata(slot);
 }
@@ -216,7 +218,7 @@ Common::String MystGameState::buildMetadataFilename(int slot) {
 	return Common::String::format("myst-%03d.mym", slot);
 }
 
-void MystGameState::updateMetadateForSaving(const Common::String &desc) {
+void MystGameState::updateMetadateForSaving(const Common::String &desc, bool autoSave) {
 	// Update save creation info
 	TimeDate t;
 	g_system->getTimeAndDate(t);
@@ -227,6 +229,7 @@ void MystGameState::updateMetadateForSaving(const Common::String &desc) {
 	_metadata.saveMinute = t.tm_min;
 	_metadata.saveDescription = desc;
 	_metadata.totalPlayTime = _vm->getTotalPlayTime();
+	_metadata.autoSave = autoSave;
 }
 
 bool MystGameState::saveMetadata(int slot) {
@@ -251,12 +254,36 @@ bool MystGameState::saveMetadata(int slot) {
 	return true;
 }
 
+bool MystGameState::isAutoSaveAllowed() {
+	// Open autosave slot and see if it an autosave
+	// Autosaving will be enabled if it is an autosave or if there is no save in that slot
+	Common::String filename = buildMetadataFilename(Mohawk::kAutoSaveSlot);
+	Common::ScopedPtr<Common::InSaveFile> metadataFile(g_system->getSavefileManager()->openForLoading(filename));
+	if (!metadataFile) { // There is no save in the autosave slot, enable autosave
+		return true;
+	}
+
+	Common::Serializer m(metadataFile.get(), nullptr);
+
+	// Read the metadata file
+	Mohawk::MystSaveMetadata metadata;
+	if (!metadata.sync(m)) { // the save in the autosave slot is corrupted, enable autosave
+		return true;
+	}
+
+	return metadata.autoSave;
+}
+
 SaveStateDescriptor MystGameState::querySaveMetaInfos(int slot) {
 	// Open the metadata file
 	Common::String filename = buildMetadataFilename(slot);
 	Common::InSaveFile *metadataFile = g_system->getSavefileManager()->openForLoading(filename);
+
+	SaveStateDescriptor desc;
+	desc.setWriteProtectedFlag(slot == Mohawk::kAutoSaveSlot);
+
 	if (!metadataFile) {
-		return SaveStateDescriptor();
+		return desc;
 	}
 
 	Common::Serializer m(metadataFile, nullptr);
@@ -265,19 +292,20 @@ SaveStateDescriptor MystGameState::querySaveMetaInfos(int slot) {
 	Mohawk::MystSaveMetadata metadata;
 	if (!metadata.sync(m)) {
 		delete metadataFile;
-		return SaveStateDescriptor();
+		return desc;
 	}
 
 	// Set the save description
-	SaveStateDescriptor desc;
 	desc.setDescription(metadata.saveDescription);
 	desc.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay);
 	desc.setSaveTime(metadata.saveHour, metadata.saveMinute);
 	desc.setPlayTime(metadata.totalPlayTime);
+	desc.setDeletableFlag(slot != Mohawk::kAutoSaveSlot);
+
 	Graphics::Surface *thumbnail;
 	if (!Graphics::loadThumbnail(*metadataFile, thumbnail)) {
 		delete metadataFile;
-		return SaveStateDescriptor();
+		return desc;
 	}
 	desc.setThumbnail(thumbnail);
 
diff --git a/engines/mohawk/myst_state.h b/engines/mohawk/myst_state.h
index 0eb7d56..8ff87d1 100644
--- a/engines/mohawk/myst_state.h
+++ b/engines/mohawk/myst_state.h
@@ -47,6 +47,8 @@ struct MystSaveMetadata {
 
 	uint32 totalPlayTime;
 
+	bool autoSave;
+
 	Common::String saveDescription;
 
 	MystSaveMetadata();
@@ -105,7 +107,8 @@ public:
 	static Common::String querySaveDescription(int slot);
 
 	bool load(int slot);
-	bool save(int slot, const Common::String &desc);
+	bool save(int slot, const Common::String &desc, bool autoSave);
+	bool isAutoSaveAllowed();
 	static void deleteSave(int slot);
 
 	void addZipDest(uint16 stack, uint16 view);
@@ -340,7 +343,7 @@ private:
 	bool loadState(int slot);
 	void loadMetadata(int slot);
 	bool saveState(int slot);
-	void updateMetadateForSaving(const Common::String &desc);
+	void updateMetadateForSaving(const Common::String &desc, bool autoSave);
 	bool saveMetadata(int slot);
 
 	// The values in these regions are lists of VIEW resources





More information about the Scummvm-git-logs mailing list