MOHAWK: Remove autosave code

This commit is contained in:
Paul Gilbert 2020-02-05 07:28:12 -08:00 committed by Paul Gilbert
parent 429cfd1cad
commit d35d91e6f6
8 changed files with 17 additions and 63 deletions

View file

@ -489,6 +489,7 @@ void Engine::handleAutoSave() {
if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) { if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) {
// Save the autosave // Save the autosave
if (canSaveAutosaveCurrently())
saveGameState(getAutosaveSlot(), _("Autosave"), true); saveGameState(getAutosaveSlot(), _("Autosave"), true);
// Reset the last autosave time // Reset the last autosave time

View file

@ -385,6 +385,13 @@ public:
*/ */
void handleAutoSave(); void handleAutoSave();
/**
* Indicates whether an autosave can currently be saved.
*/
virtual bool canSaveAutosaveCurrently() {
return canSaveGameStateCurrently();
}
/** /**
* Returns the slot that should be used for autosaves * Returns the slot that should be used for autosaves
*/ */

View file

@ -89,7 +89,6 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription
_currentCursor = 0; _currentCursor = 0;
_mainCursor = kDefaultMystCursor; _mainCursor = kDefaultMystCursor;
_showResourceRects = false; _showResourceRects = false;
_lastSaveTime = 0;
_sound = nullptr; _sound = nullptr;
_video = nullptr; _video = nullptr;
@ -560,10 +559,6 @@ void MohawkEngine_Myst::doFrame() {
_waitingOnBlockingOperation = false; _waitingOnBlockingOperation = false;
} }
if (shouldPerformAutoSave(_lastSaveTime)) {
tryAutoSaving();
}
Common::Event event; Common::Event event;
while (_system->getEventManager()->pollEvent(event)) { while (_system->getEventManager()->pollEvent(event)) {
switch (event.type) { switch (event.type) {
@ -629,11 +624,6 @@ void MohawkEngine_Myst::doFrame() {
break; break;
} }
break; break;
case Common::EVENT_QUIT:
case Common::EVENT_RTL:
// Attempt to autosave before exiting
tryAutoSaving();
break;
default: default:
break; break;
} }
@ -960,8 +950,6 @@ MystArea *MohawkEngine_Myst::loadResource(Common::SeekableReadStream *rlstStream
} }
Common::Error MohawkEngine_Myst::loadGameState(int slot) { Common::Error MohawkEngine_Myst::loadGameState(int slot) {
tryAutoSaving();
if (_gameState->load(slot)) if (_gameState->load(slot))
return Common::kNoError; return Common::kNoError;
@ -977,24 +965,8 @@ Common::Error MohawkEngine_Myst::saveGameState(int slot, const Common::String &d
return _gameState->save(slot, desc, thumbnail, false) ? Common::kNoError : Common::kUnknownError; return _gameState->save(slot, desc, thumbnail, false) ? Common::kNoError : Common::kUnknownError;
} }
void MohawkEngine_Myst::tryAutoSaving() { bool MohawkEngine_Myst::canSaveAutosaveCurrently() {
if (!canSaveGameStateCurrently()) { return canSaveGameStateCurrently() && _gameState->isAutoSaveAllowed();
return; // Can't save right now, try again on the next frame
}
_lastSaveTime = _system->getMillis();
if (!_gameState->isAutoSaveAllowed()) {
return; // Can't autosave ever, try again after the next autosave delay
}
const Graphics::Surface *thumbnail = nullptr;
if (_stack->getStackId() == kMenuStack) {
thumbnail = _gfx->getThumbnailForMainMenu();
}
if (!_gameState->save(MystGameState::kAutoSaveSlot, "Autosave", thumbnail, true))
warning("Attempt to autosave has failed.");
} }
bool MohawkEngine_Myst::hasGameSaveSupport() const { bool MohawkEngine_Myst::hasGameSaveSupport() const {

View file

@ -189,7 +189,8 @@ public:
bool canSaveGameStateCurrently() override; bool canSaveGameStateCurrently() override;
Common::Error loadGameState(int slot) override; Common::Error loadGameState(int slot) override;
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override; Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
void tryAutoSaving(); virtual bool canSaveAutosaveCurrently() override;
bool hasFeature(EngineFeature f) const override; bool hasFeature(EngineFeature f) const override;
static Common::Array<Common::Keymap *> initKeymaps(const char *target); static Common::Array<Common::Keymap *> initKeymaps(const char *target);
@ -207,7 +208,6 @@ private:
MystCardPtr _card; MystCardPtr _card;
MystCardPtr _prevCard; MystCardPtr _prevCard;
uint32 _lastSaveTime;
bool hasGameSaveSupport() const; bool hasGameSaveSupport() const;
void pauseEngineIntern(bool pause) override; void pauseEngineIntern(bool pause) override;

View file

@ -229,10 +229,6 @@ void MohawkEngine_Riven::doFrame() {
_scriptMan->runQueuedScripts(); _scriptMan->runQueuedScripts();
} }
if (shouldPerformAutoSave(_lastSaveTime)) {
tryAutoSaving();
}
_inventory->onFrame(); _inventory->onFrame();
// Update the screen once per frame // Update the screen once per frame
@ -314,7 +310,6 @@ void MohawkEngine_Riven::processInput() {
case Common::EVENT_QUIT: case Common::EVENT_QUIT:
case Common::EVENT_RTL: case Common::EVENT_RTL:
// Attempt to autosave before exiting // Attempt to autosave before exiting
tryAutoSaving();
break; break;
default: default:
break; break;
@ -751,23 +746,10 @@ void MohawkEngine_Riven::saveGameStateAndDisplayError(int slot, const Common::St
} }
} }
void MohawkEngine_Riven::tryAutoSaving() { bool MohawkEngine_Riven::canSaveAutosaveCurrently() {
if (!canSaveGameStateCurrently() || _gameEnded) { return canSaveGameStateCurrently() && !_gameEnded;
return; // Can't save right now, try again on the next frame
}
_lastSaveTime = _system->getMillis();
if (!_saveLoad->isAutoSaveAllowed()) {
return; // Can't autosave ever, try again after the next autosave delay
}
Common::Error saveError = saveGameState(RivenSaveLoad::kAutoSaveSlot, "Autosave", true);
if (saveError.getCode() != Common::kNoError)
warning("Attempt to autosave has failed.");
} }
void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) { void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
Common::String cardName = getStack()->getName(kCardNames, cardNameId); Common::String cardName = getStack()->getName(kCardNames, cardNameId);
if (cardName.empty()) if (cardName.empty())
@ -844,7 +826,6 @@ void MohawkEngine_Riven::runOptionsDialog() {
if (hasGameEnded()) { if (hasGameEnded()) {
// Attempt to autosave before exiting // Attempt to autosave before exiting
tryAutoSaving();
} }
_gfx->setTransitionMode((RivenTransitionMode) _vars["transitionmode"]); _gfx->setTransitionMode((RivenTransitionMode) _vars["transitionmode"]);

View file

@ -166,7 +166,7 @@ public:
// Save / Load // Save / Load
void runLoadDialog(); void runLoadDialog();
void runSaveDialog(); void runSaveDialog();
void tryAutoSaving(); virtual bool canSaveAutosaveCurrently() override;
void loadGameStateAndDisplayError(int slot); void loadGameStateAndDisplayError(int slot);
void saveGameStateAndDisplayError(int slot, const Common::String &desc); void saveGameStateAndDisplayError(int slot, const Common::String &desc);

View file

@ -60,8 +60,6 @@ bool RivenSaveMetadata::sync(Common::Serializer &s) {
return true; return true;
} }
const int RivenSaveLoad::kAutoSaveSlot = 0;
RivenSaveLoad::RivenSaveLoad(MohawkEngine_Riven *vm, Common::SaveFileManager *saveFileMan) : _vm(vm), _saveFileMan(saveFileMan) { RivenSaveLoad::RivenSaveLoad(MohawkEngine_Riven *vm, Common::SaveFileManager *saveFileMan) : _vm(vm), _saveFileMan(saveFileMan) {
} }
@ -110,7 +108,6 @@ SaveStateDescriptor RivenSaveLoad::querySaveMetaInfos(const int slot) {
Common::String filename = buildSaveFilename(slot); Common::String filename = buildSaveFilename(slot);
Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename); Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename);
SaveStateDescriptor descriptor; SaveStateDescriptor descriptor;
descriptor.setWriteProtectedFlag(slot == kAutoSaveSlot);
if (!loadFile) { if (!loadFile) {
return descriptor; return descriptor;
@ -142,8 +139,6 @@ SaveStateDescriptor RivenSaveLoad::querySaveMetaInfos(const int slot) {
descriptor.setPlayTime(metadata.totalPlayTime); descriptor.setPlayTime(metadata.totalPlayTime);
descriptor.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay); descriptor.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay);
descriptor.setSaveTime(metadata.saveHour, metadata.saveMinute); descriptor.setSaveTime(metadata.saveHour, metadata.saveMinute);
if (metadata.autoSave) // Allow non-saves to be deleted, but not autosaves
descriptor.setDeletableFlag(slot != kAutoSaveSlot);
delete metaStream; delete metaStream;
@ -171,7 +166,7 @@ bool RivenSaveLoad::isAutoSaveAllowed() {
// Open autosave slot and see if it an autosave // 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 // Autosaving will be enabled if it is an autosave or if there is no save in that slot
Common::String filename = buildSaveFilename(kAutoSaveSlot); Common::String filename = buildSaveFilename(_vm->getAutosaveSlot());
Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename); Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename);
if (!loadFile) { if (!loadFile) {
return true; // There is no save in the autosave slot, enable autosave return true; // There is no save in the autosave slot, enable autosave

View file

@ -59,8 +59,6 @@ struct RivenSaveMetadata {
class RivenSaveLoad { class RivenSaveLoad {
public: public:
static const int kAutoSaveSlot;
RivenSaveLoad(MohawkEngine_Riven*, Common::SaveFileManager*); RivenSaveLoad(MohawkEngine_Riven*, Common::SaveFileManager*);
~RivenSaveLoad(); ~RivenSaveLoad();