diff options
author | Paul Gilbert | 2015-08-15 20:26:36 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-08-15 20:26:36 -0400 |
commit | 621a37bbe30756a7983c1e5463389539898d41a5 (patch) | |
tree | d5f1fa95dd03590865d875a91a64f3a776987bad | |
parent | 11e327c4e7d41e01378cbdbaf339bbd09881f326 (diff) | |
download | scummvm-rg350-621a37bbe30756a7983c1e5463389539898d41a5.tar.gz scummvm-rg350-621a37bbe30756a7983c1e5463389539898d41a5.tar.bz2 scummvm-rg350-621a37bbe30756a7983c1e5463389539898d41a5.zip |
SHERLOCK: Fix saving/loading when characters are moving
-rw-r--r-- | engines/sherlock/people.cpp | 45 | ||||
-rw-r--r-- | engines/sherlock/people.h | 17 | ||||
-rw-r--r-- | engines/sherlock/saveload.h | 4 | ||||
-rw-r--r-- | engines/sherlock/scalpel/scalpel_people.cpp | 18 | ||||
-rw-r--r-- | engines/sherlock/scalpel/scalpel_people.h | 5 | ||||
-rw-r--r-- | engines/sherlock/talk.cpp | 2 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo_people.cpp | 30 |
7 files changed, 83 insertions, 38 deletions
diff --git a/engines/sherlock/people.cpp b/engines/sherlock/people.cpp index d91d7fa69a..25f379b68b 100644 --- a/engines/sherlock/people.cpp +++ b/engines/sherlock/people.cpp @@ -64,6 +64,40 @@ const char *const WALK_LIB_NAMES[NUM_IN_WALK_LIB] = { /*----------------------------------------------------------------*/ +void PointQueue::push(const Common::Point &pt) { + _impl.push_back(pt); +} + +Common::Point PointQueue::pop() { + Common::Point tmp = front(); + _impl.pop_front(); + return tmp; +} + +void PointQueue::synchronize(Common::Serializer &s) { + int count = _impl.size(); + s.syncAsUint16LE(count); + + if (s.isSaving()) { + for (Common::List<Common::Point>::iterator i = _impl.begin(); i != _impl.end(); ++i) { + Common::Point &pt = *i; + s.syncAsSint16LE(pt.x); + s.syncAsSint16LE(pt.y); + } + } else { + int xp, yp; + + _impl.clear(); + for (int idx = 0; idx < count; ++idx) { + s.syncAsSint16LE(xp); + s.syncAsSint16LE(yp); + _impl.push_back(Common::Point(xp, yp)); + } + } +} + +/*----------------------------------------------------------------*/ + Person::Person() : Sprite() { _walkLoaded = false; _oldWalkSequence = -1; @@ -194,15 +228,19 @@ void People::reset() { p._use[0]._verb = ""; p._use[1]._verb = ""; } - + + if (!saves._justLoaded) { + p._walkCount = 0; + p._walkTo.clear(); + p._delta = Point32(0, 0); + } + p._imageFrame = nullptr; p._frameNumber = 1; p._startSeq = 0; - p._delta = Point32(0, 0); p._oldPosition = Common::Point(0, 0); p._oldSize = Common::Point(0, 0); p._misc = 0; - p._walkCount = 0; p._pickUp = ""; p._allow = 0; p._noShapeSize = Common::Point(0, 0); @@ -220,7 +258,6 @@ void People::reset() { p._adjust = Common::Point(0, 0); // Load the default walk sequences - p._walkTo.clear(); p._oldWalkSequence = -1; p._walkSequences.clear(); if (IS_SERRATED_SCALPEL) { diff --git a/engines/sherlock/people.h b/engines/sherlock/people.h index d790e4ccb0..b97dc715cc 100644 --- a/engines/sherlock/people.h +++ b/engines/sherlock/people.h @@ -56,6 +56,21 @@ struct PersonData { _name(name), _portrait(portrait), _stillSequences(stillSequences), _talkSequences(talkSequences) {} }; +class PointQueue { +private: + Common::List<Common::Point> _impl; +public: + PointQueue() : _impl() {} + + bool empty() const { return _impl.empty(); } + void clear() { _impl.clear(); } + Common::Point &front() { return _impl.front(); } + const Common::Point &front() const { return _impl.front(); } + void push(const Common::Point &pt); + Common::Point pop(); + void synchronize(Common::Serializer &s); +}; + class Person : public Sprite { protected: /** @@ -63,7 +78,7 @@ protected: */ virtual Common::Point getSourcePoint() const = 0; public: - Common::Queue<Common::Point> _walkTo; + PointQueue _walkTo; int _srcZone, _destZone; bool _walkLoaded; Common::String _portrait; diff --git a/engines/sherlock/saveload.h b/engines/sherlock/saveload.h index 7f636792ac..f4f3e7cfd9 100644 --- a/engines/sherlock/saveload.h +++ b/engines/sherlock/saveload.h @@ -36,8 +36,8 @@ namespace Sherlock { #define ONSCREEN_FILES_COUNT 5 enum { - CURRENT_SAVEGAME_VERSION = 3, - MINIMUM_SAVEGAME_VERSION = 3 + CURRENT_SAVEGAME_VERSION = 4, + MINIMUM_SAVEGAME_VERSION = 4 }; enum SaveMode { SAVEMODE_NONE = 0, SAVEMODE_LOAD = 1, SAVEMODE_SAVE = 2 }; diff --git a/engines/sherlock/scalpel/scalpel_people.cpp b/engines/sherlock/scalpel/scalpel_people.cpp index 53876f8f1c..9ff3127020 100644 --- a/engines/sherlock/scalpel/scalpel_people.cpp +++ b/engines/sherlock/scalpel/scalpel_people.cpp @@ -370,6 +370,18 @@ Common::Point ScalpelPerson::getSourcePoint() const { _position.y / FIXED_INT_MULTIPLIER); } +void ScalpelPerson::synchronize(Serializer &s) { + s.syncAsSint32LE(_position.x); + s.syncAsSint32LE(_position.y); + s.syncAsSint32LE(_delta.x); + s.syncAsSint32LE(_delta.y); + s.syncAsSint16LE(_sequenceNumber); + s.syncAsSint16LE(_walkCount); + + // Walk to list + _walkTo.synchronize(s); +} + /*----------------------------------------------------------------*/ ScalpelPeople::ScalpelPeople(SherlockEngine *vm) : People(vm) { @@ -436,11 +448,9 @@ void ScalpelPeople::setTalking(int speaker) { } void ScalpelPeople::synchronize(Serializer &s) { - s.syncAsByte(_holmesOn); - s.syncAsSint32LE(_data[HOLMES]->_position.x); - s.syncAsSint32LE(_data[HOLMES]->_position.y); - s.syncAsSint16LE(_data[HOLMES]->_sequenceNumber); + (*this)[HOLMES].synchronize(s); s.syncAsSint16LE(_holmesQuotient); + s.syncAsByte(_holmesOn); if (s.isLoading()) { _savedPos = _data[HOLMES]->_position; diff --git a/engines/sherlock/scalpel/scalpel_people.h b/engines/sherlock/scalpel/scalpel_people.h index b53da2e6d8..ad9a6a5296 100644 --- a/engines/sherlock/scalpel/scalpel_people.h +++ b/engines/sherlock/scalpel/scalpel_people.h @@ -47,6 +47,11 @@ public: virtual ~ScalpelPerson() {} /** + * Synchronize the data for a savegame + */ + virtual void synchronize(Serializer &s); + + /** * This adjusts the sprites position, as well as it's animation sequence: */ virtual void adjustSprite(); diff --git a/engines/sherlock/talk.cpp b/engines/sherlock/talk.cpp index 549ad4fa5e..4be8730da8 100644 --- a/engines/sherlock/talk.cpp +++ b/engines/sherlock/talk.cpp @@ -177,7 +177,7 @@ void Talk::talkTo(const Common::String &filename) { // Turn on the Exit option ui._endKeyActive = true; - if (people[HOLMES]._walkCount || (people[HOLMES]._walkTo.size() > 0 && + if (people[HOLMES]._walkCount || (!people[HOLMES]._walkTo.empty() && (IS_SERRATED_SCALPEL || people._allowWalkAbort))) { // Only interrupt if trying to do an action, and not just if player is walking around the scene if (people._allowWalkAbort) diff --git a/engines/sherlock/tattoo/tattoo_people.cpp b/engines/sherlock/tattoo/tattoo_people.cpp index 9274d0a3c3..19010a6578 100644 --- a/engines/sherlock/tattoo/tattoo_people.cpp +++ b/engines/sherlock/tattoo/tattoo_people.cpp @@ -970,7 +970,10 @@ void TattooPerson::checkWalkGraphics() { void TattooPerson::synchronize(Serializer &s) { s.syncAsSint32LE(_position.x); s.syncAsSint32LE(_position.y); + s.syncAsSint32LE(_delta.x); + s.syncAsSint32LE(_delta.y); s.syncAsSint16LE(_sequenceNumber); + s.syncAsSint16LE(_walkCount); if (s.isSaving()) { SpriteType type = (_type == INVALID && _walkLoaded) ? HIDDEN_CHARACTER : _type; @@ -991,32 +994,7 @@ void TattooPerson::synchronize(Serializer &s) { s.syncAsByte(_updateNPCPath); // Walk to list - uint count = _walkTo.size(); - s.syncAsUint16LE(count); - if (s.isLoading()) { - // Load path - for (uint idx = 0; idx < count; ++idx) { - int xp = 0, yp = 0; - s.syncAsSint16LE(xp); - s.syncAsSint16LE(yp); - _walkTo.push(Common::Point(xp, yp)); - } - } else { - // Save path - Common::Array<Common::Point> path; - - // Save the points of the path - for (uint idx = 0; idx < count; ++idx) { - Common::Point pt = _walkTo.pop(); - s.syncAsSint16LE(pt.x); - s.syncAsSint16LE(pt.y); - path.push_back(pt); - } - - // Re-add the pending points back to the _walkTo queue - for (uint idx = 0; idx < count; ++idx) - _walkTo.push(path[idx]); - } + _walkTo.synchronize(s); // Verbs for (int idx = 0; idx < 2; ++idx) |