[Scummvm-cvs-logs] CVS: scummvm/saga actor.cpp,1.77,1.78 actor.h,1.40,1.41

Andrew Kurushin h00ligan at users.sourceforge.net
Thu Jan 6 14:23:21 CET 2005


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31902

Modified Files:
	actor.cpp actor.h 
Log Message:
small fixes to previous

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.cpp,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- actor.cpp	6 Jan 2005 21:57:10 -0000	1.77
+++ actor.cpp	6 Jan 2005 22:22:19 -0000	1.78
@@ -153,7 +153,7 @@
 	_yCellCount = _vm->getStatusYOffset() + 1;
 	_xCellCount = _vm->getDisplayWidth();
 
-	_pathCell = (int*) malloc(_yCellCount * _xCellCount * sizeof(*_pathCell));
+	_pathCell = (int8*) malloc(_yCellCount * _xCellCount * sizeof(*_pathCell));
 	
 
 	_pathRect.left = 0;
@@ -1353,7 +1353,6 @@
 	Point iteratorPoint;
 	Point bestPoint;
 	int maskType;
-	int cellValue;
 	int i;
 	Rect intersect;
 	
@@ -1368,8 +1367,7 @@
 	for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) {
 		for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) {
 			maskType = _vm->_scene->getBGMaskType(iteratorPoint);
-			cellValue = maskType ? kPathCellBarrier : kPathCellEmpty;
-			setPathCell(iteratorPoint, cellValue);			
+			setPathCell(iteratorPoint,  maskType ? kPathCellBarrier : kPathCellEmpty);			
 		}
 	}
 
@@ -1407,29 +1405,6 @@
 
 	i = fillPathArray(fromPoint, toPoint, bestPoint);
 
-#if 0
-	{
-		Point iteratorPoint;
-		int cellValue;
-		FILE	*fp =	fopen("d:\\FINDPATH.DAT", "w");
-		char	c;
-
-		fprintf(fp, "from = (%d,%d)\n", fromPoint.x, fromPoint.y);
-		fprintf(fp, "to = (%d,%d)\n", toPoint.x, toPoint.y);
-		fprintf(fp, "bestPoint = (%d,%d)\n", bestPoint.x, bestPoint.y);
-
-		for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) {
-			for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) {
-				cellValue = getPathCell(iteratorPoint);
-				c = (cellValue < 0) ? ' ' : (cellValue == kPathCellBarrier) ? kPathCellBarrier : (cellValue < 8) ? "^>v<?jLP"[cellValue] : '.';
-				putc(c, fp);
-			}
-			putc('\n', fp);
-		}
-		fclose(fp);
-	}
-#endif
-
 	if (fromPoint == bestPoint) {
 		actor->addWalkStepPoint(bestPoint);
 		return;
@@ -1506,6 +1481,7 @@
 	PathDirectionData *samplePathDirection;
 	PathDirectionList::iterator pathDirectionIterator;
 	PathDirectionList::iterator newPathDirectionIterator;
+	Point nextPoint;
 	int directionCount;
 
 	pointCounter = 0;
@@ -1521,7 +1497,7 @@
 	}
 
 	if (validPathCellPoint(fromPoint)) {
-		setPathCell(fromPoint, 0);
+		setPathCell(fromPoint, kDirUp);
 		
 		addDebugPoint(fromPoint, 24+36);
 	}	
