aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kurushin2009-05-01 15:32:15 +0000
committerAndrew Kurushin2009-05-01 15:32:15 +0000
commit52ccf2af949f217351da13e96fcb3314492fe4fc (patch)
tree9ee1f97c9a434c87d58812e3950251275878e440
parenta287eae15de6458350dfd32daeb519d7aed485a6 (diff)
downloadscummvm-rg350-52ccf2af949f217351da13e96fcb3314492fe4fc.tar.gz
scummvm-rg350-52ccf2af949f217351da13e96fcb3314492fe4fc.tar.bz2
scummvm-rg350-52ccf2af949f217351da13e96fcb3314492fe4fc.zip
SAGA: move Actor::_pathList into a Common::Array<Point>
svn-id: r40232
-rw-r--r--engines/saga/actor.cpp6
-rw-r--r--engines/saga/actor.h16
-rw-r--r--engines/saga/actor_path.cpp53
-rw-r--r--engines/saga/puzzle.cpp5
-rw-r--r--engines/saga/saga.h2
5 files changed, 39 insertions, 43 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index f0efc8e85d..fb1cb0b5c1 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -232,9 +232,8 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {
_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(SagaEngine *vm) : _vm(vm) {
Actor::~Actor() {
debug(9, "Actor::~Actor()");
- free(_pathList);
free(_pathCell);
_actorsStrings.freeMem();
//release resources
diff --git a/engines/saga/actor.h b/engines/saga/actor.h
index 01f0f8d775..d2ef43caf3 100644
--- a/engines/saga/actor.h
+++ b/engines/saga/actor.h
@@ -196,7 +196,7 @@ struct ActorFrameSequence {
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,18 +635,8 @@ private:
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));
-
- }
- _pathList[_pathListIndex] = point;
- }
+ PointList _pathList;
+ uint _pathListIndex;
PathNodeList _pathNodeList;
diff --git a/engines/saga/actor_path.cpp b/engines/saga/actor_path.cpp
index a0a80f7ada..992a52f881 100644
--- a/engines/saga/actor_path.cpp
+++ b/engines/saga/actor_path.cpp
@@ -296,10 +296,10 @@ void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point &
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 @@ void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point &
}
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 @@ void Actor::pathToNode() {
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 @@ void Actor::pathToNode() {
_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 @@ int pathLine(Point *pointList, const Point &point1, const Point &point2) {
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 @@ int pathLine(Point *pointList, const Point &point1, const Point &point2) {
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 @@ int pathLine(Point *pointList, const Point &point1, const Point &point2) {
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 @@ void Actor::nodeToPath() {
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 @@ void Actor::removePathPoints() {
start = _pathNodeList[i].link - j;
end = _pathNodeList[i].link + j;
- if (start < 0 || end > _pathListIndex) {
+ if (start < 0 || end > (int)_pathListIndex) {
continue;
}
diff --git a/engines/saga/puzzle.cpp b/engines/saga/puzzle.cpp
index 4107b4c8d9..74d7608d2b 100644
--- a/engines/saga/puzzle.cpp
+++ b/engines/saga/puzzle.cpp
@@ -295,12 +295,13 @@ void Puzzle::alterPiecePriority(void) {
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) {
diff --git a/engines/saga/saga.h b/engines/saga/saga.h
index d62b147f3d..27a1e2ae9b 100644
--- a/engines/saga/saga.h
+++ b/engines/saga/saga.h
@@ -384,7 +384,7 @@ struct StringsTable {
}
};
-
+typedef Common::Array<Point> PointList;
enum ColorId {
kITEColorTransBlack = 0x00,