From fae9f4d5baf258ecb4f9e25fe1364e42442385e2 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sat, 9 Jun 2012 12:33:30 +0100 Subject: TOON: Replace Pathfinding retPath static buffers with Common::Array. --- engines/toon/path.cpp | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'engines') diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index b4fe412144..2b41995a98 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -366,20 +366,13 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { curX = destx; curY = desty; - int32 *retPathX = new int32[4096]; - int32 *retPathY = new int32[4096]; - if (!retPathX || !retPathY) { - delete retPathX; - delete retPathY; + Common::Array retPath; - error("[PathFinding::findPath] Cannot allocate pathfinding buffers"); - } - - int32 numpath = 0; + i32Point p; + p.x = curX; + p.y = curY; + retPath.push_back(p); - retPathX[numpath] = curX; - retPathY[numpath] = curY; - numpath++; int32 bestscore = sq[destx + desty * _width]; bool retVal = false; @@ -412,18 +405,15 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { if (bestX < 0 || bestY < 0) break; - retPathX[numpath] = bestX; - retPathY[numpath] = bestY; - numpath++; + i32Point pp; + pp.x = bestX; + pp.y = bestY; + retPath.push_back(pp); if ((bestX == x && bestY == y)) { _tempPath.clear(); - i32Point p; - for (int32 i = 0; i < numpath; i++) { - p.x = retPathX[i]; - p.y = retPathY[i]; - _tempPath.push_back(p); - } + for (uint32 i = 0; i < retPath.size(); i++) + _tempPath.push_back(retPath[i]); retVal = true; break; @@ -433,9 +423,6 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { curY = bestY; } - delete retPathX; - delete retPathY; - return retVal; } -- cgit v1.2.3