aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorD G Turner2012-06-07 12:33:13 +0100
committerD G Turner2012-06-07 12:33:13 +0100
commit8deb8b3d42927d1d6e73350f96353eda1b10a1fc (patch)
tree67823ec49a9e0c4d3d2a66297f70b3a414724ae3 /engines
parentdd558510dc60b61d9f960c7f49e8bc0327d8115b (diff)
downloadscummvm-rg350-8deb8b3d42927d1d6e73350f96353eda1b10a1fc.tar.gz
scummvm-rg350-8deb8b3d42927d1d6e73350f96353eda1b10a1fc.tar.bz2
scummvm-rg350-8deb8b3d42927d1d6e73350f96353eda1b10a1fc.zip
TOON: Minor cleanup and formatting fixes to Pathfinding class.
Diffstat (limited to 'engines')
-rw-r--r--engines/toon/path.cpp51
-rw-r--r--engines/toon/path.h7
2 files changed, 27 insertions, 31 deletions
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 540290d823..101778d4b4 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -161,6 +161,18 @@ PathFinding::~PathFinding(void) {
delete[] _gridTemp;
}
+void PathFinding::init(Picture *mask) {
+ debugC(1, kDebugPath, "init(mask)");
+
+ _width = mask->getWidth();
+ _height = mask->getHeight();
+ _currentMask = mask;
+ _heap->unload();
+ _heap->init(500);
+ delete[] _gridTemp;
+ _gridTemp = new int32[_width * _height];
+}
+
bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
for (int32 i = 0; i < _numBlockingRects; i++) {
if (_blockingRects[i][4] == 0) {
@@ -180,12 +192,10 @@ bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
bool PathFinding::isWalkable(int32 x, int32 y) {
debugC(2, kDebugPath, "isWalkable(%d, %d)", x, y);
- bool maskWalk = (_currentMask->getData(x, y) & 0x1f) > 0;
-
- return maskWalk;
+ return (_currentMask->getData(x, y) & 0x1f) > 0;
}
-int32 PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX, int origY) {
+bool PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX, int origY) {
debugC(1, kDebugPath, "findClosestWalkingPoint(%d, %d, fxx, fyy, %d, %d)", xx, yy, origX, origY);
int32 currentFound = -1;
@@ -214,11 +224,11 @@ int32 PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32
if (currentFound != -1) {
*fxx = currentFound % _width;
*fyy = currentFound / _width;
- return 1;
+ return true;
} else {
*fxx = 0;
*fyy = 0;
- return 0;
+ return false;
}
}
@@ -238,15 +248,13 @@ bool PathFinding::walkLine(int32 x, int32 y, int32 x2, int32 y2) {
int32 cdx = (dx << 16) / t;
int32 cdy = (dy << 16) / t;
- int32 i = t;
_gridPathCount = 0;
- while (i) {
+ for (int32 i = t; i > 0; i--) {
_tempPathX[i] = bx >> 16;
_tempPathY[i] = by >> 16;
_gridPathCount++;
bx += cdx;
by += cdy;
- i--;
}
_tempPathX[0] = x2;
@@ -271,17 +279,16 @@ bool PathFinding::lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2) {
int32 cdx = (dx << 16) / t;
int32 cdy = (dy << 16) / t;
- int32 i = t;
- while (i) {
+ for (int32 i = t; i > 0; i--) {
if (!isWalkable(bx >> 16, by >> 16))
return false;
bx += cdx;
by += cdy;
- i--;
}
return true;
}
-int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
+
+bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
debugC(1, kDebugPath, "findPath(%d, %d, %d, %d)", x, y, destx, desty);
if (x == destx && y == desty) {
@@ -373,7 +380,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
numpath++;
int32 bestscore = sq[destx + desty * _width];
- while (1) {
+ while (true) {
int32 bestX = -1;
int32 bestY = -1;
@@ -403,7 +410,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
free(retPathX);
free(retPathY);
- return 0;
+ return false;
}
retPathX[numpath] = bestX;
@@ -432,18 +439,6 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
return false;
}
-void PathFinding::init(Picture *mask) {
- debugC(1, kDebugPath, "init(mask)");
-
- _width = mask->getWidth();
- _height = mask->getHeight();
- _currentMask = mask;
- _heap->unload();
- _heap->init(500);
- delete[] _gridTemp;
- _gridTemp = new int32[_width*_height];
-}
-
void PathFinding::resetBlockingRects() {
_numBlockingRects = 0;
}
@@ -460,7 +455,7 @@ void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
}
void PathFinding::addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h) {
- debugC(1, kDebugPath, "addBlockingRect(%d, %d, %d, %d)", x1, y1, w, h);
+ debugC(1, kDebugPath, "addBlockingEllipse(%d, %d, %d, %d)", x1, y1, w, h);
_blockingRects[_numBlockingRects][0] = x1;
_blockingRects[_numBlockingRects][1] = y1;
diff --git a/engines/toon/path.h b/engines/toon/path.h
index df2b2e94be..7709dfe2a0 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -57,13 +57,14 @@ public:
PathFinding(ToonEngine *vm);
~PathFinding();
- int32 findPath(int32 x, int32 y, int32 destX, int32 destY);
- int32 findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
+ void init(Picture *mask);
+
+ bool findPath(int32 x, int32 y, int32 destX, int32 destY);
+ bool findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
bool isWalkable(int32 x, int32 y);
bool isLikelyWalkable(int32 x, int32 y);
bool lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2);
bool walkLine(int32 x, int32 y, int32 x2, int32 y2);
- void init(Picture *mask);
void resetBlockingRects();
void addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2);