From 48adf18e21beedc2d56a88d9ca2aee36b507cfcb Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 14 Sep 2008 19:48:40 +0000 Subject: Added autosave support in Kyra. svn-id: r34535 --- engines/kyra/gui.cpp | 2 -- engines/kyra/kyra_hof.cpp | 5 +++++ engines/kyra/kyra_lok.cpp | 2 ++ engines/kyra/kyra_mr.cpp | 5 +++++ engines/kyra/kyra_v1.cpp | 3 +++ engines/kyra/kyra_v1.h | 5 +++++ engines/kyra/lol.h | 3 +++ engines/kyra/saveload.cpp | 9 ++++++++- engines/kyra/script_mr.cpp | 2 +- engines/kyra/timer_mr.cpp | 2 +- 10 files changed, 33 insertions(+), 5 deletions(-) (limited to 'engines/kyra') diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index 8a5a4dfc91..6864bd9c4d 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -311,8 +311,6 @@ void GUI::updateSaveList() { s1 -= '0'; s2 -= '0'; s3 -= '0'; - if (s1 == 9 && s2 == 9 && s3 == 9) - continue; _saveSlots.push_back(s1*100+s2*10+s3); } diff --git a/engines/kyra/kyra_hof.cpp b/engines/kyra/kyra_hof.cpp index 2c418e43e3..76d6f6ea05 100644 --- a/engines/kyra/kyra_hof.cpp +++ b/engines/kyra/kyra_hof.cpp @@ -462,8 +462,13 @@ void KyraEngine_HoF::runLoop() { _drawNoShapeFlag = 0; _gui->optionsButton(0); _deathHandler = -1; + + if (!_runFlag || !quit()) + break; } + checkAutosave(); + if (_system->getMillis() > _nextIdleAnim) showIdleAnim(); diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index 59127d62ad..f71cc8f409 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -406,6 +406,8 @@ void KyraEngine_LoK::mainLoop() { int32 frameTime = (int32)_system->getMillis(); _skipFlag = false; + checkAutosave(); + if (_currentCharacter->sceneId == 210) { updateKyragemFading(); if (seq_playEnd() && _deathHandler != 8) diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp index 3774cae6b0..9d3171e723 100644 --- a/engines/kyra/kyra_mr.cpp +++ b/engines/kyra/kyra_mr.cpp @@ -1008,7 +1008,12 @@ void KyraEngine_MR::runLoop() { _drawNoShapeFlag = 0; _gui->optionsButton(0); _deathHandler = -1; + + if (quit()) + break; } + + checkAutosave(); if (_system->getMillis() >= _nextIdleAnim) showIdleAnim(); diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp index 0a935a3e0d..8162232935 100644 --- a/engines/kyra/kyra_v1.cpp +++ b/engines/kyra/kyra_v1.cpp @@ -181,6 +181,9 @@ int KyraEngine_v1::init() { _gameToLoad = -1; } + // Prevent autosave on game startup + _lastAutosave = _system->getMillis(); + return 0; } diff --git a/engines/kyra/kyra_v1.h b/engines/kyra/kyra_v1.h index 81871615e8..d2732011be 100644 --- a/engines/kyra/kyra_v1.h +++ b/engines/kyra/kyra_v1.h @@ -271,6 +271,9 @@ protected: // save/load int _gameToLoad; + uint32 _lastAutosave; + void checkAutosave(); + const char *getSavegameFilename(int num); bool saveFileLoadable(int slot); @@ -295,6 +298,8 @@ protected: static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *file, bool loadThumbnail, SaveHeader &header); + virtual void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail) = 0; + Common::SeekableReadStream *openSaveForReading(const char *filename, SaveHeader &header); Common::WriteStream *openSaveForWriting(const char *filename, const char *saveName, const Graphics::Surface *thumbnail) const; }; diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index ee54f8abbb..2ae4d71580 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -147,6 +147,9 @@ private: void setHandItem(uint16) {} void removeHandItem() {} bool lineIsPassable(int, int) { return false; } + + // save + void saveGame(const char *fileName, const char *saveName, const Graphics::Surface *thumbnail) {} }; } // end of namespace Kyra diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp index 82e896007a..61201a2031 100644 --- a/engines/kyra/saveload.cpp +++ b/engines/kyra/saveload.cpp @@ -220,7 +220,7 @@ const char *KyraEngine_v1::getSavegameFilename(int num) { assert(num >= 0 && num <= 999); char extension[5]; - sprintf(extension, "%.3d", num); + sprintf(extension, "%03d", num); filename = _targetName + "." + extension; @@ -242,5 +242,12 @@ bool KyraEngine_v1::saveFileLoadable(int slot) { return false; } +void KyraEngine_v1::checkAutosave() { + if (shouldPerformAutoSave(_lastAutosave)) { + saveGame(getSavegameFilename(999), "Autosave", 0); + _lastAutosave = _system->getMillis(); + } +} + } // end of namespace Kyra diff --git a/engines/kyra/script_mr.cpp b/engines/kyra/script_mr.cpp index dad870a5f4..bc71e72ce4 100644 --- a/engines/kyra/script_mr.cpp +++ b/engines/kyra/script_mr.cpp @@ -293,7 +293,7 @@ int KyraEngine_MR::o3_updateScore(EMCState *script) { int KyraEngine_MR::o3_makeSecondChanceSave(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_MR::o3_makeSecondChanceSave(%p) ()", (const void *)script); - saveGame(getSavegameFilename(999), "SECOND CHANCE SAVE GAME", 0); + saveGame(getSavegameFilename(999), "Autosave", 0); return 0; } diff --git a/engines/kyra/timer_mr.cpp b/engines/kyra/timer_mr.cpp index ea7f64fed1..dd749723ce 100644 --- a/engines/kyra/timer_mr.cpp +++ b/engines/kyra/timer_mr.cpp @@ -65,7 +65,7 @@ void KyraEngine_MR::timerRunSceneScript7(int arg) { void KyraEngine_MR::timerFleaDeath(int arg) { debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_MR::timerFleaDeath(%d)", arg); _timer->setCountdown(4, 5400); - saveGame(getSavegameFilename(999), "SECOND CHANCE SAVE GAME", 0); + saveGame(getSavegameFilename(999), "Autosave", 0); _screen->hideMouse(); _timer->disable(4); runAnimationScript("FLEADTH1.EMC", 0, 0, 1, 1); -- cgit v1.2.3