[Scummvm-cvs-logs] CVS: scummvm/scumm actor.cpp,1.133,1.134 actor.h,1.32,1.33 boxes.cpp,1.42,1.43 boxes.h,1.5,1.6 debugger.cpp,1.62,1.63 scumm.h,1.262,1.263 scummvm.cpp,2.259,2.260

Max Horn fingolfin at users.sourceforge.net
Wed Jul 2 06:48:03 CEST 2003


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv24671

Modified Files:
	actor.cpp actor.h boxes.cpp boxes.h debugger.cpp scumm.h 
	scummvm.cpp 
Log Message:
removed #include "boxes.h" from scumm.h;  cleaned up AdjustBoxResult definition & usage; properly deal with larger box distances, thus partially fixing Zak on the airport (but original seems to have used a very different algorithm, so this really is only a partial fix)

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/actor.cpp,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- actor.cpp	2 Jul 2003 11:32:32 -0000	1.133
+++ actor.cpp	2 Jul 2003 13:47:02 -0000	1.134
@@ -24,6 +24,7 @@
 #include "scumm.h"
 #include "actor.h"
 #include "akos.h"
+#include "boxes.h"
 #include "charset.h"
 #include "costume.h"
 #include "resource.h"
@@ -605,17 +606,16 @@
 
 AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
 	const uint thresholdTable[] = { 30, 80, 0 };
-	AdjustBoxResult abr, tmp;
-	uint threshold;
-	uint bestDist;
-	int numBoxes;
-	int box;
+	AdjustBoxResult abr;
+	int16 tmpX, tmpY;
+	int tmpDist, bestDist, threshold, numBoxes;
 	byte flags, bestBox;
+	int box;
 	const int firstValidBox = (_vm->_features & GF_SMALL_HEADER) ? 0 : 1;
 
 	abr.x = dstX;
 	abr.y = dstY;
-	abr.dist = kInvalidBox;
+	abr.box = kInvalidBox;
 
 	if (ignoreBoxes)
 		return abr;
@@ -627,7 +627,7 @@
 		if (numBoxes < firstValidBox)
 			return abr;
 
-		bestDist = (uint) 0xFFFF;
+		bestDist = 0xFFFFFF;
 		bestBox = kInvalidBox;
 
 		// We iterate (backwards) over all boxes, searching the one closest
@@ -642,7 +642,7 @@
 			// For increased performance, we perform a quick test if
 			// the coordinates can even be within a distance of 'threshold'
 			// pixels of the box.
-			if (!_vm->inBoxQuickReject(box, dstX, dstY, threshold))
+			if (threshold > 0 && _vm->inBoxQuickReject(box, dstX, dstY, threshold))
 				continue;
 
 			// Check if the point is contained in the box. If it is,
@@ -650,23 +650,23 @@
 			if (_vm->checkXYInBoxBounds(box, dstX, dstY)) {
 				abr.x = dstX;
 				abr.y = dstY;
-				abr.dist = box;
+				abr.box = box;
 				return abr;
 			}
 
 			// Find the point in the box which is closest to our point.
-			tmp = _vm->getClosestPtOnBox(box, dstX, dstY);
+			tmpDist = _vm->getClosestPtOnBox(box, dstX, dstY, tmpX, tmpY);
 
 			// Check if the box is closer than the previous boxes.
-			if (tmp.dist < bestDist) {
-				abr.x = tmp.x;
-				abr.y = tmp.y;
+			if (tmpDist < bestDist) {
+				abr.x = tmpX;
+				abr.y = tmpY;
 	
-				if (tmp.dist == 0) {
-					abr.dist = box;
+				if (tmpDist == 0) {
+					abr.box = box;
 					return abr;
 				}
-				bestDist = tmp.dist;
+				bestDist = tmpDist;
 				bestBox = box;
 			}
 		}
@@ -674,7 +674,7 @@
 		// If the closest ('best') box we found is within the threshold, or if
 		// we are on the last run (i.e. threshold == 0), return that box.
 		if (threshold == 0 || threshold * threshold >= bestDist) {
-			abr.dist = bestBox;
+			abr.box = bestBox;
 			return abr;
 		}
 	}
@@ -689,9 +689,9 @@
 
 	x = abr.x;
 	y = abr.y;
-	walkdata.destbox = (byte)abr.dist;
+	walkdata.destbox = abr.box;
 
-	setBox(abr.dist);
+	setBox(abr.box);
 
 	walkdata.destx = -1;
 
