diff options
author | Paul Gilbert | 2014-04-22 23:00:41 -0400 |
---|---|---|
committer | Paul Gilbert | 2014-04-22 23:00:41 -0400 |
commit | 0e9e6cda40ee0bf739e6c7a6320a81307df7c8b9 (patch) | |
tree | d69131833413f6bd75ef84e95c64cc54da568e8e /engines/mads/inventory.cpp | |
parent | 3f1a49b567aac10fe8a195f7a2b8e07603470a72 (diff) | |
download | scummvm-rg350-0e9e6cda40ee0bf739e6c7a6320a81307df7c8b9.tar.gz scummvm-rg350-0e9e6cda40ee0bf739e6c7a6320a81307df7c8b9.tar.bz2 scummvm-rg350-0e9e6cda40ee0bf739e6c7a6320a81307df7c8b9.zip |
MADS: Beginnings of savegame synchronisation
Diffstat (limited to 'engines/mads/inventory.cpp')
-rw-r--r-- | engines/mads/inventory.cpp | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/engines/mads/inventory.cpp b/engines/mads/inventory.cpp index bb65430bb1..abd281dcc8 100644 --- a/engines/mads/inventory.cpp +++ b/engines/mads/inventory.cpp @@ -26,42 +26,57 @@ namespace MADS { -void InventoryObject::load(Common::SeekableReadStream &f) { - _descId = f.readUint16LE(); - _roomNumber = f.readUint16LE(); - _article = f.readByte(); - _vocabCount = f.readByte(); +void InventoryObject::synchronize(Common::Serializer &s) { + s.syncAsUint16LE(_descId); + s.syncAsUint16LE(_roomNumber); + s.syncAsByte(_article); + s.syncAsByte(_vocabCount); for (int i = 0; i < 3; ++i) { - _vocabList[i]._verbType = (VerbType)f.readByte(); - _vocabList[i]._prepType = (PrepType)f.readByte(); - _vocabList[i]._vocabId = f.readUint16LE(); + s.syncAsByte(_vocabList[i]._verbType); + s.syncAsByte(_vocabList[i]._prepType); + s.syncAsUint16LE( _vocabList[i]._vocabId); } - f.skip(4); // field12 - f.read(&_mutilateString[0], 10); - f.skip(16); + s.skip(4); // field12 + s.syncBytes((byte *)&_mutilateString[0], 10); + s.skip(16); } /*------------------------------------------------------------------------*/ void InventoryObjects::load() { File f("*OBJECTS.DAT"); + Common::Serializer s(&f, nullptr); - // Get the total numer of inventory objects - int count = f.readUint16LE(); - reserve(count); - - // Read in each object - for (int i = 0; i < count; ++i) { - InventoryObject obj; - obj.load(f); - push_back(obj); + // Load the objects data + synchronize(s); +} - // If it's for the player's inventory, add the index to the inventory list - if (obj._roomNumber == PLAYER_INVENTORY) { - _inventoryList.push_back(i); - assert(_inventoryList.size() <= 32); +void InventoryObjects::synchronize(Common::Serializer &s) { + int count = size(); + s.syncAsUint16LE(count); + + if (s.isSaving()) { + // Store the data for each object in the inventory lsit + for (int idx = 0; idx < count; ++idx) + (*this)[idx].synchronize(s); + } else { + clear(); + _inventoryList.clear(); + reserve(count); + + // Read in each object + for (int i = 0; i < count; ++i) { + InventoryObject obj; + obj.synchronize(s); + push_back(obj); + + // If it's for the player's inventory, add the index to the inventory list + if (obj._roomNumber == PLAYER_INVENTORY) { + _inventoryList.push_back(i); + assert(_inventoryList.size() <= 32); + } } } } |