[Scummvm-cvs-logs] SF.net SVN: scummvm:[40232] scummvm/trunk/engines/saga

h00ligan at users.sourceforge.net h00ligan at users.sourceforge.net
Fri May 1 17:32:15 CEST 2009


Revision: 40232
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40232&view=rev
Author:   h00ligan
Date:     2009-05-01 15:32:15 +0000 (Fri, 01 May 2009)

Log Message:
-----------
SAGA: move Actor::_pathList into a Common::Array<Point>

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/actor.h
    scummvm/trunk/engines/saga/actor_path.cpp
    scummvm/trunk/engines/saga/puzzle.cpp
    scummvm/trunk/engines/saga/saga.h

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2009-05-01 14:31:59 UTC (rev 40231)
+++ scummvm/trunk/engines/saga/actor.cpp	2009-05-01 15:32:15 UTC (rev 40232)
@@ -232,9 +232,8 @@
 	_protagStates = NULL;
 	_protagStatesCount = 0;
 
-	_pathList = NULL;
-	_pathListAlloced = 0;
-	_pathListIndex = -1;
+	_pathList.resize(600);
+	_pathListIndex = 0;
 
 	_centerActor = _protagonist = NULL;
 	_protagState = 0;
@@ -320,7 +319,6 @@
 Actor::~Actor() {
 	debug(9, "Actor::~Actor()");
 
-	free(_pathList);
 	free(_pathCell);
 	_actorsStrings.freeMem();
 	//release resources

Modified: scummvm/trunk/engines/saga/actor.h
===================================================================
--- scummvm/trunk/engines/saga/actor.h	2009-05-01 14:31:59 UTC (rev 40231)
+++ scummvm/trunk/engines/saga/actor.h	2009-05-01 15:32:15 UTC (rev 40232)
@@ -196,7 +196,7 @@
 	ActorFrameRange directions[ACTOR_DIRECTIONS_COUNT];
 };
 
-int pathLine(Point *pointList, const Point &point1, const Point &point2);
+uint pathLine(PointList &pointList, uint idx, const Point &point1, const Point &point2);
 
 struct Location {
 	int32 x;					// logical coordinates
@@ -635,19 +635,9 @@
 	int _yCellCount;
 	Rect _pathRect;
 
-	Point *_pathList;
-	int _pathListIndex;
-	int _pathListAlloced;
-	void addPathListPoint(const Point &point) {
-		++_pathListIndex;
-		if (_pathListIndex >= _pathListAlloced) {
-			_pathListAlloced += 100;
-			_pathList = (Point*) realloc(_pathList, _pathListAlloced * sizeof(*_pathList));
+	PointList _pathList;
+	uint _pathListIndex;
 
-		}
-		_pathList[_pathListIndex] = point;
-	}
-
 	PathNodeList _pathNodeList;
 
 public:

Modified: scummvm/trunk/engines/saga/actor_path.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor_path.cpp	2009-05-01 14:31:59 UTC (rev 40231)
+++ scummvm/trunk/engines/saga/actor_path.cpp	2009-05-01 15:32:15 UTC (rev 40232)
@@ -296,10 +296,10 @@
 	Point nextPoint;
 	int8 direction;
 
-	_pathListIndex = -1;
-	addPathListPoint(toPoint);
+	_pathList[0] = toPoint;
 	nextPoint = toPoint;
 
+	_pathListIndex = 0;
 	while (!(nextPoint == fromPoint)) {
 		direction = getPathCell(nextPoint);
 		if ((direction < 0) || (direction >= 8)) {
@@ -307,7 +307,12 @@
 		}
 		nextPoint.x -= pathDirectionLUT2[direction][0];
 		nextPoint.y -= pathDirectionLUT2[direction][1];
-		addPathListPoint(nextPoint);
+		++_pathListIndex;
+		if (_pathListIndex >= _pathList.size()) {
+			_pathList.push_back(nextPoint);
+		} else {
+			_pathList[_pathListIndex] = nextPoint;
+		}
 
 #ifdef ACTOR_DEBUG
 		addDebugPoint(nextPoint, 0x8a);
@@ -328,18 +333,15 @@
 	Point point1, point2, delta;
 	int direction;
 	int i;
-	Point *point;
 
-	point= &_pathList[_pathListIndex];
 	direction = 0;
 
 	_pathNodeList.clear();
-	_pathNodeList.push_back(PathNode(*point));
+	_pathNodeList.push_back(PathNode(_pathList[_pathListIndex]));
 
 	for (i = _pathListIndex; i > 0; i--) {
-		point1 = *point;
-		--point;
-		point2 = *point;
+		point1 = _pathList[i];
+		point2 = _pathList[i - 1];
 		if (direction == 0) {
 			delta.x = int16Compare(point2.x, point1.x);
 			delta.y = int16Compare(point2.y, point1.y);
@@ -349,19 +351,18 @@
 			_pathNodeList.push_back(PathNode(point1));
 			direction--;
 			i++;
-			point++;
 		}
 	}
-	_pathNodeList.push_back(PathNode(*_pathList));
+	_pathNodeList.push_back(PathNode(_pathList[0]));
 }
 
-int pathLine(Point *pointList, const Point &point1, const Point &point2) {
+uint pathLine(PointList &pointList, uint idx, const Point &point1, const Point &point2) {
 	Point point;
 	Point delta;
 	Point tempPoint;
 	Point s;
 	int16 errterm;
-	int16 res;
+	uint res;
 
 	calcDeltaS(point1, point2, delta, s);
 
@@ -384,8 +385,12 @@
 			point.y += s.y;
 			errterm += tempPoint.x;
 
-			*pointList = point;
-			pointList++;
+			if (idx >= pointList.size()) {
+				pointList.push_back(point);
+			} else {
+				pointList[idx] = point;
+			}
+			++idx;
 			delta.y--;
 		}
 	} else {
@@ -402,8 +407,12 @@
 			point.x += s.x;
 			errterm += tempPoint.y;
 
-			*pointList = point;
-			pointList++;
+			if (idx >= pointList.size()) {
+				pointList.push_back(point);
+			} else {
+				pointList[idx] = point;
+			}
+			++idx;
 			delta.x--;
 		}
 	}
