ZVISION: Implement auto-saving

This commit is contained in:
Filippos Karapetis 2014-12-26 18:22:18 +02:00
parent eea1ee445f
commit e5f0ee2271
6 changed files with 21 additions and 21 deletions

View File

@ -308,6 +308,11 @@ SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, in
if (successfulRead) {
SaveStateDescriptor desc(slot, header.saveName);
// Do not allow save slot 0 (used for auto-saving) to be deleted or
// overwritten.
desc.setDeletableFlag(slot != 0);
desc.setWriteProtectedFlag(slot == 0);
desc.setThumbnail(header.thumbnail);
if (header.version > 0) {

View File

@ -87,6 +87,8 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName) {
file->finalize();
delete file;
_lastSaveTime = g_system->getMillis();
}
void SaveManager::saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream) {
@ -99,6 +101,8 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName, Common::Me
file->finalize();
delete file;
_lastSaveTime = g_system->getMillis();
}
void SaveManager::saveGameBuffered(uint slot, const Common::String &saveName) {
@ -109,15 +113,7 @@ void SaveManager::saveGameBuffered(uint slot, const Common::String &saveName) {
}
void SaveManager::autoSave() {
Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(_engine->generateAutoSaveFileName());
writeSaveGameHeader(file, "auto");
_engine->getScriptManager()->serialize(file);
// Cleanup
file->finalize();
delete file;
saveGame(0, "Auto save");
}
void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName) {

View File

@ -48,13 +48,18 @@ struct SaveGameHeader {
class SaveManager {
public:
SaveManager(ZVision *engine) : _engine(engine), _tempSave(NULL) {}
SaveManager(ZVision *engine) : _engine(engine), _tempSave(NULL), _lastSaveTime(0) {}
~SaveManager() {
flushSaveBuffer();
}
uint32 getLastSaveTime() const {
return _lastSaveTime;
}
private:
ZVision *_engine;
uint32 _lastSaveTime;
static const uint32 SAVEGAME_ID;
enum {
@ -67,8 +72,7 @@ private:
public:
/**
* Called every room change. Saves the state of the room just before
* we switched rooms. Uses ZVision::generateAutoSaveFileName() to
* create the save file name.
* the room changes.
*/
void autoSave();
/**

View File

@ -569,10 +569,6 @@ void ScriptManager::ChangeLocationReal() {
} else {
if (_currentLocation.world == 'g' && _currentLocation.room == 'j')
_engine->getSaveManager()->flushSaveBuffer();
else {
// Auto save
//_engine->getSaveManager()->autoSave();
}
}
setStateValue(StateKey_World, _nextLocation.world);

View File

@ -259,6 +259,10 @@ Common::Error ZVision::run() {
delay >>= 1;
}
if (canSaveGameStateCurrently() && shouldPerformAutoSave(_saveManager->getLastSaveTime())) {
_saveManager->autoSave();
}
_system->delayMillis(delay);
}
@ -279,10 +283,6 @@ Common::String ZVision::generateSaveFileName(uint slot) {
return Common::String::format("%s.%03u", _targetName.c_str(), slot);
}
Common::String ZVision::generateAutoSaveFileName() {
return Common::String::format("%s.auto", _targetName.c_str());
}
void ZVision::setRenderDelay(uint delay) {
_frameRenderDelay = delay;
}

View File

@ -194,7 +194,6 @@ public:
Video::VideoDecoder *loadAnimation(const Common::String &fileName);
Common::String generateSaveFileName(uint slot);
Common::String generateAutoSaveFileName();
void setRenderDelay(uint);
bool canRender();