diff options
author | whiterandrek | 2018-05-25 17:48:22 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | d6b1b9396e54f78fb49c6c0b123e9463f91be676 (patch) | |
tree | f979cc4b79741a15a0b1a340b6ff92bc9ad492f0 | |
parent | 578b93af203272e9913adcc4ff793d25ac337e1a (diff) | |
download | scummvm-rg350-d6b1b9396e54f78fb49c6c0b123e9463f91be676.tar.gz scummvm-rg350-d6b1b9396e54f78fb49c6c0b123e9463f91be676.tar.bz2 scummvm-rg350-d6b1b9396e54f78fb49c6c0b123e9463f91be676.zip |
PINK: add state saving/loading of Module and GamePage
-rw-r--r-- | engines/pink/objects/module.cpp | 26 | ||||
-rw-r--r-- | engines/pink/objects/module.h | 7 | ||||
-rw-r--r-- | engines/pink/objects/pages/game_page.cpp | 59 | ||||
-rw-r--r-- | engines/pink/objects/pages/game_page.h | 10 |
4 files changed, 68 insertions, 34 deletions
diff --git a/engines/pink/objects/module.cpp b/engines/pink/objects/module.cpp index cdb374612a..a09e202fb3 100644 --- a/engines/pink/objects/module.cpp +++ b/engines/pink/objects/module.cpp @@ -23,6 +23,7 @@ #include "pink/pink.h" #include "pink/objects/module.h" #include "pink/objects/pages/game_page.h" +#include "pink/objects/actors/lead_actor.h" namespace Pink { @@ -99,4 +100,29 @@ InventoryMgr *Module::getInventoryMgr() { return &_invMgr; } +void Module::loadState(Archive &archive) { + _invMgr.loadState(archive); + _variables.deserialize(archive); + + for (uint i = 0; i < _pages.size(); ++i) { + _pages[i]->loadState(archive); + } + + _page = findPage(archive.readString()); + _page->loadManagers(); + _page->getLeadActor()->loadState(archive); +} + +void Module::saveState(Archive &archive) { + _invMgr.saveState(archive); + _variables.serialize(archive); + + for (uint i = 0; i < _pages.size(); ++i) { + _pages[i]->saveState(archive); + } + + archive.writeString(_page->getName()); + _page->getLeadActor()->saveState(archive); +} + } // End of namespace Pink diff --git a/engines/pink/objects/module.h b/engines/pink/objects/module.h index 16bda6cbc3..084fb19e93 100644 --- a/engines/pink/objects/module.h +++ b/engines/pink/objects/module.h @@ -46,6 +46,9 @@ public: Module(PinkEngine *game, const Common::String &name); ~Module(); + void loadState(Archive &archive); + void saveState(Archive &archive); + void load(Archive &archive); void init(bool isLoadingSave, const Common::String &pageName); void changePage(const Common::String &pageName); @@ -60,6 +63,8 @@ public: bool checkValueOfVariable(Common::String &variable, Common::String &value); void setVariable(Common::String &variable, Common::String &value); + GamePage *getPage() { return _page; }; + private: GamePage *findPage(const Common::String &pageName) const; @@ -67,7 +72,7 @@ private: GamePage *_page; Array<GamePage *> _pages; InventoryMgr _invMgr; - Common::StringMap _variables; + StringMap _variables; }; diff --git a/engines/pink/objects/pages/game_page.cpp b/engines/pink/objects/pages/game_page.cpp index 8e534443d5..883e129670 100644 --- a/engines/pink/objects/pages/game_page.cpp +++ b/engines/pink/objects/pages/game_page.cpp @@ -112,7 +112,7 @@ void GamePage::loadManagers() { _resMgr.init(_module->getGame(), this); if (_memFile != nullptr) { - loadState(); + loadStateFromMem(); delete _memFile; _memFile = nullptr; @@ -146,51 +146,50 @@ WalkMgr *GamePage::getWalkMgr() { return _walkMgr; } -void GamePage::loadState() { +void GamePage::loadStateFromMem() { Archive archive(static_cast<Common::SeekableReadStream*>(_memFile)); - //_variables.clear(1); - Common::StringMap mapTest; // HACK. Without it isn't working - //archive >> _variables; + _variables.deserialize(archive); - uint size = archive.readCount(); - for (uint i = 0; i < size; ++i) { - Common::String key = archive.readString(); - Common::String val = archive.readString(); - mapTest.setVal(key, val); - } - - _variables = mapTest; - - uint16 actorCount = archive.readWORD(); - - Common::String actorName; - for (int i = 0; i < actorCount; ++i) { - actorName = archive.readString(); - findActor(actorName)->loadState(archive); + for (uint i = 0; i < _actors.size(); ++i) { + _actors[i]->loadState(archive); } } -void GamePage::saveState() { +void GamePage::saveStateToMem() { _memFile = new Common::MemoryReadWriteStream(DisposeAfterUse::YES); Archive archive(static_cast<Common::WriteStream*>(_memFile)); + _variables.serialize(archive); - for (Common::StringMap::const_iterator it = _variables.begin(); it != _variables.end(); ++it) { - archive.writeString(it->_key); - archive.writeString(it->_value); - } - - archive.writeWORD(_actors.size()); for (uint i = 0; i < _actors.size(); ++i) { - archive.writeString(_actors[i]->getName()); _actors[i]->saveState(archive); } +} +void GamePage::loadState(Archive &archive) { + uint size = archive.readDWORD(); + _memFile = new Common::MemoryReadWriteStream(DisposeAfterUse::YES); + for (uint i = 0; i < size; ++i) { + _memFile->writeByte(_memFile->readByte()); + } +} + +void GamePage::saveState(Archive &archive) { + if (this == _module->getPage()) { + saveStateToMem(); + archive.writeDWORD(_memFile->size()); + } else { + if (_memFile != nullptr) { + archive.writeDWORD(_memFile->size()); + archive.getWriteStream()->write(_memFile->getData(), _memFile->size()); + } else + archive.writeDWORD(0); + } } void GamePage::unload() { _leadActor->setAction(_leadActor->findAction(kIdleAction)); - saveState(); + saveStateToMem(); clear(); _isLoaded = false; @@ -198,7 +197,7 @@ void GamePage::unload() { void GamePage::clear() { Page::clear(); - //_variables.clear(1); + _variables.clear(1); for (uint i = 0; i < _handlers.size(); ++i) { delete _handlers[i]; diff --git a/engines/pink/objects/pages/game_page.h b/engines/pink/objects/pages/game_page.h index 1c7e5cf217..7b4f25fcf1 100644 --- a/engines/pink/objects/pages/game_page.h +++ b/engines/pink/objects/pages/game_page.h @@ -41,6 +41,9 @@ public: virtual void toConsole(); virtual void deserialize(Archive &archive); + void loadState(Archive &archive); + void saveState(Archive &archive); + virtual void load(Archive &archive); void unload(); void loadManagers(); @@ -58,8 +61,9 @@ public: private: bool initHandler(); - void loadState(); - void saveState(); + + void loadStateFromMem(); + void saveStateToMem(); bool _isLoaded; Common::MemoryReadWriteStream *_memFile; @@ -68,7 +72,7 @@ private: WalkMgr *_walkMgr; Sequencer *_sequencer; Array<HandlerStartPage *> _handlers; - Common::StringMap _variables; + StringMap _variables; }; } |