[Scummvm-cvs-logs] CVS: scummvm/saga actor.cpp,1.92,1.93 actor.h,1.48,1.49

Andrew Kurushin h00ligan at users.sourceforge.net
Sun Jan 16 12:32:03 CET 2005


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

Modified Files:
	actor.cpp actor.h 
Log Message:
-small pathfind fix
-pathfind speedup 

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.cpp,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- actor.cpp	16 Jan 2005 19:05:49 -0000	1.92
+++ actor.cpp	16 Jan 2005 20:30:57 -0000	1.93
@@ -150,8 +150,11 @@
 
 	_pathNodeList = _newPathNodeList = NULL;
 	_pathList = NULL;
+	_pathDirectionList = NULL;
 	_pathListAlloced = _pathNodeListAlloced = _newPathNodeListAlloced = 0;
 	_pathListIndex = _pathNodeListIndex = _newPathNodeListIndex = -1;
+	_pathDirectionListCount = 0;
+	_pathDirectionListAlloced = 0;
 		
 
 	_centerActor = _protagonist = NULL;
@@ -226,7 +229,7 @@
 #ifdef ACTOR_DEBUG
 	free(_debugPoints);
 #endif
-
+	free(_pathDirectionList);
 	free(_pathNodeList);
 	free(_newPathNodeList);
 	free(_pathList);
@@ -1248,6 +1251,7 @@
 	Point collision;
 	Point pointFrom, pointTo, pointBest, pointAdd;
 	Point delta, bestDelta;
+	Point tempPoint;
 	bool extraStartNode;
 	bool extraEndNode;
 
@@ -1366,7 +1370,6 @@
 			}
 
 			if (extraEndNode) {
-				Point tempPoint;
 				toLocation.toScreenPointXY(tempPoint);
 				actor->walkStepsCount--;
 				actor->addWalkStepPoint(tempPoint);
@@ -1622,27 +1625,26 @@
 int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &bestPoint) {
 	int bestRating;
 	int currentRating;
+	int i;
 	Point bestPath;
 	int pointCounter;
-	int startDirection;
-	PathDirectionList pathDirectionList;
+	int startDirection;	
 	PathDirectionData *pathDirection;
+	PathDirectionData *newPathDirection;
 	PathDirectionData *samplePathDirection;
-	PathDirectionList::iterator pathDirectionIterator;
-	PathDirectionList::iterator newPathDirectionIterator;
 	Point nextPoint;
 	int directionCount;
 
+	_pathDirectionListCount = 0;
 	pointCounter = 0;
 	bestRating = quickDistance(fromPoint, toPoint);
 	bestPath = fromPoint;
 	
 	for (startDirection = 0; startDirection < 4; startDirection++) {
-		newPathDirectionIterator = pathDirectionList.pushBack();
-		pathDirection = newPathDirectionIterator.operator->();
-		pathDirection->x = fromPoint.x;
-		pathDirection->y = fromPoint.y;
-		pathDirection->direction = startDirection;
+		newPathDirection = addPathDirectionListData();
+		newPathDirection->x = fromPoint.x;
+		newPathDirection->y = fromPoint.y;
+		newPathDirection->direction = startDirection;
 	}
 
 	if (validPathCellPoint(fromPoint)) {
@@ -1653,10 +1655,11 @@
 #endif
 	}	
 	
-	pathDirectionIterator = pathDirectionList.begin();
+	
+	i = 0;
 
 	do {
-		pathDirection = pathDirectionIterator.operator->();
+		pathDirection = &_pathDirectionList[i];
 		for (directionCount = 0; directionCount < 3; directionCount++) {
 			samplePathDirection = &pathDirectionLUT[pathDirection->direction][directionCount];
 			nextPoint.x = samplePathDirection->x + pathDirection->x;
@@ -1675,11 +1678,10 @@
 #ifdef ACTOR_DEBUG
 			addDebugPoint(nextPoint, samplePathDirection->direction + 96);
 #endif
-			newPathDirectionIterator = pathDirectionList.pushBack();
-			pathDirection = newPathDirectionIterator.operator->();
-			pathDirection->x = nextPoint.x;
-			pathDirection->y = nextPoint.y;
-			pathDirection->direction = samplePathDirection->direction;
+			newPathDirection = addPathDirectionListData();
+			newPathDirection->x = nextPoint.x;
+			newPathDirection->y = nextPoint.y;
+			newPathDirection->direction = samplePathDirection->direction;
 			++pointCounter;
 			if (nextPoint == toPoint) {
 				bestPoint = toPoint;
@@ -1690,11 +1692,12 @@
 				bestRating = currentRating;
 				bestPath = nextPoint;
 			}
+			pathDirection = &_pathDirectionList[i];
 		}
-		++pathDirectionIterator;
-	} while (pathDirectionIterator != pathDirectionList.end());
+		++i;
+	} while (i < _pathDirectionListCount);
 
-	bestPoint = bestPath;	
+	bestPoint = bestPath;
 	return pointCounter;
 }
 

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- actor.h	15 Jan 2005 23:46:42 -0000	1.48
+++ actor.h	16 Jan 2005 20:30:57 -0000	1.49
@@ -116,12 +116,10 @@
 
 struct PathDirectionData {
 	int8 direction;
-	int	x;
-	int y;
+	int16	x;
+	int16 y;
 };
 
-typedef SortedList<PathDirectionData> PathDirectionList;
-
 struct PathNode {
 	Point point;
 	int link;
@@ -367,6 +365,17 @@
 	int _yCellCount;
 	Rect _pathRect;
 
+	PathDirectionData *_pathDirectionList;
+	int _pathDirectionListCount;
+	int _pathDirectionListAlloced;
+	PathDirectionData * addPathDirectionListData() {
+		if (_pathDirectionListCount + 1 >= _pathDirectionListAlloced) {
+			_pathDirectionListAlloced += 100;
+			_pathDirectionList = (PathDirectionData*) realloc(_pathDirectionList, _pathDirectionListAlloced * sizeof(*_pathDirectionList));
+		}
+		return &_pathDirectionList[_pathDirectionListCount++];
+	}
+
 	Point *_pathList;
 	int _pathListIndex;
 	int _pathListAlloced;





More information about the Scummvm-git-logs mailing list