[Scummvm-cvs-logs] scummvm master -> 621a37bbe30756a7983c1e5463389539898d41a5

dreammaster dreammaster at scummvm.org
Sun Aug 16 02:27:57 CEST 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
621a37bbe3 SHERLOCK: Fix saving/loading when characters are moving


Commit: 621a37bbe30756a7983c1e5463389539898d41a5
    https://github.com/scummvm/scummvm/commit/621a37bbe30756a7983c1e5463389539898d41a5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-08-15T20:26:36-04:00

Commit Message:
SHERLOCK: Fix saving/loading when characters are moving

Changed paths:
    engines/sherlock/people.cpp
    engines/sherlock/people.h
    engines/sherlock/saveload.h
    engines/sherlock/scalpel/scalpel_people.cpp
    engines/sherlock/scalpel/scalpel_people.h
    engines/sherlock/talk.cpp
    engines/sherlock/tattoo/tattoo_people.cpp



diff --git a/engines/sherlock/people.cpp b/engines/sherlock/people.cpp
index d91d7fa..25f379b 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 d790e4c..b97dc71 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 7f63679..f4f3e7c 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 53876f8..9ff3127 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 b53da2e..ad9a6a5 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 549ad4f..4be8730 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 9274d0a..19010a6 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)






More information about the Scummvm-git-logs mailing list