From 13832580002a0a902a23fa893784aa61f7b3faaa Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 10 Jun 2012 20:45:37 +0100 Subject: [PATCH] TOON: Migrate Pathfinding Path Buffers to Common::Point. 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. --- engines/toon/path.cpp | 26 ++++++-------------------- engines/toon/path.h | 9 +++------ 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index 5aae52345559..63dbf1a44203 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -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; @@ -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) { @@ -363,12 +356,8 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) { curX = destx; curY = desty; - Common::Array retPath; - - i32Point p; - p.x = curX; - p.y = curY; - retPath.push_back(p); + Common::Array retPath; + retPath.push_back(Common::Point(curX, curY)); int32 bestscore = _sq[destx + desty * _width]; @@ -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(); diff --git a/engines/toon/path.h b/engines/toon/path.h index f73415adc5ba..2a583e5bff85 100644 --- a/engines/toon/path.h +++ b/engines/toon/path.h @@ -24,6 +24,7 @@ #define TOON_PATH_H #include "common/array.h" +#include "common/rect.h" #include "toon/toon.h" @@ -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); @@ -87,11 +88,7 @@ class PathFinding { int16 _width; int16 _height; - struct i32Point { - int32 x, y; - }; - - Common::Array _tempPath; + Common::Array _tempPath; int16 _blockingRects[kMaxBlockingRects][5]; uint8 _numBlockingRects;