@@ -412,12 +421,10 @@
 
 void Actor::nodeToPath() {
 	uint i;
-	int j;
 	Point point1, point2;
-	Point *point;
 
-	for (j = 0, point = _pathList; j < _pathListAlloced; j++, point++) {
-		point->x = point->y = PATH_NODE_EMPTY;
+	for (i = 0; i < _pathList.size(); i++) {
+		_pathList[i].x = _pathList[i].y = PATH_NODE_EMPTY;
 	}
 
 	_pathListIndex = 1;
@@ -426,7 +433,7 @@
 	for (i = 0; i < _pathNodeList.size() - 1; i++) {
 		point1 = _pathNodeList[i].point;
 		point2 = _pathNodeList[i + 1].point;
-		_pathListIndex += pathLine(&_pathList[_pathListIndex], point1, point2);
+		_pathListIndex += pathLine(_pathList, _pathListIndex, point1, point2);
 		_pathNodeList[i + 1].link = _pathListIndex - 1;
 	}
 	_pathListIndex--;
@@ -549,7 +556,7 @@
 			start = _pathNodeList[i].link - j;
 			end = _pathNodeList[i].link + j;
 
-			if (start < 0 || end > _pathListIndex) {
+			if (start < 0 || end > (int)_pathListIndex) {
 				continue;
 			}
 

Modified: scummvm/trunk/engines/saga/puzzle.cpp
===================================================================
--- scummvm/trunk/engines/saga/puzzle.cpp	2009-05-01 14:31:59 UTC (rev 40231)
+++ scummvm/trunk/engines/saga/puzzle.cpp	2009-05-01 15:32:15 UTC (rev 40232)
@@ -295,12 +295,13 @@
 
 void Puzzle::slidePiece(int x1, int y1, int x2, int y2) {
 	int count;
-	Point slidePoints[320];
+	PointList slidePoints;
+	slidePoints.resize(320);
 
 	x1 += _pieceInfo[_puzzlePiece].offX;
 	y1 += _pieceInfo[_puzzlePiece].offY;
 
-	count = pathLine(&slidePoints[0], Point(x1, y1),
+	count = pathLine(slidePoints, 0, Point(x1, y1),
 		 Point(x2 + _pieceInfo[_puzzlePiece].offX, y2 + _pieceInfo[_puzzlePiece].offY));
 
 	if (count > 1) {

Modified: scummvm/trunk/engines/saga/saga.h
===================================================================
--- scummvm/trunk/engines/saga/saga.h	2009-05-01 14:31:59 UTC (rev 40231)
+++ scummvm/trunk/engines/saga/saga.h	2009-05-01 15:32:15 UTC (rev 40232)
@@ -384,8 +384,8 @@
 	}
 };
 
+typedef Common::Array<Point> PointList;
 
-
 enum ColorId {
 	kITEColorTransBlack = 0x00,
 	kITEColorBrightWhite = 0x01,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list