Skip to content

Commit

Permalink
TOON: Migrate Pathfinding Path Buffers to Common::Point.
Browse files Browse the repository at this point in the history
This removes the need for i32Point, which used int32, instead of the
int16 of Common::Point. Since the co-ordinates passed in are in int16,
this is safe. Tested with no regressions.

Also, removed return value from walkLine function as it always returned
true.
  • Loading branch information
digitall committed Jun 10, 2012
1 parent 5458127 commit 1383258
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
26 changes: 6 additions & 20 deletions engines/toon/path.cpp
Expand Up @@ -232,7 +232,7 @@ bool PathFinding::findClosestWalkingPoint(int16 xx, int16 yy, int16 *fxx, int16
}
}

bool PathFinding::walkLine(int16 x, int16 y, int16 x2, int16 y2) {
void PathFinding::walkLine(int16 x, int16 y, int16 x2, int16 y2) {
uint32 bx = x << 16;
int32 dx = x2 - x;
uint32 by = y << 16;
Expand All @@ -249,20 +249,13 @@ bool PathFinding::walkLine(int16 x, int16 y, int16 x2, int16 y2) {
int32 cdy = (dy << 16) / t;

_tempPath.clear();
i32Point p;
for (int32 i = t; i > 0; i--) {
p.x = bx >> 16;
p.y = by >> 16;
_tempPath.insert_at(0, p);
_tempPath.insert_at(0, Common::Point(bx >> 16, by >> 16));
bx += cdx;
by += cdy;
}

p.x = x2;
p.y = y2;
_tempPath.insert_at(0, p);

return true;
_tempPath.insert_at(0, Common::Point(x2, y2));
}

bool PathFinding::lineIsWalkable(int16 x, int16 y, int16 x2, int16 y2) {
Expand Down Expand Up @@ -363,12 +356,8 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
curX = destx;
curY = desty;

Common::Array<i32Point> retPath;

i32Point p;
p.x = curX;
p.y = curY;
retPath.push_back(p);
Common::Array<Common::Point> retPath;
retPath.push_back(Common::Point(curX, curY));

int32 bestscore = _sq[destx + desty * _width];

Expand Down Expand Up @@ -402,10 +391,7 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
if (bestX < 0 || bestY < 0)
break;

i32Point pp;
pp.x = bestX;
pp.y = bestY;
retPath.push_back(pp);
retPath.push_back(Common::Point(bestX, bestY));

if ((bestX == x && bestY == y)) {
_tempPath.clear();
Expand Down
9 changes: 3 additions & 6 deletions engines/toon/path.h
Expand Up @@ -24,6 +24,7 @@
#define TOON_PATH_H

#include "common/array.h"
#include "common/rect.h"

#include "toon/toon.h"

Expand Down Expand Up @@ -66,7 +67,7 @@ class PathFinding {
bool isWalkable(int16 x, int16 y);
bool isLikelyWalkable(int16 x, int16 y);
bool lineIsWalkable(int16 x, int16 y, int16 x2, int16 y2);
bool walkLine(int16 x, int16 y, int16 x2, int16 y2);
void walkLine(int16 x, int16 y, int16 x2, int16 y2);

void resetBlockingRects() { _numBlockingRects = 0; }
void addBlockingRect(int16 x1, int16 y1, int16 x2, int16 y2);
Expand All @@ -87,11 +88,7 @@ class PathFinding {
int16 _width;
int16 _height;

struct i32Point {
int32 x, y;
};

Common::Array<i32Point> _tempPath;
Common::Array<Common::Point> _tempPath;

int16 _blockingRects[kMaxBlockingRects][5];
uint8 _numBlockingRects;
Expand Down

0 comments on commit 1383258

Please sign in to comment.