[Scummvm-cvs-logs] CVS: scummvm/scumm boxes.cpp,1.2,1.3 scumm.h,1.120,1.121

Max Horn fingolfin at users.sourceforge.net
Sun Dec 29 13:15:02 CET 2002


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

Modified Files:
	boxes.cpp scumm.h 
Log Message:
cleanup

Index: boxes.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/boxes.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- boxes.cpp	8 Sep 2002 01:08:12 -0000	1.2
+++ boxes.cpp	29 Dec 2002 21:14:27 -0000	1.3
@@ -419,7 +419,7 @@
 	}
 
 	while (boxm[0] != 0xFF) {
-		if (boxm[0] <= to && boxm[1] >= to)
+		if (boxm[0] <= to && to <= boxm[1])
 			dest = boxm[2];
 		boxm += 3;
 	}
@@ -566,32 +566,32 @@
 
 void Scumm::createBoxMatrix()
 {
-	byte *matrix_ptr;
 	int num, i, j;
 	byte flags;
 	int table_1[66], table_2[66];
 	int counter, val;
 	int code;
 
-	PathVertex *vtx;
-	PathNode *node, *node2 = NULL;
 
+	// A heap (an optiimsation to avoid calling malloc/free extremly often)
 	_maxBoxVertexHeap = 1000;
-
-	createResource(rtMatrix, 4, 1000);
-	createResource(rtMatrix, 3, 4160);	//65 items of something of size 64
+	createResource(rtMatrix, 4, _maxBoxVertexHeap);
+	_boxPathVertexHeap = getResourceAddress(rtMatrix, 4);
+	_boxPathVertexHeapIndex = 1;
+	
+	// Temporary 64*65 distance matrix
+	createResource(rtMatrix, 3, 65 * 64);
+	_boxMatrixPtr3 = getResourceAddress(rtMatrix, 3);
+	
+	// The result "matrix" in the special format used by Scumm.
 	createResource(rtMatrix, 1, BOX_MATRIX_SIZE);
-
-	matrix_ptr = getResourceAddress(rtMatrix, 1);
-
-	_boxMatrixPtr4 = getResourceAddress(rtMatrix, 4);
 	_boxMatrixPtr1 = getResourceAddress(rtMatrix, 1);
-	_boxMatrixPtr3 = getResourceAddress(rtMatrix, 3);
-
-	_boxPathVertexHeapIndex = _boxMatrixItem = 0;
 
 	num = getNumBoxes();
 
+	// Initialise the distance matrix: each box has distance 0 to itself,
+	// and distance 1 to its direct neighbors. Initially, it has distance
+	// 250 (= infinity) to all other boxes.
 	for (i = 0; i < num; i++) {
 		for (j = 0; j < num; j++) {
 			if (i == j) {
@@ -604,15 +604,18 @@
 		}
 	}
 
+	// Iterate over all boxes
 	for (j = 0; j < num; j++) {
 		flags = getBoxFlags(j);
 		if (flags & kBoxInvisible) {
+			// Locked/invisible boxes are only reachable from themselves.
 			addToBoxMatrix(0xFF);
 			addToBoxMatrix(j);
 			addToBoxMatrix(j);
 			addToBoxMatrix(j);
 		} else {
-			vtx = addPathVertex();
+			PathNode *node, *node2 = NULL;
+			PathVertex *vtx = addPathVertex();
 			for (i = 0; i < num; i++) {
 				flags = getBoxFlags(j);
 				if (!(flags & kBoxInvisible)) {
@@ -666,27 +669,23 @@
 			}
 
 			addToBoxMatrix(0xFF);
-			for (i = 1; i < num;) {
+			for (i = 1; i < num; i++) {
 				if (table_2[i - 1] != -1) {
 					addToBoxMatrix(i - 1);	/* lo */
-					if (table_2[i - 1] != table_2[i]) {
-						addToBoxMatrix(i - 1);	/* hi */
-						addToBoxMatrix(table_2[i - 1]);	/* dst */
-					} else {
-						while (table_2[i - 1] == table_2[i]) {
-							if (++i == num)
-								break;
-						}
-						addToBoxMatrix(i - 1);	/* hi */
-						addToBoxMatrix(table_2[i - 1]);	/* dst */
+					while (table_2[i - 1] == table_2[i]) {
+						++i;
+						if (i == num)
+							break;
 					}
-				}
-				if (++i == num && table_2[i - 1] != -1) {
-					addToBoxMatrix(i - 1);	/* lo */
 					addToBoxMatrix(i - 1);	/* hi */
-					addToBoxMatrix(table_2[i - 1]);	/* dest */
+					addToBoxMatrix(table_2[i - 1]);	/* dst */
 				}
 			}
+			if (i == num && table_2[i - 1] != -1) {
+				addToBoxMatrix(i - 1);	/* lo */
+				addToBoxMatrix(i - 1);	/* hi */
+				addToBoxMatrix(table_2[i - 1]);	/* dest */
+			}
 		}
 	}
 
@@ -725,27 +724,24 @@
 	if (vtx == NULL)
 		return NULL;
 
-	if (!vtx->right) {
-		node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode));
-		vtx->left = vtx->right = node;
+	node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode));
+	node->index = i;
+	node->left = 0;
+	node->right = 0;
 
-		node->index = i;
-		node->left = 0;
-		node->right = 0;
+	if (!vtx->right) {
+		vtx->left = node;
 	} else {
-		node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode));
 		vtx->right->left = node;
-
 		node->right = vtx->right;
-		node->index = i;
-		node->left = 0;
-
-		vtx->right = node;
 	}
 
+	vtx->right = node;
+
 	return vtx->right;
 }
 
+
 /* Check if two boxes are neighbours */
 bool Scumm::areBoxesNeighbours(int box1nr, int box2nr)
 {
@@ -866,9 +862,9 @@
 
 void *Scumm::addToBoxVertexHeap(int size)
 {
-	byte *ptr = _boxMatrixPtr4;
+	byte *ptr = _boxPathVertexHeap;
 
-	_boxMatrixPtr4 += size;
+	_boxPathVertexHeap += size;
 	_boxPathVertexHeapIndex += size;
 
 	if (_boxPathVertexHeapIndex >= _maxBoxVertexHeap)
@@ -879,7 +875,7 @@
 
 PathVertex *Scumm::addPathVertex()
 {
-	_boxMatrixPtr4 = getResourceAddress(rtMatrix, 4);
+	_boxPathVertexHeap = getResourceAddress(rtMatrix, 4);
 	_boxPathVertexHeapIndex = 0;
 
 	return (PathVertex *)addToBoxVertexHeap(sizeof(PathVertex));

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- scumm.h	29 Dec 2002 19:54:11 -0000	1.120
+++ scumm.h	29 Dec 2002 21:14:28 -0000	1.121
@@ -846,7 +846,7 @@
 
 	/* Walkbox / Navigation class */
 	int _maxBoxVertexHeap, _boxPathVertexHeapIndex, _boxMatrixItem;
-	byte *_boxMatrixPtr4, *_boxMatrixPtr1, *_boxMatrixPtr3;	
+	byte *_boxPathVertexHeap, *_boxMatrixPtr1, *_boxMatrixPtr3;	
 
 	uint16 _extraBoxFlags[65];
 





More information about the Scummvm-git-logs mailing list