aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorD G Turner2012-06-09 11:58:26 +0100
committerD G Turner2012-06-09 11:58:26 +0100
commita693603e1ee1a58f2d4c72f726a9f92a3ddf1627 (patch)
treeb3ac03a60ac5a7371ebf47f3a9ca50196d7cb65d /engines
parent380d3f000a12c4b923d7330cc88551f73abd7265 (diff)
downloadscummvm-rg350-a693603e1ee1a58f2d4c72f726a9f92a3ddf1627.tar.gz
scummvm-rg350-a693603e1ee1a58f2d4c72f726a9f92a3ddf1627.tar.bz2
scummvm-rg350-a693603e1ee1a58f2d4c72f726a9f92a3ddf1627.zip
TOON: Replace Pathfinding _tempPath static buffers with Common::Array.
Diffstat (limited to 'engines')
-rw-r--r--engines/toon/path.cpp31
-rw-r--r--engines/toon/path.h16
2 files changed, 28 insertions, 19 deletions
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<i32Point> _tempPath;
int32 _blockingRects[kMaxBlockingRects][5];
uint8 _numBlockingRects;