From a693603e1ee1a58f2d4c72f726a9f92a3ddf1627 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sat, 9 Jun 2012 11:58:26 +0100 Subject: TOON: Replace Pathfinding _tempPath static buffers with Common::Array. --- engines/toon/path.cpp | 31 ++++++++++++++++++------------- engines/toon/path.h | 16 ++++++++++------ 2 files changed, 28 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index b3f9b306be..b4fe412144 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -248,17 +248,19 @@ bool PathFinding::walkLine(int32 x, int32 y, int32 x2, int32 y2) { int32 cdx = (dx << 16) / t; int32 cdy = (dy << 16) / t; - _gridPathCount = 0; + _tempPath.clear(); + i32Point p; for (int32 i = t; i > 0; i--) { - _tempPathX[i] = bx >> 16; - _tempPathY[i] = by >> 16; - _gridPathCount++; + p.x = bx >> 16; + p.y = by >> 16; + _tempPath.insert_at(0, p); bx += cdx; by += cdy; } - _tempPathX[0] = x2; - _tempPathY[0] = y2; + p.x = x2; + p.y = y2; + _tempPath.insert_at(0, p); return true; } @@ -292,13 +294,13 @@ 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) { - _gridPathCount = 0; + _tempPath.clear(); return true; } // ignore path finding if the character is outside the screen if (x < 0 || x > 1280 || y < 0 || y > 400 || destx < 0 || destx > 1280 || desty < 0 || desty > 400) { - _gridPathCount = 0; + _tempPath.clear(); return true; } @@ -357,7 +359,7 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { // let's see if we found a result ! if (!_gridTemp[destx + desty * _width]) { // didn't find anything - _gridPathCount = 0; + _tempPath.clear(); return false; } @@ -415,10 +417,13 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { numpath++; if ((bestX == x && bestY == y)) { - _gridPathCount = numpath; - - memcpy(_tempPathX, retPathX, sizeof(int32) * numpath); - memcpy(_tempPathY, retPathY, sizeof(int32) * numpath); + _tempPath.clear(); + i32Point p; + for (int32 i = 0; i < numpath; i++) { + p.x = retPathX[i]; + p.y = retPathY[i]; + _tempPath.push_back(p); + } retVal = true; break; diff --git a/engines/toon/path.h b/engines/toon/path.h index 26abb411cc..6a22096054 100644 --- a/engines/toon/path.h +++ b/engines/toon/path.h @@ -23,6 +23,8 @@ #ifndef TOON_PATH_H #define TOON_PATH_H +#include "common/array.h" + #include "toon/toon.h" namespace Toon { @@ -70,9 +72,9 @@ public: void addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2); void addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h); - int32 getPathNodeCount() const { return _gridPathCount; } - int32 getPathNodeX(int32 nodeId) const { return _tempPathX[ _gridPathCount - nodeId - 1]; } - int32 getPathNodeY(int32 nodeId) const { return _tempPathY[ _gridPathCount - nodeId - 1]; } + int32 getPathNodeCount() const { return _tempPath.size(); } + int32 getPathNodeX(int32 nodeId) const { return _tempPath[ _tempPath.size() - nodeId - 1].x; } + int32 getPathNodeY(int32 nodeId) const { return _tempPath[ _tempPath.size() - nodeId - 1].y; } private: static const uint8 kMaxBlockingRects = 16; @@ -85,9 +87,11 @@ private: int32 _width; int32 _height; - int32 _tempPathX[4096]; - int32 _tempPathY[4096]; - int32 _gridPathCount; + struct i32Point { + int32 x, y; + }; + + Common::Array _tempPath; int32 _blockingRects[kMaxBlockingRects][5]; uint8 _numBlockingRects; -- cgit v1.2.3