GRIFFON: Implement autosaves

This commit is contained in:
Paul Gilbert 2020-02-02 21:01:50 -08:00 committed by Paul Gilbert
parent 055a9effc2
commit 318c7003fc
7 changed files with 22 additions and 6 deletions

1
engines/griffon/POTFILES Normal file
View File

@ -0,0 +1 @@
engines/griffon/griffon.cpp

View File

@ -21,6 +21,7 @@
*/
#include "base/plugins.h"
#include "common/config-manager.h"
#include "engines/advancedDetector.h"
#include "griffon/griffon.h"
@ -59,7 +60,9 @@ public:
return "Griffon Engine";
}
virtual int getMaximumSaveSlot() const { return 3; }
virtual int getMaximumSaveSlot() const {
return ConfMan.getInt("autosave_period") ? 4 : 3;
}
virtual const char *getOriginalCopyright() const {
return "The Griffon Legend (c) 2005 Syn9 (Daniel Kennedy)";

View File

@ -630,7 +630,7 @@ void GriffonEngine::saveLoadNew() {
}
}
if (lowerLock && tickPause < _ticks) {
if ((curCol == 1) && saveGameState(curRow - 1, "").getCode() == Common::kNoError) {
if ((curCol == 1) && saveGameState(curRow - 1, "", false).getCode() == Common::kNoError) {
_secStart += _secsInGame;
_secsInGame = 0;
lowerLock = false;

View File

@ -97,6 +97,7 @@ void GriffonEngine::mainLoop() {
checkTrigger();
checkInputs();
autoSaveCheck();
if (!_forcePause)
handleWalking();

View File

@ -40,6 +40,7 @@
#include "common/file.h"
#include "common/fs.h"
#include "common/system.h"
#include "common/translation.h"
#include "graphics/pixelformat.h"
#include "engines/util.h"
@ -60,6 +61,7 @@ GriffonEngine::GriffonEngine(OSystem *syst) : Engine(syst) {
_shouldQuit = false;
_gameMode = kGameModeIntro;
_lastAutosaveTime = g_system->getMillis();
_musicChannel = -1;
_menuChannel = -1;
@ -183,4 +185,11 @@ Common::Error GriffonEngine::run() {
return Common::kNoError;
}
void GriffonEngine::autoSaveCheck() {
if (shouldPerformAutoSave(_lastAutosaveTime) && canSaveGameStateCurrently()) {
saveGameState(4, _("Autosave"), true);
_lastAutosaveTime = g_system->getMillis();
}
}
}

View File

@ -340,6 +340,7 @@ private:
Common::RandomSource *_rnd;
bool _shouldQuit;
int _gameMode;
uint32 _lastAutosaveTime;
Console *_console;
@ -416,9 +417,10 @@ private:
virtual Common::String getSaveStateName(int slot) const override;
int loadPlayer(int slotnum);
virtual Common::Error loadGameState(int slot) override;
virtual Common::Error saveGameState(int slot, const Common::String &desc) override;
virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave) override;
virtual Common::Error loadGameStream(Common::SeekableReadStream *file) override;
virtual Common::Error saveGameStream(Common::WriteStream *file, bool autoSave) override;
virtual Common::Error saveGameStream(Common::WriteStream *file, bool isAutosave) override;
void autoSaveCheck();
// sound.cpp
void setChannelVolume(int channel, int volume);

View File

@ -69,9 +69,9 @@ Common::Error GriffonEngine::loadGameState(int slot) {
return result;
}
Common::Error GriffonEngine::saveGameState(int slot, const Common::String &desc) {
Common::Error GriffonEngine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
Common::String saveDesc = Common::String::format("Level: %d Map: %d", _player.level, _curMap);
return Engine::saveGameState(slot, saveDesc);
return Engine::saveGameState(slot, isAutosave ? desc : saveDesc, isAutosave);
}
Common::Error GriffonEngine::loadGameStream(Common::SeekableReadStream *file) {