@@ -1532,29 +1508,34 @@
 		pathDirection = pathDirectionIterator.operator->();
 		for (directionCount = 0; directionCount < 3; directionCount++) {
 			samplePathDirection = &pathDirectionLUT[pathDirection->direction][directionCount];
-			Point nextPoint;
 			nextPoint.x = samplePathDirection->x + pathDirection->x;
 			nextPoint.y = samplePathDirection->y + pathDirection->y;
-			if (validPathCellPoint(nextPoint) && 
-				(getPathCell(nextPoint) == kPathCellEmpty)) {
-				setPathCell(nextPoint, samplePathDirection->direction);
-				
-				addDebugPoint(nextPoint, samplePathDirection->direction + 96);
-				newPathDirectionIterator = pathDirectionList.pushBack();
-				pathDirection = newPathDirectionIterator.operator->();
-				pathDirection->x = nextPoint.x;
-				pathDirection->y = nextPoint.y;
-				pathDirection->direction = samplePathDirection->direction;
-				++pointCounter;
-				if (nextPoint == toPoint) {
-					bestPoint = toPoint;
-					return pointCounter;
-				}
-				currentRating = quickDistance(nextPoint, toPoint);
-				if (currentRating  < bestRating) {
-					bestRating = currentRating;
-					bestPath = nextPoint;
-				}
+			
+			if (!validPathCellPoint(nextPoint)) {
+				continue; 
+			}
+
+			if (getPathCell(nextPoint) != kPathCellEmpty) {
+				continue;
+			}
+
+			setPathCell(nextPoint, samplePathDirection->direction);
+
+			addDebugPoint(nextPoint, samplePathDirection->direction + 96);
+			newPathDirectionIterator = pathDirectionList.pushBack();
+			pathDirection = newPathDirectionIterator.operator->();
+			pathDirection->x = nextPoint.x;
+			pathDirection->y = nextPoint.y;
+			pathDirection->direction = samplePathDirection->direction;
+			++pointCounter;
+			if (nextPoint == toPoint) {
+				bestPoint = toPoint;
+				return pointCounter;
+			}
+			currentRating = quickDistance(nextPoint, toPoint);
+			if (currentRating  < bestRating) {
+				bestRating = currentRating;
+				bestPath = nextPoint;
 			}
 		}
 		++pathDirectionIterator;
@@ -1566,7 +1547,7 @@
 
 void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point &toPoint) {
 	Point nextPoint;
-	int direction;
+	int8 direction;
 	int i;
 
 	_pathListIndex = -1;
@@ -1575,7 +1556,7 @@
 
 	while ( !(nextPoint == fromPoint)) {
 		direction = getPathCell(nextPoint);
-		if ((direction < 0) || (direction > 8)) {
+		if ((direction < 0) || (direction >= 8)) {
 			error("Actor::setActorPath error direction 0x%X", direction);
 		}
 		nextPoint.x -= pathDirectionLUT2[direction][0];

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- actor.h	6 Jan 2005 21:57:10 -0000	1.40
+++ actor.h	6 Jan 2005 22:22:20 -0000	1.41
@@ -115,11 +115,12 @@
 
 enum PathCellType {
 	kPathCellEmpty = -1,
+	//kDirUp = 0 .... kDirUpLeft = 7 
 	kPathCellBarrier = 0x57
 };
 
 struct PathDirectionData {
-	int direction;
+	int8 direction;
 	int	x;
 	int y;
 };
@@ -319,13 +320,13 @@
 		return !((testPoint.x < 0) || (testPoint.x >= _xCellCount) ||
 			(testPoint.y < 0) || (testPoint.y >= _yCellCount));
 	}
-	void setPathCell(const Point &testPoint, int value) {		
+	void setPathCell(const Point &testPoint, int8 value) {		
 		if (!validPathCellPoint(testPoint)) {
 			error("Actor::setPathCell wrong point");
 		}
 		_pathCell[testPoint.x + testPoint.y * _xCellCount] = value;
 	}
-	int getPathCell(const Point &testPoint) {
+	int8 getPathCell(const Point &testPoint) {
 		if (!validPathCellPoint(testPoint)) {
 			error("Actor::getPathCell wrong point");
 		}
@@ -351,7 +352,7 @@
 //path stuff
 	Rect _barrierList[ACTOR_BARRIERS_MAX];
 	int _barrierCount;
-	int *_pathCell;
+	int8 *_pathCell;
 
 	int _xCellCount;
 	int _yCellCount;





More information about the Scummvm-git-logs mailing list