diff options
author | Filippos Karapetis | 2015-01-09 01:09:53 +0200 |
---|---|---|
committer | Filippos Karapetis | 2015-01-09 01:09:53 +0200 |
commit | 79b92fe04698d3336f1d5232d4701133ff3ac10c (patch) | |
tree | 6511d61966875619b0b332294b42dc8907e99489 /engines | |
parent | 345b33d9f0ea971e0ca69f1165d9d3b69d67984c (diff) | |
download | scummvm-rg350-79b92fe04698d3336f1d5232d4701133ff3ac10c.tar.gz scummvm-rg350-79b92fe04698d3336f1d5232d4701133ff3ac10c.tar.bz2 scummvm-rg350-79b92fe04698d3336f1d5232d4701133ff3ac10c.zip |
ZVISION: Clean up save logic, and fix a thumbnail-related FIXME
This fixes the save game thumbnails when using the original save/load
screens
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/detection.cpp | 2 | ||||
-rw-r--r-- | engines/zvision/file/save_manager.cpp | 59 | ||||
-rw-r--r-- | engines/zvision/file/save_manager.h | 9 | ||||
-rw-r--r-- | engines/zvision/scripting/controls/save_control.cpp | 4 |
4 files changed, 32 insertions, 42 deletions
diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 0385a0fd99..1295f76705 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -261,7 +261,7 @@ Common::Error ZVision::ZVision::loadGameState(int slot) { } Common::Error ZVision::ZVision::saveGameState(int slot, const Common::String &desc) { - _saveManager->saveGame(slot, desc); + _saveManager->saveGame(slot, desc, false); return Common::kNoError; } diff --git a/engines/zvision/file/save_manager.cpp b/engines/zvision/file/save_manager.cpp index 022b08884f..fb9cceecbe 100644 --- a/engines/zvision/file/save_manager.cpp +++ b/engines/zvision/file/save_manager.cpp @@ -69,7 +69,7 @@ bool SaveManager::scummVMSaveLoadDialog(bool isSave) { return false; if (isSave) { - saveGame(slot, desc); + saveGame(slot, desc, false); return true; } else { Common::ErrorCode result = loadGame(slot).getCode(); @@ -77,46 +77,34 @@ bool SaveManager::scummVMSaveLoadDialog(bool isSave) { } } -void SaveManager::saveGame(uint slot, const Common::String &saveName) { - Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); - Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); - - writeSaveGameHeader(file, saveName); +void SaveManager::saveGame(uint slot, const Common::String &saveName, bool useSaveBuffer) { + if (!_tempSave && useSaveBuffer) + return; - _engine->getScriptManager()->serialize(file); - - file->finalize(); - delete file; - - _lastSaveTime = g_system->getMillis(); -} - -void SaveManager::saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream) { Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); - writeSaveGameHeader(file, saveName); + writeSaveGameHeader(file, saveName, useSaveBuffer); - file->write(stream->getData(), stream->size()); + if (useSaveBuffer) + file->write(_tempSave->getData(), _tempSave->size()); + else + _engine->getScriptManager()->serialize(file); file->finalize(); delete file; - _lastSaveTime = g_system->getMillis(); -} - -void SaveManager::saveGameBuffered(uint slot, const Common::String &saveName) { - if (_tempSave) { - saveGame(slot, saveName, _tempSave); + if (useSaveBuffer) flushSaveBuffer(); - } + + _lastSaveTime = g_system->getMillis(); } void SaveManager::autoSave() { - saveGame(0, "Auto save"); + saveGame(0, "Auto save", false); } -void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName) { +void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName, bool useSaveBuffer) { file->writeUint32BE(SAVEGAME_ID); // Write version @@ -126,8 +114,11 @@ void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::S file->writeString(saveName); file->writeByte(0); - // Create a thumbnail and save it - Graphics::saveThumbnail(*file); + // Save the game thumbnail + if (useSaveBuffer) + file->write(_tempThumbnail->getData(), _tempThumbnail->size()); + else + Graphics::saveThumbnail(*file); // Write out the save date/time TimeDate td; @@ -245,18 +236,20 @@ Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) { } void SaveManager::prepareSaveBuffer() { - if (_tempSave) - delete _tempSave; + delete _tempThumbnail; + _tempThumbnail = new Common::MemoryWriteStreamDynamic; + Graphics::saveThumbnail(*_tempThumbnail); + delete _tempSave; _tempSave = new Common::MemoryWriteStreamDynamic; - _engine->getScriptManager()->serialize(_tempSave); } void SaveManager::flushSaveBuffer() { - if (_tempSave) - delete _tempSave; + delete _tempThumbnail; + _tempThumbnail = NULL; + delete _tempSave; _tempSave = NULL; } diff --git a/engines/zvision/file/save_manager.h b/engines/zvision/file/save_manager.h index 516d0e75cd..d3f6aaaedc 100644 --- a/engines/zvision/file/save_manager.h +++ b/engines/zvision/file/save_manager.h @@ -48,7 +48,7 @@ struct SaveGameHeader { class SaveManager { public: - SaveManager(ZVision *engine) : _engine(engine), _tempSave(NULL), _lastSaveTime(0) {} + SaveManager(ZVision *engine) : _engine(engine), _tempSave(NULL), _tempThumbnail(NULL), _lastSaveTime(0) {} ~SaveManager() { flushSaveBuffer(); } @@ -67,6 +67,7 @@ private: SAVE_VERSION = 1 }; + Common::MemoryWriteStreamDynamic *_tempThumbnail; Common::MemoryWriteStreamDynamic *_tempSave; public: @@ -83,9 +84,7 @@ public: * @param slot The save slot this save pertains to. Must be [1, 20] * @param saveName The internal name for this save. This is NOT the name of the actual save file. */ - void saveGame(uint slot, const Common::String &saveName); - void saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream); - void saveGameBuffered(uint slot, const Common::String &saveName); + void saveGame(uint slot, const Common::String &saveName, bool useSaveBuffer); /** * Loads the state data from the save file that slot references. Uses * ZVision::generateSaveFileName(slot) to get the save file name. @@ -101,7 +100,7 @@ public: void flushSaveBuffer(); bool scummVMSaveLoadDialog(bool isSave); private: - void writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName); + void writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName, bool useSaveBuffer); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp index 6cedddffeb..2ac77c4776 100644 --- a/engines/zvision/scripting/controls/save_control.cpp +++ b/engines/zvision/scripting/controls/save_control.cpp @@ -102,9 +102,7 @@ bool SaveControl::process(uint32 deltaTimeInMillis) { toSave = false; if (toSave) { - // FIXME: At this point, the screen shows the save control, so the save game thumbnails will always - // show the save control - _engine->getSaveManager()->saveGameBuffered(iter->saveId, inp->getText()); + _engine->getSaveManager()->saveGame(iter->saveId, inp->getText(), true); _engine->getRenderManager()->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000); _engine->getScriptManager()->changeLocation(_engine->getScriptManager()->getLastMenuLocation()); } |