diff options
author | Simei Yin | 2018-04-15 21:56:20 +0200 |
---|---|---|
committer | Simei Yin | 2018-04-15 22:10:41 +0200 |
commit | 2cf79dc67c8c904833e7c16b71b7f6fb64d6d011 (patch) | |
tree | 7d0ea571677b60b12661d1037ca9ec9cf6f2541a /engines/sludge | |
parent | 53c79fdde90f9dfa5467e501c3dcfb19a7494793 (diff) | |
download | scummvm-rg350-2cf79dc67c8c904833e7c16b71b7f6fb64d6d011.tar.gz scummvm-rg350-2cf79dc67c8c904833e7c16b71b7f6fb64d6d011.tar.bz2 scummvm-rg350-2cf79dc67c8c904833e7c16b71b7f6fb64d6d011.zip |
SLUDGE: Refactor save/load costume to Persona
Diffstat (limited to 'engines/sludge')
-rw-r--r-- | engines/sludge/loadsave.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/people.cpp | 58 | ||||
-rw-r--r-- | engines/sludge/people.h | 6 |
3 files changed, 35 insertions, 33 deletions
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 20725cebf1..9d0a0088b5 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -214,7 +214,7 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) { return saveStackRef(from->varData.theStack, stream); case SVT_COSTUME: - g_sludge->_peopleMan->saveCostume(from->varData.costumeHandler, stream); + from->varData.costumeHandler->save(stream); return false; case SVT_ANIM: @@ -253,7 +253,7 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) { to->varData.costumeHandler = new Persona; if (!checkNew(to->varData.costumeHandler)) return false; - g_sludge->_peopleMan->loadCostume(to->varData.costumeHandler, stream); + to->varData.costumeHandler->load(stream); return true; case SVT_ANIM: diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index 1574166176..27301c2126 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -158,6 +158,33 @@ bool PersonaAnimation::load(Common::SeekableReadStream *stream) { return true; } +bool Persona::save(Common::WriteStream *stream) { + int a; + stream->writeUint16BE(numDirections); + for (a = 0; a < numDirections * 3; a++) { + if (!animation[a]->save(stream)) + return false; + } + return true; +} + +bool Persona::load(Common::SeekableReadStream *stream) { + int a; + numDirections = stream->readUint16BE(); + animation = new PersonaAnimation *[numDirections * 3]; + if (!checkNew(animation)) + return false; + for (a = 0; a < numDirections * 3; a++) { + animation[a] = new PersonaAnimation ; + if (!checkNew(animation[a])) + return false; + + if (!animation[a]->load(stream)) + return false; + } + return true; +} + PeopleManager::PeopleManager(SludgeEngine *vm) { _vm = vm; _allPeople = nullptr; @@ -971,33 +998,6 @@ void PeopleManager::removeOneCharacter(int i) { } } -bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) { - int a; - stream->writeUint16BE(cossy->numDirections); - for (a = 0; a < cossy->numDirections * 3; a++) { - if (!cossy->animation[a]->save(stream)) - return false; - } - return true; -} - -bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stream) { - int a; - cossy->numDirections = stream->readUint16BE(); - cossy->animation = new PersonaAnimation *[cossy->numDirections * 3]; - if (!checkNew(cossy->animation)) - return false; - for (a = 0; a < cossy->numDirections * 3; a++) { - cossy->animation[a] = new PersonaAnimation ; - if (!checkNew(cossy->animation[a])) - return false; - - if (!cossy->animation[a]->load(stream)) - return false; - } - return true; -} - bool PeopleManager::savePeople(Common::WriteStream *stream) { OnScreenPerson *me = _allPeople; int countPeople = 0, a; @@ -1018,7 +1018,7 @@ bool PeopleManager::savePeople(Common::WriteStream *stream) { stream->writeFloatLE(me->x); stream->writeFloatLE(me->y); - saveCostume(me->myPersona, stream); + me->myPersona->save(stream); me->myAnim->save(stream); stream->writeByte(me->myAnim == me->lastUsedAnim); @@ -1094,7 +1094,7 @@ bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) { me->x = stream->readFloatLE(); me->y = stream->readFloatLE(); - loadCostume(me->myPersona, stream); + me->myPersona->load(stream); me->myAnim->load(stream); me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL; diff --git a/engines/sludge/people.h b/engines/sludge/people.h index 86ada693ac..baf127cf7b 100644 --- a/engines/sludge/people.h +++ b/engines/sludge/people.h @@ -65,6 +65,10 @@ struct PersonaAnimation { struct Persona { PersonaAnimation **animation; int numDirections; + + // Save & load + bool save(Common::WriteStream *stream); + bool load(Common::SeekableReadStream *stream); }; struct OnScreenPerson { @@ -135,8 +139,6 @@ public: // Loading and saving bool savePeople(Common::WriteStream *stream); bool loadPeople(Common::SeekableReadStream *stream); - bool saveCostume(Persona *cossy, Common::WriteStream *stream); - bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream); // Freeze void freeze(FrozenStuffStruct *frozenStuff); |