diff options
author | David Fioramonti | 2018-04-28 06:58:12 -0700 |
---|---|---|
committer | Bastien Bouclet | 2018-05-19 17:56:05 +0200 |
commit | 719c2b83742495f1619d62088d14f8b63fd50aaa (patch) | |
tree | 2125be2de2cbcc9bfe42f87ea467b5bf1fbe488c /engines/mohawk | |
parent | 43babaeef8ff385b1f10be1c2fa917085afd2f88 (diff) | |
download | scummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.tar.gz scummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.tar.bz2 scummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.zip |
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.
Diffstat (limited to 'engines/mohawk')
-rw-r--r-- | engines/mohawk/myst.cpp | 25 | ||||
-rw-r--r-- | engines/mohawk/myst.h | 4 | ||||
-rw-r--r-- | engines/mohawk/myst_state.cpp | 44 | ||||
-rw-r--r-- | engines/mohawk/myst_state.h | 7 |
4 files changed, 69 insertions, 11 deletions
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index f324c8cad4..7171373846 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 fcbdafa512..beefdb0394 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 ab98da1f00..5de336ac49 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 0eb7d56525..8ff87d1bbc 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 |