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,7 +489,8 @@ void Engine::handleAutoSave() {
if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) {
// Save the autosave
saveGameState(getAutosaveSlot(), _("Autosave"), true);
if (canSaveAutosaveCurrently())
saveGameState(getAutosaveSlot(), _("Autosave"), true);
// Reset the last autosave time
_lastAutosaveTime = _system->getMillis();

View file

@ -385,6 +385,13 @@ public:
*/
void handleAutoSave();
/**
* Indicates whether an autosave can currently be saved.
*/
virtual bool canSaveAutosaveCurrently() {
return canSaveGameStateCurrently();
}
/**
* 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;
_mainCursor = kDefaultMystCursor;
_showResourceRects = false;
_lastSaveTime = 0;
_sound = nullptr;
_video = nullptr;
@ -560,10 +559,6 @@ void MohawkEngine_Myst::doFrame() {
_waitingOnBlockingOperation = false;
}
if (shouldPerformAutoSave(_lastSaveTime)) {
tryAutoSaving();
}
Common::Event event;
while (_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
@ -629,11 +624,6 @@ void MohawkEngine_Myst::doFrame() {
break;
}
break;
case Common::EVENT_QUIT:
case Common::EVENT_RTL:
// Attempt to autosave before exiting
tryAutoSaving();
break;
default:
break;
}
@ -960,8 +950,6 @@ MystArea *MohawkEngine_Myst::loadResource(Common::SeekableReadStream *rlstStream
}
Common::Error MohawkEngine_Myst::loadGameState(int slot) {
tryAutoSaving();
if (_gameState->load(slot))
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;
}
void MohawkEngine_Myst::tryAutoSaving() {
if (!canSaveGameStateCurrently()) {
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::canSaveAutosaveCurrently() {
return canSaveGameStateCurrently() && _gameState->isAutoSaveAllowed();
}
bool MohawkEngine_Myst::hasGameSaveSupport() const {

View file

@ -189,7 +189,8 @@ public:
bool canSaveGameStateCurrently() override;
Common::Error loadGameState(int slot) 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;
static Common::Array<Common::Keymap *> initKeymaps(const char *target);
@ -207,7 +208,6 @@ private:
MystCardPtr _card;
MystCardPtr _prevCard;
uint32 _lastSaveTime;
bool hasGameSaveSupport() const;
void pauseEngineIntern(bool pause) override;

View file

@ -229,10 +229,6 @@ void MohawkEngine_Riven::doFrame() {
_scriptMan->runQueuedScripts();
}
if (shouldPerformAutoSave(_lastSaveTime)) {
tryAutoSaving();
}
_inventory->onFrame();
// Update the screen once per frame
@ -314,7 +310,6 @@ void MohawkEngine_Riven::processInput() {
case Common::EVENT_QUIT:
case Common::EVENT_RTL:
// Attempt to autosave before exiting
tryAutoSaving();
break;
default:
break;
@ -751,23 +746,10 @@ void MohawkEngine_Riven::saveGameStateAndDisplayError(int slot, const Common::St
}
}
void MohawkEngine_Riven::tryAutoSaving() {
if (!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.");
bool MohawkEngine_Riven::canSaveAutosaveCurrently() {
return canSaveGameStateCurrently() && !_gameEnded;
}
void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
Common::String cardName = getStack()->getName(kCardNames, cardNameId);
if (cardName.empty())
@ -844,7 +826,6 @@ void MohawkEngine_Riven::runOptionsDialog() {
if (hasGameEnded()) {
// Attempt to autosave before exiting
tryAutoSaving();
}
_gfx->setTransitionMode((RivenTransitionMode) _vars["transitionmode"]);

View file

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

View file

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

View file

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