@@ -1175,11 +1175,11 @@
 	}
 
 	if (ignoreBoxes) {
-		abr.dist = kInvalidBox;
+		abr.box = kInvalidBox;
 		walkbox = kInvalidBox;
 	} else {
 		if (_vm->checkXYInBoxBounds(walkdata.destbox, abr.x, abr.y)) {
-			abr.dist = walkdata.destbox;
+			abr.box = walkdata.destbox;
 		} else {
 			abr = adjustXYToBeInBox(abr.x, abr.y);
 		}
@@ -1194,7 +1194,7 @@
 
 	walkdata.destx = abr.x;
 	walkdata.desty = abr.y;
-	walkdata.destbox = (byte)abr.dist;	/* a box */
+	walkdata.destbox = abr.box;
 	walkdata.destdir = dir;
 	moving = (moving & MF_IN_LEG) | MF_NEW_LEG;
 	walkdata.point3x = 32000;

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/actor.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- actor.h	14 Jun 2003 13:49:47 -0000	1.32
+++ actor.h	2 Jul 2003 13:47:02 -0000	1.33
@@ -67,6 +67,11 @@
 	}
 };
 
+struct AdjustBoxResult {	/* Result type of AdjustBox functions */
+	int16 x, y;
+	byte box;
+};
+
 struct SaveLoadEntry;
 
 class Actor {

Index: boxes.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/boxes.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- boxes.cpp	30 Jun 2003 22:22:04 -0000	1.42
+++ boxes.cpp	2 Jul 2003 13:47:03 -0000	1.43
@@ -23,6 +23,7 @@
 #include "stdafx.h"
 #include "scumm.h"
 #include "actor.h"
+#include "boxes.h"
 #include "common/util.h"
 
 #include <math.h>
@@ -382,13 +383,13 @@
 
 	diffx = abs(ptx - x);
 
-	if (diffx >= 0x100)
-		return 0xFFFF;
+	if (diffx >= 0x1000)
+		return 0xFFFFFF;
 
 	diffy = abs(pty - y);
 
-	if (diffy >= 0x100)
-		return 0xFFFF;
+	if (diffy >= 0x1000)
+		return 0xFFFFFF;
 	diffx *= diffx;
 	diffy *= diffy;
 	return diffx + diffy;
@@ -484,33 +485,29 @@
 
 	getBoxCoordinates(b, &box);
 
-	if (threshold == 0)
-		return true;
-
 	t = x - threshold;
 	if (t > box.ul.x && t > box.ur.x && t > box.lr.x && t > box.ll.x)
-		return false;
+		return true;
 
 	t = x + threshold;
 	if (t < box.ul.x && t < box.ur.x && t < box.lr.x && t < box.ll.x)
-		return false;
+		return true;
 
 	t = y - threshold;
 	if (t > box.ul.y && t > box.ur.y && t > box.lr.y && t > box.ll.y)
-		return false;
+		return true;
 
 	t = y + threshold;
 	if (t < box.ul.y && t < box.ur.y && t < box.lr.y && t < box.ll.y)
-		return false;
+		return true;
 
-	return true;
+	return false;
 }
 
-AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
+int Scumm::getClosestPtOnBox(int b, int x, int y, int16& outX, int16& outY) {
 	ScummVM::Point pt;
-	AdjustBoxResult best;
 	uint dist;
-	uint bestdist = (uint)0xFFFF;
+	uint bestdist = 0xFFFFFF;
 	BoxCoords box;
 
 	getBoxCoordinates(b, &box);
@@ -519,36 +516,35 @@
 	dist = distanceFromPt(x, y, pt.x, pt.y);
 	if (dist < bestdist) {
 		bestdist = dist;
-		best.x = pt.x;
-		best.y = pt.y;
+		outX = pt.x;
+		outY = pt.y;
 	}
 
 	pt = closestPtOnLine(box.ur.x, box.ur.y, box.lr.x, box.lr.y, x, y);
 	dist = distanceFromPt(x, y, pt.x, pt.y);
 	if (dist < bestdist) {
 		bestdist = dist;
-		best.x = pt.x;
-		best.y = pt.y;
+		outX = pt.x;
+		outY = pt.y;
 	}
 
 	pt = closestPtOnLine(box.lr.x, box.lr.y, box.ll.x, box.ll.y, x, y);
 	dist = distanceFromPt(x, y, pt.x, pt.y);
 	if (dist < bestdist) {
 		bestdist = dist;
-		best.x = pt.x;
-		best.y = pt.y;
+		outX = pt.x;
+		outY = pt.y;
 	}
 
 	pt = closestPtOnLine(box.ll.x, box.ll.y, box.ul.x, box.ul.y, x, y);
 	dist = distanceFromPt(x, y, pt.x, pt.y);
 	if (dist < bestdist) {
 		bestdist = dist;
-		best.x = pt.x;
-		best.y = pt.y;
+		outX = pt.x;
+		outY = pt.y;
 	}
 
-	best.dist = bestdist;
-	return best;
+	return bestdist;
 }
 
 byte *Scumm::getBoxMatrixBaseAddr() {
@@ -1036,10 +1032,9 @@
 	BoxCoords coords;
 	ScummVM::Point Clo[8];
 	ScummVM::Point poly[8];
-	AdjustBoxResult abr;
 	int line1, line2;
 
-	// For all corner coordinates of the first box, compute the point cloest 
+	// For all corner coordinates of the first box, compute the point closest 
 	// to them on the second box (and also compute the distance of these points).
 	getBoxCoordinates(trap1, &coords);
 	poly[0] = coords.ul;
@@ -1047,10 +1042,7 @@
 	poly[2] = coords.lr;
 	poly[3] = coords.ll;
 	for (i = 0; i < 4; i++) {
-		abr = getClosestPtOnBox(trap2, poly[i].x, poly[i].y);
-		dist[i] = abr.dist;
-		Clo[i].x = abr.x;
-		Clo[i].y = abr.y;
+		dist[i] = getClosestPtOnBox(trap2, poly[i].x, poly[i].y, Clo[i].x, Clo[i].y);
 	}
 
 	// Now do the same but with the roles of the first and second box swapped.
@@ -1060,10 +1052,7 @@
 	poly[6] = coords.lr;
 	poly[7] = coords.ll;
 	for (i = 4; i < 8; i++) {
-		abr = getClosestPtOnBox(trap1, poly[i].x, poly[i].y);
-		dist[i] = abr.dist;
-		Clo[i].x = abr.x;
-		Clo[i].y = abr.y;
+		dist[i] = getClosestPtOnBox(trap1, poly[i].x, poly[i].y, Clo[i].x, Clo[i].y);
 	}
 
 	// Find the three closest "close" points between the two boxes.
@@ -1077,7 +1066,7 @@
 		}
 		dist[closest[j]] = 0xFFFF;
 		minDist[j] = (int)sqrt((double)minDist[j]);
