diff options
author | Eugene Sandulenko | 2011-06-28 22:55:14 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2011-06-29 17:16:25 +0300 |
commit | 15a16e556ca03b51b1fc03f135834bf57f592b52 (patch) | |
tree | 33b1fab3325c2ed4b7cc55e559526a2d08b9672a /engines/sword25/kernel | |
parent | c32a3ea0d30336771bab460ecccb58c4614e6294 (diff) | |
download | scummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.tar.gz scummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.tar.bz2 scummvm-rg350-15a16e556ca03b51b1fc03f135834bf57f592b52.zip |
SWORD25: Implement persistence functions for soundengine
Now sound is properly saved/restored. Implemented savegame versioning.
Compatibility with old saves pertained.
Diffstat (limited to 'engines/sword25/kernel')
-rw-r--r-- | engines/sword25/kernel/inputpersistenceblock.cpp | 5 | ||||
-rw-r--r-- | engines/sword25/kernel/inputpersistenceblock.h | 6 | ||||
-rw-r--r-- | engines/sword25/kernel/persistenceservice.cpp | 30 | ||||
-rw-r--r-- | engines/sword25/kernel/persistenceservice.h | 1 |
4 files changed, 34 insertions, 8 deletions
diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp index c1cd771e39..2d45dfb640 100644 --- a/engines/sword25/kernel/inputpersistenceblock.cpp +++ b/engines/sword25/kernel/inputpersistenceblock.cpp @@ -35,9 +35,10 @@ namespace Sword25 { -InputPersistenceBlock::InputPersistenceBlock(const void *data, uint dataLength) : +InputPersistenceBlock::InputPersistenceBlock(const void *data, uint dataLength, int version) : _data(static_cast<const byte *>(data), dataLength), - _errorState(NONE) { + _errorState(NONE), + _version(version) { _iter = _data.begin(); } diff --git a/engines/sword25/kernel/inputpersistenceblock.h b/engines/sword25/kernel/inputpersistenceblock.h index f643b06bc1..7e68137246 100644 --- a/engines/sword25/kernel/inputpersistenceblock.h +++ b/engines/sword25/kernel/inputpersistenceblock.h @@ -46,7 +46,7 @@ public: OUT_OF_SYNC }; - InputPersistenceBlock(const void *data, uint dataLength); + InputPersistenceBlock(const void *data, uint dataLength, int version); virtual ~InputPersistenceBlock(); void read(int16 &value); @@ -64,6 +64,8 @@ public: return _errorState; } + int getVersion() const { return _version; } + private: bool checkMarker(byte marker); bool checkBlockSize(int size); @@ -72,6 +74,8 @@ private: Common::Array<byte> _data; Common::Array<byte>::const_iterator _iter; ErrorState _errorState; + + int _version; }; } // End of namespace Sword25 diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp index c88360e031..27d669caa1 100644 --- a/engines/sword25/kernel/persistenceservice.cpp +++ b/engines/sword25/kernel/persistenceservice.cpp @@ -50,7 +50,9 @@ static const char *SAVEGAME_DIRECTORY = "saves"; static const char *FILE_MARKER = "BS25SAVEGAME"; static const uint SLOT_COUNT = 18; static const uint FILE_COPY_BUFFER_SIZE = 1024 * 10; -static const char *VERSIONID = "SCUMMVM1"; +static const char *VERSIONIDOLD = "SCUMMVM1"; +static const char *VERSIONID = "SCUMMVM2"; +static const int VERSIONNUM = 2; #define MAX_SAVEGAME_SIZE 100 @@ -99,6 +101,7 @@ struct SavegameInformation { bool isOccupied; bool isCompatible; Common::String description; + int version; uint gamedataLength; uint gamedataOffset; uint gamedataUncompressedLength; @@ -147,9 +150,15 @@ struct PersistenceService::Impl { // Read in the header Common::String storedMarker = loadString(file); Common::String storedVersionID = loadString(file); + if (storedVersionID == VERSIONIDOLD) { + curSavegameInfo.version = 1; + } else { + Common::String versionNum = loadString(file); + curSavegameInfo.version = atoi(versionNum.c_str()); + } Common::String gameDescription = loadString(file); - Common::String gameDataLength = loadString(file); - curSavegameInfo.gamedataLength = atoi(gameDataLength.c_str()); + Common::String gamedataLength = loadString(file); + curSavegameInfo.gamedataLength = atoi(gamedataLength.c_str()); Common::String gamedataUncompressedLength = loadString(file); curSavegameInfo.gamedataUncompressedLength = atoi(gamedataUncompressedLength.c_str()); @@ -158,7 +167,7 @@ struct PersistenceService::Impl { // The slot is marked as occupied. curSavegameInfo.isOccupied = true; // Check if the saved game is compatible with the current engine version. - curSavegameInfo.isCompatible = (storedVersionID == Common::String(VERSIONID)); + curSavegameInfo.isCompatible = (curSavegameInfo.version <= VERSIONNUM); // Load the save game description. curSavegameInfo.description = gameDescription; // The offset to the stored save game data within the file. @@ -242,6 +251,12 @@ Common::String &PersistenceService::getSavegameFilename(uint slotID) { return result; } +int PersistenceService::getSavegameVersion(uint slotID) { + if (!checkslotID(slotID)) + return -1; + return _impl->_savegameInformations[slotID].version; +} + bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotFilename) { // FIXME: This code is a hack which bypasses the savefile API, // and should eventually be removed. @@ -264,6 +279,11 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF file->writeString(VERSIONID); file->writeByte(0); + char buf[20]; + snprintf(buf, 20, "%d", VERSIONNUM); + file->writeString(buf); + file->writeByte(0); + TimeDate dt; g_system->getTimeAndDate(dt); file->writeString(formatTimestamp(dt)); @@ -385,7 +405,7 @@ bool PersistenceService::loadGame(uint slotID) { memcpy(uncompressedDataBuffer, compressedDataBuffer, uncompressedBufferSize); } - InputPersistenceBlock reader(&uncompressedDataBuffer[0], curSavegameInfo.gamedataUncompressedLength); + InputPersistenceBlock reader(&uncompressedDataBuffer[0], curSavegameInfo.gamedataUncompressedLength, curSavegameInfo.version); // Einzelne Engine-Module depersistieren. bool success = true; diff --git a/engines/sword25/kernel/persistenceservice.h b/engines/sword25/kernel/persistenceservice.h index f73962892c..59e0a3661d 100644 --- a/engines/sword25/kernel/persistenceservice.h +++ b/engines/sword25/kernel/persistenceservice.h @@ -57,6 +57,7 @@ public: void reloadSlots(); bool isSlotOccupied(uint slotID); bool isSavegameCompatible(uint slotID); + int getSavegameVersion(uint slotID); Common::String &getSavegameDescription(uint slotID); Common::String &getSavegameFilename(uint slotID); |