[Scummvm-git-logs] scummvm master -> b248f432e97e40a5c0ae6739bfa3a24c2843e837

npjg nathanael.gentrydb8 at gmail.com
Wed Jul 8 03:22:14 UTC 2020


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:
b248f432e9 DIRECTOR: Finish implementing constraint of sprite


Commit: b248f432e97e40a5c0ae6739bfa3a24c2843e837
    https://github.com/scummvm/scummvm/commit/b248f432e97e40a5c0ae6739bfa3a24c2843e837
Author: Nathanael Gentry (nathanael.gentrydb8 at gmail.com)
Date: 2020-07-07T23:21:16-04:00

Commit Message:
DIRECTOR: Finish implementing constraint of sprite

Changed paths:
    engines/director/score.cpp
    engines/director/score.h


diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index ec89f90fdd..c23b4be273 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -156,20 +156,47 @@ void Channel::setClean(Sprite *nextSprite, int spriteId) {
 	}
 }
 
+void Channel::addRegistrationOffset(Common::Point &pos) {
+	if (_sprite->_cast && _sprite->_cast->_type == kCastBitmap) {
+		BitmapCastMember *bc = (BitmapCastMember *)(_sprite->_cast);
+
+		pos += Common::Point(bc->_initialRect.left - bc->_regX,
+												 bc->_initialRect.top - bc->_regY);
+	}
+}
+
 void Channel::addDelta(Common::Point pos) {
 	// TODO: Channel should have a pointer to its score
-	if (_constraint > g_director->getCurrentMovie()->getScore()->_channels.size() - 1) {
-		warning("Channel::addDelta: Received out-of-bounds constraint: %d", _constraint);
-		_constraint = 0;
-	} else if (_sprite->_moveable && _constraint > 0) {
+	if (_sprite->_moveable &&
+			_constraint > 0 &&
+			_constraint < g_director->getCurrentMovie()->getScore()->_channels.size()) {
 		Common::Rect constraintBbox = g_director->getCurrentMovie()->getScore()->_channels[_constraint]->getBbox();
 
 		Common::Rect currentBbox = getBbox();
-		currentBbox.translate(pos.x, pos.y);
+		currentBbox.translate(_delta.x + pos.x, _delta.y + pos.y);
 
-		// TODO: Snap to the nearest point on the rectangle.
-		if (constraintBbox.findIntersectingRect(currentBbox) != currentBbox)
-			return;
+		Common::Point regPoint;
+		addRegistrationOffset(regPoint);
+
+		constraintBbox.top += regPoint.y;
+		constraintBbox.bottom -= regPoint.y;
+
+		constraintBbox.left += regPoint.x;
+		constraintBbox.right -= regPoint.x;
+
+		if (!constraintBbox.contains(currentBbox)) {
+			if (currentBbox.top < constraintBbox.top) {
+				pos.y += constraintBbox.top - currentBbox.top;
+			} else if (currentBbox.bottom > constraintBbox.bottom) {
+				pos.y += constraintBbox.bottom - currentBbox.bottom;
+			}
+
+			if (currentBbox.left < constraintBbox.left) {
+				pos.x += constraintBbox.left - currentBbox.left;
+			} else if (currentBbox.right > constraintBbox.right) {
+				pos.x += constraintBbox.right - currentBbox.right;
+			}
+		}
 	}
 
 	_delta += pos;
@@ -177,14 +204,7 @@ void Channel::addDelta(Common::Point pos) {
 
 Common::Point Channel::getPosition() {
 	Common::Point res = _currentPoint;
-
-	if (_sprite->_cast && _sprite->_cast->_type == kCastBitmap) {
-		BitmapCastMember *bc = (BitmapCastMember *)(_sprite->_cast);
-
-		res += Common::Point(bc->_initialRect.left - bc->_regX,
-												 bc->_initialRect.top - bc->_regY);
-	}
-
+	addRegistrationOffset(res);
 	return res;
 }
 
diff --git a/engines/director/score.h b/engines/director/score.h
index 94aae24e86..26a81f2c24 100644
--- a/engines/director/score.h
+++ b/engines/director/score.h
@@ -123,6 +123,7 @@ struct Channel {
 	Channel(Sprite *sp);
 	bool isDirty(Sprite *nextSprite = nullptr);
 
+	void addRegistrationOffset(Common::Point &pos);
 	Common::Rect getBbox();
 	Common::Point getPosition();
 	MacShape *getShape();




More information about the Scummvm-git-logs mailing list