-		box[j] = (closest[j] > 3);	// Is the poin on the first or on the second box?
+		box[j] = (closest[j] > 3);	// Is the point on the first or on the second box?
 	}
 
 
@@ -1117,7 +1106,6 @@
 	if (line1 < 4) {							/* from box 1 to box 2 */
 		gateA[0] = poly[line1];
 		gateA[1] = Clo[line1];
-
 	} else {
 		gateA[1] = poly[line1];
 		gateA[0] = Clo[line1];
@@ -1126,7 +1114,6 @@
 	if (line2 < 4) {							/* from box */
 		gateB[0] = poly[line2];
 		gateB[1] = Clo[line2];
-
 	} else {
 		gateB[1] = poly[line2];
 		gateB[0] = Clo[line2];

Index: boxes.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/boxes.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- boxes.h	15 May 2003 21:57:38 -0000	1.5
+++ boxes.h	2 Jul 2003 13:47:03 -0000	1.6
@@ -38,20 +38,11 @@
 	kBoxInvisible	= 0x80
 } BoxFlags;
 
-struct AdjustBoxResult {	/* Result type of AdjustBox functions */
-	int16 x, y;
-	uint16 dist;
-};
-
 struct BoxCoords {			/* Box coordinates */
 	ScummVM::Point ul;
 	ScummVM::Point ur;
 	ScummVM::Point ll;
 	ScummVM::Point lr;
 };
-
-struct Box;
-struct PathNode;
-struct PathVertex;
 
 #endif

Index: debugger.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/debugger.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- debugger.cpp	1 Jul 2003 04:20:41 -0000	1.62
+++ debugger.cpp	2 Jul 2003 13:47:03 -0000	1.63
@@ -22,6 +22,7 @@
 #include "scumm.h"
 #include "sound.h"
 #include "actor.h"
+#include "boxes.h"
 #include "imuse.h"
 #include "debugger.h"
 #include "common/util.h"

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.262
retrieving revision 1.263
diff -u -d -r1.262 -r1.263
--- scumm.h	26 Jun 2003 22:50:01 -0000	1.262
+++ scumm.h	2 Jul 2003 13:47:03 -0000	1.263
@@ -30,7 +30,6 @@
 #include "common/str.h"
 
 #include "gfx.h"
-#include "boxes.h"
 
 class Actor;
 class BaseCostumeRenderer;
@@ -46,6 +45,9 @@
 class ScummDebugger;
 class Serializer;
 class Sound;
+
+struct Box;
+struct BoxCoords;
 struct FindObjectInRoom;
 
 typedef ScummVM::Map<ScummVM::String, int> ObjectIDMap;
@@ -1012,7 +1014,7 @@
 	int getPathToDestBox(byte from, byte to);
 	void getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Point gateB[2]);
 	bool inBoxQuickReject(int box, int x, int y, int threshold);
-	AdjustBoxResult getClosestPtOnBox(int box, int x, int y);
+	int getClosestPtOnBox(int box, int x, int y, int16& outX, int16& outY);
 	int getSpecialBox(int param1, int param2);
 	
 	void setBoxFlags(int box, int val);

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scummvm.cpp,v
retrieving revision 2.259
retrieving revision 2.260
diff -u -d -r2.259 -r2.260
--- scummvm.cpp	2 Jul 2003 00:46:32 -0000	2.259
+++ scummvm.cpp	2 Jul 2003 13:47:03 -0000	2.260
@@ -23,6 +23,7 @@
 #include "stdafx.h"
 #include "scumm.h"
 #include "actor.h"
+#include "boxes.h"
 #include "charset.h"
 #include "debugger.h"
 #include "dialogs.h"





More information about the Scummvm-git-logs mailing list