[Scummvm-cvs-logs] scummvm master -> 57d34d2576d38a2820afeae0ba860dc863a34b08

digitall digitall at scummvm.org
Thu Jun 14 18:48:40 CEST 2012


This automated email contains information about 15 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
dd558510dc TOON: Move PathFindingHeap API to use int16 for x,y coordinates.
8deb8b3d42 TOON: Minor cleanup and formatting fixes to Pathfinding class.
6cda28adc9 TOON: Remove unecessary usages of g_system.
70f09e4ee3 TOON: Reduce unecessary linkages in Pathfinding class.
380d3f000a TOON: Further cleanup to Pathfinding Class.
a693603e1e TOON: Replace Pathfinding _tempPath static buffers with Common::Array.
fae9f4d5ba TOON: Replace Pathfinding retPath static buffers with Common::Array.
2d0cedab1f TOON: Minor cleanups in Pathfinding class. No functional change.
5458127d97 TOON: Migrate Pathfinding API x,y coordinates to int16.
1383258000 TOON: Migrate Pathfinding Path Buffers to Common::Point.
fcfff28c5f TOON: Minor type fixes and cleanups in Pathfinding class.
87eb651886 TOON: Migrate Character API x,y coordinates and subclasses to int16.
d2eab05e7d TOON: Replace Character _currentPath static buffers with Common::Array.
4aa0ec7fc4 TOON: Change Pathfinding weight buffers to uint16.
57d34d2576 Merge branch 'toon-RAM-reduction'


Commit: dd558510dc60b61d9f960c7f49e8bc0327d8115b
    https://github.com/scummvm/scummvm/commit/dd558510dc60b61d9f960c7f49e8bc0327d8115b
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-07T00:39:38-07:00

Commit Message:
TOON: Move PathFindingHeap API to use int16 for x,y coordinates.

The internal x,y point representation was already changed to int16
anyway, so this just harmonises this with the external API (and with
Common::Point which uses int16).

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 2dd5fc4..540290d 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -60,7 +60,7 @@ void PathFindingHeap::clear() {
 	memset(_data, 0, sizeof(HeapDataGrid) * _size);
 }
 
-void PathFindingHeap::push(int32 x, int32 y, int32 weight) {
+void PathFindingHeap::push(int16 x, int16 y, int32 weight) {
 	debugC(2, kDebugPath, "push(%d, %d, %d)", x, y, weight);
 
 	if (_count == _size) {
@@ -87,7 +87,7 @@ void PathFindingHeap::push(int32 x, int32 y, int32 weight) {
 	int32 lMax = _count-1;
 	int32 lT = 0;
 
-	while (1) {
+	while (true) {
 		if (lMax <= 0)
 			break;
 		lT = (lMax-1) / 2;
@@ -104,7 +104,7 @@ void PathFindingHeap::push(int32 x, int32 y, int32 weight) {
 	}
 }
 
-void PathFindingHeap::pop(int32 *x, int32 *y, int32 *weight) {
+void PathFindingHeap::pop(int16 *x, int16 *y, int32 *weight) {
 	debugC(2, kDebugPath, "pop(x, y, weight)");
 
 	if (!_count) {
@@ -123,7 +123,7 @@ void PathFindingHeap::pop(int32 *x, int32 *y, int32 *weight) {
 	int32 lMin = 0;
 	int32 lT = 0;
 
-	while (1) {
+	while (true) {
 		lT = (lMin << 1) + 1;
 		if (lT < _count) {
 			if (lT < _count-1) {
@@ -315,7 +315,9 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 
 	while (_heap->getCount()) {
 		wei = 0;
-		_heap->pop(&curX, &curY, &curWeight);
+		int16 tempCurX, tempCurY;
+		_heap->pop(&tempCurX, &tempCurY, &curWeight);
+		curX = tempCurX, curY = tempCurY; // FIXME - Bodge to match heap->pop types
 		int curNode = curX + curY * _width;
 
 		int32 endX = MIN<int32>(curX + 1, _width - 1);
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 2de5806..df2b2e9 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -38,8 +38,8 @@ public:
 	PathFindingHeap();
 	~PathFindingHeap();
 
-	void push(int32 x, int32 y, int32 weight);
-	void pop(int32 *x, int32 *y, int32 *weight);
+	void push(int16 x, int16 y, int32 weight);
+	void pop(int16 *x, int16 *y, int32 *weight);
 	void init(int32 size);
 	void clear();
 	void unload();


Commit: 8deb8b3d42927d1d6e73350f96353eda1b10a1fc
    https://github.com/scummvm/scummvm/commit/8deb8b3d42927d1d6e73350f96353eda1b10a1fc
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-07T04:33:13-07:00

Commit Message:
TOON: Minor cleanup and formatting fixes to Pathfinding class.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 540290d..101778d 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -161,6 +161,18 @@ PathFinding::~PathFinding(void) {
 	delete[] _gridTemp;
 }
 
+void PathFinding::init(Picture *mask) {
+	debugC(1, kDebugPath, "init(mask)");
+
+	_width = mask->getWidth();
+	_height = mask->getHeight();
+	_currentMask = mask;
+	_heap->unload();
+	_heap->init(500);
+	delete[] _gridTemp;
+	_gridTemp = new int32[_width * _height];
+}
+
 bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
 	for (int32 i = 0; i < _numBlockingRects; i++) {
 		if (_blockingRects[i][4] == 0) {
@@ -180,12 +192,10 @@ bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
 bool PathFinding::isWalkable(int32 x, int32 y) {
 	debugC(2, kDebugPath, "isWalkable(%d, %d)", x, y);
 
-	bool maskWalk = (_currentMask->getData(x, y) & 0x1f) > 0;
-
-	return maskWalk;
+	return (_currentMask->getData(x, y) & 0x1f) > 0;
 }
 
-int32 PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX, int origY) {
+bool PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX, int origY) {
 	debugC(1, kDebugPath, "findClosestWalkingPoint(%d, %d, fxx, fyy, %d, %d)", xx, yy, origX, origY);
 
 	int32 currentFound = -1;
@@ -214,11 +224,11 @@ int32 PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32
 	if (currentFound != -1) {
 		*fxx = currentFound % _width;
 		*fyy = currentFound / _width;
-		return 1;
+		return true;
 	} else {
 		*fxx = 0;
 		*fyy = 0;
-		return 0;
+		return false;
 	}
 }
 
@@ -238,15 +248,13 @@ bool PathFinding::walkLine(int32 x, int32 y, int32 x2, int32 y2) {
 	int32 cdx = (dx << 16) / t;
 	int32 cdy = (dy << 16) / t;
 
-	int32 i = t;
 	_gridPathCount = 0;
-	while (i) {
+	for (int32 i = t; i > 0; i--) {
 		_tempPathX[i] = bx >> 16;
 		_tempPathY[i] = by >> 16;
 		_gridPathCount++;
 		bx += cdx;
 		by += cdy;
-		i--;
 	}
 
 	_tempPathX[0] = x2;
@@ -271,17 +279,16 @@ bool PathFinding::lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2) {
 	int32 cdx = (dx << 16) / t;
 	int32 cdy = (dy << 16) / t;
 
-	int32 i = t;
-	while (i) {
+	for (int32 i = t; i > 0; i--) {
 		if (!isWalkable(bx >> 16, by >> 16))
 			return false;
 		bx += cdx;
 		by += cdy;
-		i--;
 	}
 	return true;
 }
-int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
+
+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) {
@@ -373,7 +380,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	numpath++;
 	int32 bestscore = sq[destx + desty * _width];
 
-	while (1) {
+	while (true) {
 		int32 bestX = -1;
 		int32 bestY = -1;
 
@@ -403,7 +410,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 			free(retPathX);
 			free(retPathY);
 
-			return 0;
+			return false;
 		}
 
 		retPathX[numpath] = bestX;
@@ -432,18 +439,6 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	return false;
 }
 
-void PathFinding::init(Picture *mask) {
-	debugC(1, kDebugPath, "init(mask)");
-
-	_width = mask->getWidth();
-	_height = mask->getHeight();
-	_currentMask = mask;
-	_heap->unload();
-	_heap->init(500);
-	delete[] _gridTemp;
-	_gridTemp = new int32[_width*_height];
-}
-
 void PathFinding::resetBlockingRects() {
 	_numBlockingRects = 0;
 }
@@ -460,7 +455,7 @@ void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
 }
 
 void PathFinding::addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h) {
-	debugC(1, kDebugPath, "addBlockingRect(%d, %d, %d, %d)", x1, y1, w, h);
+	debugC(1, kDebugPath, "addBlockingEllipse(%d, %d, %d, %d)", x1, y1, w, h);
 
 	_blockingRects[_numBlockingRects][0] = x1;
 	_blockingRects[_numBlockingRects][1] = y1;
diff --git a/engines/toon/path.h b/engines/toon/path.h
index df2b2e9..7709dfe 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -57,13 +57,14 @@ public:
 	PathFinding(ToonEngine *vm);
 	~PathFinding();
 
-	int32 findPath(int32 x, int32 y, int32 destX, int32 destY);
-	int32 findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
+	void init(Picture *mask);
+
+	bool findPath(int32 x, int32 y, int32 destX, int32 destY);
+	bool findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
 	bool isWalkable(int32 x, int32 y);
 	bool isLikelyWalkable(int32 x, int32 y);
 	bool lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2);
 	bool walkLine(int32 x, int32 y, int32 x2, int32 y2);
-	void init(Picture *mask);
 
 	void resetBlockingRects();
 	void addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2);


Commit: 6cda28adc9e1adb5b05bdb58baf449f2e24b9945
    https://github.com/scummvm/scummvm/commit/6cda28adc9e1adb5b05bdb58baf449f2e24b9945
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-07T05:20:53-07:00

Commit Message:
TOON: Remove unecessary usages of g_system.

Changed paths:
    engines/toon/toon.cpp



diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 657e186..9e7aa65 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -168,7 +168,7 @@ void ToonEngine::waitForScriptStep() {
 	// Wait after a specified number of script steps when executing a script
 	// to lower CPU usage
 	if (++_scriptStep >= 40) {
-		g_system->delayMillis(1);
+		_system->delayMillis(1);
 		_scriptStep = 0;
 	}
 }
@@ -2979,8 +2979,7 @@ bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) {
 		return false; // dialog aborted
 
 	Common::String savegameFile = getSavegameName(savegameId);
-	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
-	Common::OutSaveFile *saveFile = saveMan->openForSaving(savegameFile);
+	Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(savegameFile);
 	if (!saveFile)
 		return false;
 
@@ -3068,8 +3067,7 @@ bool ToonEngine::loadGame(int32 slot) {
 		return false; // dialog aborted
 
 	Common::String savegameFile = getSavegameName(savegameId);
-	Common::SaveFileManager *saveMan = g_system->getSavefileManager();
-	Common::InSaveFile *loadFile = saveMan->openForLoading(savegameFile);
+	Common::InSaveFile *loadFile = _saveFileMan->openForLoading(savegameFile);
 	if (!loadFile)
 		return false;
 


Commit: 70f09e4ee36525025421db28a5a50b8b5dc0a963
    https://github.com/scummvm/scummvm/commit/70f09e4ee36525025421db28a5a50b8b5dc0a963
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-07T05:50:24-07:00

Commit Message:
TOON: Reduce unecessary linkages in Pathfinding class.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h
    engines/toon/toon.cpp



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 101778d..527be13 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -146,7 +146,7 @@ void PathFindingHeap::pop(int16 *x, int16 *y, int32 *weight) {
 	}
 }
 
-PathFinding::PathFinding(ToonEngine *vm) : _vm(vm) {
+PathFinding::PathFinding() {
 	_width = 0;
 	_height = 0;
 	_heap = new PathFindingHeap();
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 7709dfe..30a7a53 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -28,11 +28,6 @@
 namespace Toon {
 
 // binary heap system for fast A*
-struct HeapDataGrid {
-	int16 _x, _y;
-	int16 _weight;
-};
-
 class PathFindingHeap {
 public:
 	PathFindingHeap();
@@ -46,6 +41,11 @@ public:
 	int32 getCount() { return _count; }
 
 private:
+	struct HeapDataGrid {
+		int16 _x, _y;
+		int16 _weight;
+	};
+
 	HeapDataGrid *_data;
 
 	int32 _size;
@@ -54,7 +54,7 @@ private:
 
 class PathFinding {
 public:
-	PathFinding(ToonEngine *vm);
+	PathFinding();
 	~PathFinding();
 
 	void init(Picture *mask);
@@ -73,7 +73,8 @@ public:
 	int32 getPathNodeCount() const;
 	int32 getPathNodeX(int32 nodeId) const;
 	int32 getPathNodeY(int32 nodeId) const;
-protected:
+
+private:
 	Picture *_currentMask;
 
 	PathFindingHeap *_heap;
@@ -88,8 +89,6 @@ protected:
 	int32 _numBlockingRects;
 	int32 _allocatedGridPathCount;
 	int32 _gridPathCount;
-
-	ToonEngine *_vm;
 };
 
 } // End of namespace Toon
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 9e7aa65..0b39432 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -100,7 +100,7 @@ void ToonEngine::init() {
 
 	syncSoundSettings();
 
-	_pathFinding = new PathFinding(this);
+	_pathFinding = new PathFinding();
 
 	resources()->openPackage("LOCAL.PAK");
 	resources()->openPackage("ONETIME.PAK");


Commit: 380d3f000a12c4b923d7330cc88551f73abd7265
    https://github.com/scummvm/scummvm/commit/380d3f000a12c4b923d7330cc88551f73abd7265
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-07T06:41:04-07:00

Commit Message:
TOON: Further cleanup to Pathfinding Class.

Removal of some unused variables, logical reordering of functions and
minor changes to reduce minor duplication. No functional changes.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 527be13..b3f9b30 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -174,7 +174,7 @@ void PathFinding::init(Picture *mask) {
 }
 
 bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
-	for (int32 i = 0; i < _numBlockingRects; i++) {
+	for (uint8 i = 0; i < _numBlockingRects; i++) {
 		if (_blockingRects[i][4] == 0) {
 			if (x >= _blockingRects[i][0] && x <= _blockingRects[i][2] && y >= _blockingRects[i][1] && y < _blockingRects[i][3])
 				return false;
@@ -364,11 +364,11 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	curX = destx;
 	curY = desty;
 
-	int32 *retPathX = (int32 *)malloc(4096 * sizeof(int32));
-	int32 *retPathY = (int32 *)malloc(4096 * sizeof(int32));
+	int32 *retPathX = new int32[4096];
+	int32 *retPathY = new int32[4096];
 	if (!retPathX || !retPathY) {
-		free(retPathX);
-		free(retPathY);
+		delete retPathX;
+		delete retPathY;
 
 		error("[PathFinding::findPath] Cannot allocate pathfinding buffers");
 	}
@@ -380,6 +380,7 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	numpath++;
 	int32 bestscore = sq[destx + desty * _width];
 
+	bool retVal = false;
 	while (true) {
 		int32 bestX = -1;
 		int32 bestY = -1;
@@ -406,12 +407,8 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 			}
 		}
 
-		if (bestX < 0 || bestY < 0) {
-			free(retPathX);
-			free(retPathY);
-
-			return false;
-		}
+		if (bestX < 0 || bestY < 0)
+			break;
 
 		retPathX[numpath] = bestX;
 		retPathY[numpath] = bestY;
@@ -423,28 +420,26 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 			memcpy(_tempPathX, retPathX, sizeof(int32) * numpath);
 			memcpy(_tempPathY, retPathY, sizeof(int32) * numpath);
 
-			free(retPathX);
-			free(retPathY);
-
-			return true;
+			retVal = true;
+			break;
 		}
 
 		curX = bestX;
 		curY = bestY;
 	}
 
-	free(retPathX);
-	free(retPathY);
+	delete retPathX;
+	delete retPathY;
 
-	return false;
-}
-
-void PathFinding::resetBlockingRects() {
-	_numBlockingRects = 0;
+	return retVal;
 }
 
 void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
 	debugC(1, kDebugPath, "addBlockingRect(%d, %d, %d, %d)", x1, y1, x2, y2);
+	if (_numBlockingRects >= kMaxBlockingRects) {
+		warning("Maximum number of %d Blocking Rects reached!", kMaxBlockingRects);
+		return;
+	}
 
 	_blockingRects[_numBlockingRects][0] = x1;
 	_blockingRects[_numBlockingRects][1] = y1;
@@ -456,6 +451,10 @@ void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
 
 void PathFinding::addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h) {
 	debugC(1, kDebugPath, "addBlockingEllipse(%d, %d, %d, %d)", x1, y1, w, h);
+	if (_numBlockingRects >= kMaxBlockingRects) {
+		warning("Maximum number of %d Blocking Rects reached!", kMaxBlockingRects);
+		return;
+	}
 
 	_blockingRects[_numBlockingRects][0] = x1;
 	_blockingRects[_numBlockingRects][1] = y1;
@@ -465,16 +464,4 @@ void PathFinding::addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h) {
 	_numBlockingRects++;
 }
 
-int32 PathFinding::getPathNodeCount() const {
-	return _gridPathCount;
-}
-
-int32 PathFinding::getPathNodeX(int32 nodeId) const {
-	return _tempPathX[ _gridPathCount - nodeId - 1];
-}
-
-int32 PathFinding::getPathNodeY(int32 nodeId) const {
-	return _tempPathY[ _gridPathCount - nodeId - 1];
-}
-
 } // End of namespace Toon
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 30a7a53..26abb41 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -66,15 +66,17 @@ public:
 	bool lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2);
 	bool walkLine(int32 x, int32 y, int32 x2, int32 y2);
 
-	void resetBlockingRects();
+	void resetBlockingRects() { _numBlockingRects = 0; }
 	void addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2);
 	void addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h);
 
-	int32 getPathNodeCount() const;
-	int32 getPathNodeX(int32 nodeId) const;
-	int32 getPathNodeY(int32 nodeId) const;
+	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]; }
 
 private:
+	static const uint8 kMaxBlockingRects = 16;
+
 	Picture *_currentMask;
 
 	PathFindingHeap *_heap;
@@ -85,10 +87,10 @@ private:
 
 	int32 _tempPathX[4096];
 	int32 _tempPathY[4096];
-	int32 _blockingRects[16][5];
-	int32 _numBlockingRects;
-	int32 _allocatedGridPathCount;
 	int32 _gridPathCount;
+
+	int32 _blockingRects[kMaxBlockingRects][5];
+	uint8 _numBlockingRects;
 };
 
 } // End of namespace Toon


Commit: a693603e1ee1a58f2d4c72f726a9f92a3ddf1627
    https://github.com/scummvm/scummvm/commit/a693603e1ee1a58f2d4c72f726a9f92a3ddf1627
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-09T03:58:26-07:00

Commit Message:
TOON: Replace Pathfinding _tempPath static buffers with Common::Array.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index b3f9b30..b4fe412 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 26abb41..6a22096 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;


Commit: fae9f4d5baf258ecb4f9e25fe1364e42442385e2
    https://github.com/scummvm/scummvm/commit/fae9f4d5baf258ecb4f9e25fe1364e42442385e2
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-09T04:33:30-07:00

Commit Message:
TOON: Replace Pathfinding retPath static buffers with Common::Array.

Changed paths:
    engines/toon/path.cpp



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index b4fe412..2b41995 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<i32Point> 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;
 }
 


Commit: 2d0cedab1ff3984d1d269c0fb735f9179ca8e7d9
    https://github.com/scummvm/scummvm/commit/2d0cedab1ff3984d1d269c0fb735f9179ca8e7d9
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-09T05:43:42-07:00

Commit Message:
TOON: Minor cleanups in Pathfinding class. No functional change.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 2b41995..dfdf095 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -150,7 +150,7 @@ PathFinding::PathFinding() {
 	_width = 0;
 	_height = 0;
 	_heap = new PathFindingHeap();
-	_gridTemp = NULL;
+	_sq = NULL;
 	_numBlockingRects = 0;
 }
 
@@ -158,7 +158,7 @@ PathFinding::~PathFinding(void) {
 	if (_heap)
 		_heap->unload();
 	delete _heap;
-	delete[] _gridTemp;
+	delete[] _sq;
 }
 
 void PathFinding::init(Picture *mask) {
@@ -169,8 +169,8 @@ void PathFinding::init(Picture *mask) {
 	_currentMask = mask;
 	_heap->unload();
 	_heap->init(500);
-	delete[] _gridTemp;
-	_gridTemp = new int32[_width * _height];
+	delete[] _sq;
+	_sq = new int32[_width * _height];
 }
 
 bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
@@ -311,23 +311,22 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	}
 
 	// no direct line, we use the standard A* algorithm
-	memset(_gridTemp , 0, _width * _height * sizeof(int32));
+	memset(_sq , 0, _width * _height * sizeof(int32));
 	_heap->clear();
 	int32 curX = x;
 	int32 curY = y;
 	int32 curWeight = 0;
-	int32 *sq = _gridTemp;
 
-	sq[curX + curY *_width] = 1;
+	_sq[curX + curY *_width] = 1;
 	_heap->push(curX, curY, abs(destx - x) + abs(desty - y));
-	int wei = 0;
+	int32 wei = 0;
 
 	while (_heap->getCount()) {
 		wei = 0;
 		int16 tempCurX, tempCurY;
 		_heap->pop(&tempCurX, &tempCurY, &curWeight);
 		curX = tempCurX, curY = tempCurY; // FIXME - Bodge to match heap->pop types
-		int curNode = curX + curY * _width;
+		int32 curNode = curX + curY * _width;
 
 		int32 endX = MIN<int32>(curX + 1, _width - 1);
 		int32 endY = MIN<int32>(curY + 1, _height - 1);
@@ -336,17 +335,17 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 		bool next = false;
 
 		for (int32 px = startX; px <= endX && !next; px++) {
-			for (int py = startY; py <= endY && !next; py++) {
+			for (int32 py = startY; py <= endY && !next; py++) {
 				if (px != curX || py != curY) {
 					wei = ((abs(px - curX) + abs(py - curY)));
 
 					int32 curPNode = px + py * _width;
 					if (isWalkable(px, py)) { // walkable ?
-						int sum = sq[curNode] + wei * (1 + (isLikelyWalkable(px, py) ? 5 : 0));
-						if (sq[curPNode] > sum || !sq[curPNode]) {
-							int newWeight = abs(destx - px) + abs(desty - py);
-							sq[curPNode] = sum;
-							_heap->push(px, py, sq[curPNode] + newWeight);
+						int32 sum = _sq[curNode] + wei * (1 + (isLikelyWalkable(px, py) ? 5 : 0));
+						if (_sq[curPNode] > sum || !_sq[curPNode]) {
+							int32 newWeight = abs(destx - px) + abs(desty - py);
+							_sq[curPNode] = sum;
+							_heap->push(px, py, _sq[curPNode] + newWeight);
 							if (!newWeight)
 								next = true; // we found it !
 						}
@@ -357,7 +356,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]) {
+	if (!_sq[destx + desty * _width]) {
 		// didn't find anything
 		_tempPath.clear();
 		return false;
@@ -373,7 +372,7 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	p.y = curY;
 	retPath.push_back(p);
 
-	int32 bestscore = sq[destx + desty * _width];
+	int32 bestscore = _sq[destx + desty * _width];
 
 	bool retVal = false;
 	while (true) {
@@ -390,10 +389,10 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 				if (px != curX || py != curY) {
 					wei = abs(px - curX) + abs(py - curY);
 
-					int PNode = px + py * _width;
-					if (sq[PNode] && (isWalkable(px, py))) {
-						if (sq[PNode] < bestscore) {
-							bestscore = sq[PNode];
+					int32 PNode = px + py * _width;
+					if (_sq[PNode] && (isWalkable(px, py))) {
+						if (_sq[PNode] < bestscore) {
+							bestscore = _sq[PNode];
 							bestX = px;
 							bestY = py;
 						}
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 6a22096..8e2c61d 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -83,7 +83,7 @@ private:
 
 	PathFindingHeap *_heap;
 
-	int32 *_gridTemp;
+	int32 *_sq;
 	int32 _width;
 	int32 _height;
 


Commit: 5458127d9706d2c124d907edc5be06e58384d562
    https://github.com/scummvm/scummvm/commit/5458127d9706d2c124d907edc5be06e58384d562
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-10T08:00:26-07:00

Commit Message:
TOON: Migrate Pathfinding API x,y coordinates to int16.

This harmonises the usage with Common::Point.

Changed paths:
    engines/toon/character.cpp
    engines/toon/path.cpp
    engines/toon/path.h
    engines/toon/toon.cpp



diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 0e51899..3ac4549 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -173,7 +173,9 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) {
 		_vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY);
 	}
 
-	_vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &_finalX, &_finalY, _x, _y);
+	int16 tempFinalX, tempFinalY;
+	_vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &tempFinalX, &tempFinalY, _x, _y);
+	_finalX = tempFinalX, _finalY = tempFinalY; // FIXME - Bodge to match types...
 	if (_x == _finalX && _y == _finalY)
 		return true;
 
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index dfdf095..5aae523 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -60,7 +60,7 @@ void PathFindingHeap::clear() {
 	memset(_data, 0, sizeof(HeapDataGrid) * _size);
 }
 
-void PathFindingHeap::push(int16 x, int16 y, int32 weight) {
+void PathFindingHeap::push(int16 x, int16 y, int16 weight) {
 	debugC(2, kDebugPath, "push(%d, %d, %d)", x, y, weight);
 
 	if (_count == _size) {
@@ -104,7 +104,7 @@ void PathFindingHeap::push(int16 x, int16 y, int32 weight) {
 	}
 }
 
-void PathFindingHeap::pop(int16 *x, int16 *y, int32 *weight) {
+void PathFindingHeap::pop(int16 *x, int16 *y, int16 *weight) {
 	debugC(2, kDebugPath, "pop(x, y, weight)");
 
 	if (!_count) {
@@ -173,14 +173,14 @@ void PathFinding::init(Picture *mask) {
 	_sq = new int32[_width * _height];
 }
 
-bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
+bool PathFinding::isLikelyWalkable(int16 x, int16 y) {
 	for (uint8 i = 0; i < _numBlockingRects; i++) {
 		if (_blockingRects[i][4] == 0) {
 			if (x >= _blockingRects[i][0] && x <= _blockingRects[i][2] && y >= _blockingRects[i][1] && y < _blockingRects[i][3])
 				return false;
 		} else {
-			int32 dx = abs(_blockingRects[i][0] - x);
-			int32 dy = abs(_blockingRects[i][1] - y);
+			int16 dx = abs(_blockingRects[i][0] - x);
+			int16 dy = abs(_blockingRects[i][1] - y);
 			if ((dx << 8) / _blockingRects[i][2] < (1 << 8) && (dy << 8) / _blockingRects[i][3] < (1 << 8)) {
 				return false;
 			}
@@ -189,13 +189,13 @@ bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
 	return true;
 }
 
-bool PathFinding::isWalkable(int32 x, int32 y) {
+bool PathFinding::isWalkable(int16 x, int16 y) {
 	debugC(2, kDebugPath, "isWalkable(%d, %d)", x, y);
 
 	return (_currentMask->getData(x, y) & 0x1f) > 0;
 }
 
-bool PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX, int origY) {
+bool PathFinding::findClosestWalkingPoint(int16 xx, int16 yy, int16 *fxx, int16 *fyy, int16 origX, int16 origY) {
 	debugC(1, kDebugPath, "findClosestWalkingPoint(%d, %d, fxx, fyy, %d, %d)", xx, yy, origX, origY);
 
 	int32 currentFound = -1;
@@ -207,8 +207,8 @@ bool PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32
 	if (origY == -1)
 		origY = yy;
 
-	for (int y = 0; y < _height; y++) {
-		for (int x = 0; x < _width; x++) {
+	for (int16 y = 0; y < _height; y++) {
+		for (int16 x = 0; x < _width; x++) {
 			if (isWalkable(x, y) && isLikelyWalkable(x, y)) {
 				int32 ndist = (x - xx) * (x - xx) + (y - yy) * (y - yy);
 				int32 ndist2 = (x - origX) * (x - origX) + (y - origY) * (y - origY);
@@ -232,7 +232,7 @@ bool PathFinding::findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32
 	}
 }
 
-bool PathFinding::walkLine(int32 x, int32 y, int32 x2, int32 y2) {
+bool PathFinding::walkLine(int16 x, int16 y, int16 x2, int16 y2) {
 	uint32 bx = x << 16;
 	int32 dx = x2 - x;
 	uint32 by = y << 16;
@@ -265,7 +265,7 @@ bool PathFinding::walkLine(int32 x, int32 y, int32 x2, int32 y2) {
 	return true;
 }
 
-bool PathFinding::lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2) {
+bool PathFinding::lineIsWalkable(int16 x, int16 y, int16 x2, int16 y2) {
 	uint32 bx = x << 16;
 	int32 dx = x2 - x;
 	uint32 by = y << 16;
@@ -290,7 +290,7 @@ bool PathFinding::lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2) {
 	return true;
 }
 
-bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
+bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 	debugC(1, kDebugPath, "findPath(%d, %d, %d, %d)", x, y, destx, desty);
 
 	if (x == destx && y == desty) {
@@ -313,9 +313,9 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	// no direct line, we use the standard A* algorithm
 	memset(_sq , 0, _width * _height * sizeof(int32));
 	_heap->clear();
-	int32 curX = x;
-	int32 curY = y;
-	int32 curWeight = 0;
+	int16 curX = x;
+	int16 curY = y;
+	int16 curWeight = 0;
 
 	_sq[curX + curY *_width] = 1;
 	_heap->push(curX, curY, abs(destx - x) + abs(desty - y));
@@ -323,19 +323,17 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 
 	while (_heap->getCount()) {
 		wei = 0;
-		int16 tempCurX, tempCurY;
-		_heap->pop(&tempCurX, &tempCurY, &curWeight);
-		curX = tempCurX, curY = tempCurY; // FIXME - Bodge to match heap->pop types
+		_heap->pop(&curX, &curY, &curWeight);
 		int32 curNode = curX + curY * _width;
 
-		int32 endX = MIN<int32>(curX + 1, _width - 1);
-		int32 endY = MIN<int32>(curY + 1, _height - 1);
-		int32 startX = MAX<int32>(curX - 1, 0);
-		int32 startY = MAX<int32>(curY - 1, 0);
+		int16 endX = MIN<int16>(curX + 1, _width - 1);
+		int16 endY = MIN<int16>(curY + 1, _height - 1);
+		int16 startX = MAX<int16>(curX - 1, 0);
+		int16 startY = MAX<int16>(curY - 1, 0);
 		bool next = false;
 
-		for (int32 px = startX; px <= endX && !next; px++) {
-			for (int32 py = startY; py <= endY && !next; py++) {
+		for (int16 px = startX; px <= endX && !next; px++) {
+			for (int16 py = startY; py <= endY && !next; py++) {
 				if (px != curX || py != curY) {
 					wei = ((abs(px - curX) + abs(py - curY)));
 
@@ -376,16 +374,16 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 
 	bool retVal = false;
 	while (true) {
-		int32 bestX = -1;
-		int32 bestY = -1;
+		int16 bestX = -1;
+		int16 bestY = -1;
 
-		int32 endX = MIN<int32>(curX + 1, _width - 1);
-		int32 endY = MIN<int32>(curY + 1, _height - 1);
-		int32 startX = MAX<int32>(curX - 1, 0);
-		int32 startY = MAX<int32>(curY - 1, 0);
+		int16 endX = MIN<int16>(curX + 1, _width - 1);
+		int16 endY = MIN<int16>(curY + 1, _height - 1);
+		int16 startX = MAX<int16>(curX - 1, 0);
+		int16 startY = MAX<int16>(curY - 1, 0);
 
-		for (int32 px = startX; px <= endX; px++) {
-			for (int32 py = startY; py <= endY; py++) {
+		for (int16 px = startX; px <= endX; px++) {
+			for (int16 py = startY; py <= endY; py++) {
 				if (px != curX || py != curY) {
 					wei = abs(px - curX) + abs(py - curY);
 
@@ -425,7 +423,7 @@ bool PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
 	return retVal;
 }
 
-void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
+void PathFinding::addBlockingRect(int16 x1, int16 y1, int16 x2, int16 y2) {
 	debugC(1, kDebugPath, "addBlockingRect(%d, %d, %d, %d)", x1, y1, x2, y2);
 	if (_numBlockingRects >= kMaxBlockingRects) {
 		warning("Maximum number of %d Blocking Rects reached!", kMaxBlockingRects);
@@ -440,7 +438,7 @@ void PathFinding::addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2) {
 	_numBlockingRects++;
 }
 
-void PathFinding::addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h) {
+void PathFinding::addBlockingEllipse(int16 x1, int16 y1, int16 w, int16 h) {
 	debugC(1, kDebugPath, "addBlockingEllipse(%d, %d, %d, %d)", x1, y1, w, h);
 	if (_numBlockingRects >= kMaxBlockingRects) {
 		warning("Maximum number of %d Blocking Rects reached!", kMaxBlockingRects);
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 8e2c61d..f73415a 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -35,8 +35,8 @@ public:
 	PathFindingHeap();
 	~PathFindingHeap();
 
-	void push(int16 x, int16 y, int32 weight);
-	void pop(int16 *x, int16 *y, int32 *weight);
+	void push(int16 x, int16 y, int16 weight);
+	void pop(int16 *x, int16 *y, int16 *weight);
 	void init(int32 size);
 	void clear();
 	void unload();
@@ -61,16 +61,16 @@ public:
 
 	void init(Picture *mask);
 
-	bool findPath(int32 x, int32 y, int32 destX, int32 destY);
-	bool findClosestWalkingPoint(int32 xx, int32 yy, int32 *fxx, int32 *fyy, int origX = -1, int origY = -1);
-	bool isWalkable(int32 x, int32 y);
-	bool isLikelyWalkable(int32 x, int32 y);
-	bool lineIsWalkable(int32 x, int32 y, int32 x2, int32 y2);
-	bool walkLine(int32 x, int32 y, int32 x2, int32 y2);
+	bool findPath(int16 x, int16 y, int16 destX, int16 destY);
+	bool findClosestWalkingPoint(int16 xx, int16 yy, int16 *fxx, int16 *fyy, int16 origX = -1, int16 origY = -1);
+	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 resetBlockingRects() { _numBlockingRects = 0; }
-	void addBlockingRect(int32 x1, int32 y1, int32 x2, int32 y2);
-	void addBlockingEllipse(int32 x1, int32 y1, int32 w, int32 h);
+	void addBlockingRect(int16 x1, int16 y1, int16 x2, int16 y2);
+	void addBlockingEllipse(int16 x1, int16 y1, int16 w, int16 h);
 
 	int32 getPathNodeCount() const { return _tempPath.size(); }
 	int32 getPathNodeX(int32 nodeId) const { return _tempPath[ _tempPath.size() - nodeId - 1].x; }
@@ -84,8 +84,8 @@ private:
 	PathFindingHeap *_heap;
 
 	int32 *_sq;
-	int32 _width;
-	int32 _height;
+	int16 _width;
+	int16 _height;
 
 	struct i32Point {
 		int32 x, y;
@@ -93,7 +93,7 @@ private:
 
 	Common::Array<i32Point> _tempPath;
 
-	int32 _blockingRects[kMaxBlockingRects][5];
+	int16 _blockingRects[kMaxBlockingRects][5];
 	uint8 _numBlockingRects;
 };
 
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 0b39432..dd3c32b 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -1488,7 +1488,7 @@ void ToonEngine::clickEvent() {
 	}
 
 	if (!currentHot) {
-		int32 xx, yy;
+		int16 xx, yy;
 
 		if (_gameState->_inCutaway || _gameState->_inInventory || _gameState->_inCloseUp)
 			return;


Commit: 13832580002a0a902a23fa893784aa61f7b3faaa
    https://github.com/scummvm/scummvm/commit/13832580002a0a902a23fa893784aa61f7b3faaa
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-10T12:45:37-07:00

Commit Message:
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.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 5aae523..63dbf1a 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<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];
 
@@ -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 f73415a..2a583e5 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 @@ public:
 	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 @@ private:
 	int16 _width;
 	int16 _height;
 
-	struct i32Point {
-		int32 x, y;
-	};
-
-	Common::Array<i32Point> _tempPath;
+	Common::Array<Common::Point> _tempPath;
 
 	int16 _blockingRects[kMaxBlockingRects][5];
 	uint8 _numBlockingRects;


Commit: fcfff28c5f3cabf193d83846cfe9d90f0153d187
    https://github.com/scummvm/scummvm/commit/fcfff28c5f3cabf193d83846cfe9d90f0153d187
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-10T13:12:01-07:00

Commit Message:
TOON: Minor type fixes and cleanups in Pathfinding class.

Changed paths:
    engines/toon/character.cpp
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 3ac4549..260296c 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -186,7 +186,7 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) {
 		int32 smoothDx = 0;
 		int32 smoothDy = 0;
 
-		for (int32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) {
+		for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) {
 			_currentPathX[a] = _vm->getPathFinding()->getPathNodeX(a);
 			_currentPathY[a] = _vm->getPathFinding()->getPathNodeY(a);
 		}
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 63dbf1a..735801e 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -65,7 +65,7 @@ void PathFindingHeap::push(int16 x, int16 y, int16 weight) {
 
 	if (_count == _size) {
 		// Increase size by 50%
-		int newSize = _size + (_size >> 1) + 1;
+		uint32 newSize = _size + (_size / 2) + 1;
 		HeapDataGrid *newData;
 
 		newData = (HeapDataGrid *)realloc(_data, sizeof(HeapDataGrid) * newSize);
@@ -84,13 +84,13 @@ void PathFindingHeap::push(int16 x, int16 y, int16 weight) {
 	_data[_count]._weight = weight;
 	_count++;
 
-	int32 lMax = _count-1;
-	int32 lT = 0;
+	uint32 lMax = _count - 1;
+	uint32 lT = 0;
 
 	while (true) {
 		if (lMax <= 0)
 			break;
-		lT = (lMax-1) / 2;
+		lT = (lMax - 1) / 2;
 
 		if (_data[lT]._weight > _data[lMax]._weight) {
 			HeapDataGrid temp;
@@ -120,13 +120,13 @@ void PathFindingHeap::pop(int16 *x, int16 *y, int16 *weight) {
 	if (!_count)
 		return;
 
-	int32 lMin = 0;
-	int32 lT = 0;
+	uint32 lMin = 0;
+	uint32 lT = 0;
 
 	while (true) {
-		lT = (lMin << 1) + 1;
+		lT = (lMin * 2) + 1;
 		if (lT < _count) {
-			if (lT < _count-1) {
+			if (lT < _count - 1) {
 				if (_data[lT + 1]._weight < _data[lT]._weight)
 					lT++;
 			}
@@ -312,8 +312,8 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 
 	_sq[curX + curY *_width] = 1;
 	_heap->push(curX, curY, abs(destx - x) + abs(desty - y));
-	int32 wei = 0;
 
+	int16 wei;
 	while (_heap->getCount()) {
 		wei = 0;
 		_heap->pop(&curX, &curY, &curWeight);
@@ -328,7 +328,7 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 		for (int16 px = startX; px <= endX && !next; px++) {
 			for (int16 py = startY; py <= endY && !next; py++) {
 				if (px != curX || py != curY) {
-					wei = ((abs(px - curX) + abs(py - curY)));
+					wei = abs(px - curX) + abs(py - curY);
 
 					int32 curPNode = px + py * _width;
 					if (isWalkable(px, py)) { // walkable ?
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 2a583e5..2476dc3 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -41,7 +41,7 @@ public:
 	void init(int32 size);
 	void clear();
 	void unload();
-	int32 getCount() { return _count; }
+	uint32 getCount() { return _count; }
 
 private:
 	struct HeapDataGrid {
@@ -51,8 +51,8 @@ private:
 
 	HeapDataGrid *_data;
 
-	int32 _size;
-	int32 _count;
+	uint32 _size;
+	uint32 _count;
 };
 
 class PathFinding {
@@ -73,9 +73,9 @@ public:
 	void addBlockingRect(int16 x1, int16 y1, int16 x2, int16 y2);
 	void addBlockingEllipse(int16 x1, int16 y1, int16 w, int16 h);
 
-	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; }
+	uint32 getPathNodeCount() const { return _tempPath.size(); }
+	int16 getPathNodeX(uint32 nodeId) const { return _tempPath[(_tempPath.size() - 1) - nodeId].x; }
+	int16 getPathNodeY(uint32 nodeId) const { return _tempPath[(_tempPath.size() - 1) - nodeId].y; }
 
 private:
 	static const uint8 kMaxBlockingRects = 16;


Commit: 87eb651886ef911d8026d777abec72c88ffdf32f
    https://github.com/scummvm/scummvm/commit/87eb651886ef911d8026d777abec72c88ffdf32f
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-13T16:19:34-07:00

Commit Message:
TOON: Migrate Character API x,y coordinates and subclasses to int16.

This harmonises the usage with Common::Point.

Changed paths:
    engines/toon/character.cpp
    engines/toon/character.h
    engines/toon/drew.cpp
    engines/toon/drew.h
    engines/toon/flux.cpp
    engines/toon/flux.h



diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 260296c..2a28642 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -81,7 +81,7 @@ Character::~Character(void) {
 void Character::init() {
 }
 
-void Character::forceFacing( int32 facing ) {
+void Character::forceFacing(int32 facing) {
 	debugC(4, kDebugCharacter, "forceFacing(%d)", facing);
 	_facing = facing;
 }
@@ -136,8 +136,7 @@ void Character::setFacing(int32 facing) {
 	_facing = facing;
 }
 
-void Character::forcePosition(int32 x, int32 y) {
-
+void Character::forcePosition(int16 x, int16 y) {
 	debugC(5, kDebugCharacter, "forcePosition(%d, %d)", x, y);
 
 	setPosition(x, y);
@@ -145,7 +144,7 @@ void Character::forcePosition(int32 x, int32 y) {
 	_finalY = y;
 }
 
-void Character::setPosition(int32 x, int32 y) {
+void Character::setPosition(int16 x, int16 y) {
 	debugC(5, kDebugCharacter, "setPosition(%d, %d)", x, y);
 
 	_x = x;
@@ -155,7 +154,7 @@ void Character::setPosition(int32 x, int32 y) {
 	return;
 }
 
-bool Character::walkTo(int32 newPosX, int32 newPosY) {
+bool Character::walkTo(int16 newPosX, int16 newPosY) {
 	debugC(1, kDebugCharacter, "walkTo(%d, %d)", newPosX, newPosY);
 
 	if (!_visible)
@@ -168,21 +167,19 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) {
 
 	// don't allow flux to go at the same position as drew
 	if (_id == 1 ) {
-		int32 sizeX = MAX<int32>(5, 30 * _vm->getDrew()->getScale() / 1024);
-		int32 sizeY = MAX<int32>(2, 20 * _vm->getDrew()->getScale() / 1024);
+		int16 sizeX = MAX<int16>(5, 30 * _vm->getDrew()->getScale() / 1024);
+		int16 sizeY = MAX<int16>(2, 20 * _vm->getDrew()->getScale() / 1024);
 		_vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY);
 	}
 
-	int16 tempFinalX, tempFinalY;
-	_vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &tempFinalX, &tempFinalY, _x, _y);
-	_finalX = tempFinalX, _finalY = tempFinalY; // FIXME - Bodge to match types...
+	_vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &_finalX, &_finalY, _x, _y);
 	if (_x == _finalX && _y == _finalY)
 		return true;
 
 	if (_vm->getPathFinding()->findPath(_x, _y, _finalX, _finalY)) {
 
-		int32 localFinalX = _finalX;
-		int32 localFinalY = _finalY;
+		int16 localFinalX = _finalX;
+		int16 localFinalY = _finalY;
 		int32 smoothDx = 0;
 		int32 smoothDy = 0;
 
@@ -266,10 +263,11 @@ int32 Character::getFlag() {
 	return _flags;
 }
 
-int32 Character::getX() {
+int16 Character::getX() {
 	return _x;
 }
-int32 Character::getY() {
+
+int16 Character::getY() {
 	return _y;
 }
 
@@ -529,7 +527,7 @@ void Character::update(int32 timeIncrement) {
 }
 
 // adapted from Kyra
-int32 Character::getFacingFromDirection(int32 dx, int32 dy) {
+int32 Character::getFacingFromDirection(int16 dx, int16 dy) {
 	debugC(4, kDebugCharacter, "getFacingFromDirection(%d, %d)", dx, dy);
 
 	static const int facingTable[] = {
@@ -640,7 +638,7 @@ void Character::load(Common::ReadStream *stream) {
 	// "not visible" flag.
 	if (_flags & 0x100) {
 		_flags &= ~0x100;
-		setVisible(false);	
+		setVisible(false);
 	}
 }
 
@@ -1080,11 +1078,11 @@ void Character::setDefaultSpecialAnimationId(int32 defaultAnimationId) {
 	_animSpecialDefaultId = defaultAnimationId;
 }
 
-int32 Character::getFinalX() {
+int16 Character::getFinalX() {
 	return _finalX;
 }
 
-int32 Character::getFinalY() {
+int16 Character::getFinalY() {
 	return _finalY;
 }
 
diff --git a/engines/toon/character.h b/engines/toon/character.h
index d06a6c0..d2d84a8 100644
--- a/engines/toon/character.h
+++ b/engines/toon/character.h
@@ -65,13 +65,13 @@ public:
 	virtual int32 getFlag();
 	virtual int32 getAnimFlag();
 	virtual void setAnimFlag(int32 flag);
-	virtual void setPosition(int32 x, int32 y);
-	virtual void forcePosition(int32 x, int32 y);
-	virtual int32 getX();
-	virtual int32 getY();
-	virtual int32 getFinalX();
-	virtual int32 getFinalY();
-	virtual bool walkTo(int32 newPosX, int32 newPosY);
+	virtual void setPosition(int16 x, int16 y);
+	virtual void forcePosition(int16 x, int16 y);
+	virtual int16 getX();
+	virtual int16 getY();
+	virtual int16 getFinalX();
+	virtual int16 getFinalY();
+	virtual bool walkTo(int16 newPosX, int16 newPosY);
 	virtual bool getVisible();
 	virtual void setVisible(bool visible);
 	virtual bool loadWalkAnimation(const Common::String &animName);
@@ -99,7 +99,7 @@ public:
 	virtual void resetScale() {}
 	virtual void plotPath(Graphics::Surface& surface);
 
-	int32 getFacingFromDirection(int32 dx, int32 dy);
+	int32 getFacingFromDirection(int16 dx, int16 dy);
 	static const SpecialCharacterAnimation *getSpecialAnimation(int32 characterId, int32 animationId);
 
 protected:
@@ -112,11 +112,11 @@ protected:
 	int32 _sceneAnimationId;
 	int32 _lineToSayId;
 	int32 _time;
-	int32 _x;
-	int32 _y;
+	int16 _x;
+	int16 _y;
 	int32 _z;
-	int32 _finalX;
-	int32 _finalY;
+	int16 _finalX;
+	int16 _finalY;
 	int32 _facing;
 	int32 _flags;
 	int32 _animFlags;
@@ -137,8 +137,8 @@ protected:
 	Animation *_shadowAnim;
 	Animation *_specialAnim;
 
-	int32 _currentPathX[4096];
-	int32 _currentPathY[4096];
+	int16 _currentPathX[4096];
+	int16 _currentPathY[4096];
 	int32 _currentPathNodeCount;
 	int32 _currentPathNode;
 	int32 _currentWalkStamp;
diff --git a/engines/toon/drew.cpp b/engines/toon/drew.cpp
index df5cfcf..dfd3f51 100644
--- a/engines/toon/drew.cpp
+++ b/engines/toon/drew.cpp
@@ -48,7 +48,7 @@ bool CharacterDrew::setupPalette() {
 	return false;
 }
 
-void CharacterDrew::setPosition(int32 x, int32 y) {
+void CharacterDrew::setPosition(int16 x, int16 y) {
 	debugC(5, kDebugCharacter, "setPosition(%d, %d)", x, y);
 
 	_z = _vm->getLayerAtPoint(x, y);
diff --git a/engines/toon/drew.h b/engines/toon/drew.h
index 3357b99..ff1b619 100644
--- a/engines/toon/drew.h
+++ b/engines/toon/drew.h
@@ -35,7 +35,7 @@ public:
 	virtual ~CharacterDrew();
 	bool setupPalette();
 	void playStandingAnim();
-	void setPosition(int32 x, int32 y);
+	void setPosition(int16 x, int16 y);
 	void resetScale();
 	void update(int32 timeIncrement);
 	void playWalkAnim(int32 start, int32 end);
diff --git a/engines/toon/flux.cpp b/engines/toon/flux.cpp
index b752e65..70aa40f 100644
--- a/engines/toon/flux.cpp
+++ b/engines/toon/flux.cpp
@@ -45,7 +45,7 @@ void CharacterFlux::playStandingAnim() {
 	_animationInstance->stopAnimation();
 	_animationInstance->setLooping(true);
 
-	//s/etVisible(true);
+	//setVisible(true);
 }
 
 void CharacterFlux::setVisible(bool visible) {
@@ -99,7 +99,7 @@ int32 CharacterFlux::fixFacingForAnimation(int32 originalFacing, int32 animation
 	return finalFacing;
 }
 
-void CharacterFlux::setPosition(int32 x, int32 y) {
+void CharacterFlux::setPosition(int16 x, int16 y) {
 	debugC(5, kDebugCharacter, "setPosition(%d, %d)", x, y);
 
 	_z = _vm->getLayerAtPoint(x, y);
diff --git a/engines/toon/flux.h b/engines/toon/flux.h
index c208bc5..1dc0d9c 100644
--- a/engines/toon/flux.h
+++ b/engines/toon/flux.h
@@ -34,7 +34,7 @@ public:
 	CharacterFlux(ToonEngine *vm);
 	virtual ~CharacterFlux();
 
-	void setPosition(int32 x, int32 y);
+	void setPosition(int16 x, int16 y);
 	void playStandingAnim();
 	void playWalkAnim(int32 start, int32 end);
 	void update(int32 timeIncrement);


Commit: d2eab05e7d08bd5e4e615ee786e62be64293060a
    https://github.com/scummvm/scummvm/commit/d2eab05e7d08bd5e4e615ee786e62be64293060a
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-14T05:38:45-07:00

Commit Message:
TOON: Replace Character _currentPath static buffers with Common::Array.

Changed paths:
    engines/toon/character.cpp
    engines/toon/character.h



diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 2a28642..c9073de 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -56,7 +56,6 @@ Character::Character(ToonEngine *vm) : _vm(vm) {
 	_animScriptId = -1;
 	_animSpecialId = -1;
 	_animSpecialDefaultId = 0;
-	_currentPathNodeCount = 0;
 	_currentPathNode = 0;
 	_currentWalkStamp = 0;
 	_visible = true;
@@ -123,7 +122,7 @@ void Character::setFacing(int32 facing) {
 				_lastWalkTime = _vm->getOldMilli();
 			}
 
-			if	(_currentPathNode == 0)
+			if (_currentPathNode == 0)
 				playStandingAnim();
 			else
 				playWalkAnim(0, 0);
@@ -166,7 +165,7 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) {
 	_vm->getPathFinding()->resetBlockingRects();
 
 	// don't allow flux to go at the same position as drew
-	if (_id == 1 ) {
+	if (_id == 1) {
 		int16 sizeX = MAX<int16>(5, 30 * _vm->getDrew()->getScale() / 1024);
 		int16 sizeY = MAX<int16>(2, 20 * _vm->getDrew()->getScale() / 1024);
 		_vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY);
@@ -183,11 +182,9 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) {
 		int32 smoothDx = 0;
 		int32 smoothDy = 0;
 
-		for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) {
-			_currentPathX[a] = _vm->getPathFinding()->getPathNodeX(a);
-			_currentPathY[a] = _vm->getPathFinding()->getPathNodeY(a);
-		}
-		_currentPathNodeCount = _vm->getPathFinding()->getPathNodeCount();
+		_currentPath.clear();
+		for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++)
+			_currentPath.push_back(Common::Point(_vm->getPathFinding()->getPathNodeX(a), _vm->getPathFinding()->getPathNodeY(a)));
 		_currentPathNode = 0;
 		stopSpecialAnim();
 
@@ -202,12 +199,12 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) {
 		int32 localWalkStamp = _currentWalkStamp;
 
 		if (_blockingWalk) {
-			while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPathNodeCount && !_vm->shouldQuitGame()) {
-				if (_currentPathNode < _currentPathNodeCount - 4) {
-					int32 delta = MIN<int32>(4, _currentPathNodeCount - _currentPathNode);
+			while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPath.size() && !_vm->shouldQuitGame()) {
+				if (_currentPathNode < _currentPath.size() - 4) {
+					int32 delta = MIN<int32>(4, _currentPath.size() - _currentPathNode);
 
-					int32 dx = _currentPathX[_currentPathNode+delta] - _x;
-					int32 dy = _currentPathY[_currentPathNode+delta] - _y;
+					int16 dx = _currentPath[_currentPathNode+delta].x - _x;
+					int16 dy = _currentPath[_currentPathNode+delta].y - _y;
 
 					// smooth the facing computation. It prevents some ugly flickering from happening
 					if (!smoothDx && !smoothDy) {
@@ -226,9 +223,9 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) {
 				_numPixelToWalk += _speed * (_vm->getSystem()->getMillis() - _lastWalkTime) * _scale / 1024;
 				_lastWalkTime =  _vm->getSystem()->getMillis();
 
-				while (_numPixelToWalk >= 1000 && _currentPathNode < _currentPathNodeCount) {
-					_x = _currentPathX[_currentPathNode];
-					_y = _currentPathY[_currentPathNode];
+				while (_numPixelToWalk >= 1000 && _currentPathNode < _currentPath.size()) {
+					_x = _currentPath[_currentPathNode].x;
+					_y = _currentPath[_currentPathNode].y;
 					_currentPathNode += 1;
 					_numPixelToWalk -= 1000;
 				}
@@ -244,7 +241,7 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) {
 			playStandingAnim();
 			_flags &= ~0x1;
 			_currentPathNode = 0;
-			_currentPathNodeCount = 0;
+			_currentPath.clear();
 
 			if (_x != localFinalX || _y != localFinalY) {
 				return false;
@@ -348,12 +345,12 @@ void Character::stopSpecialAnim() {
 
 void Character::update(int32 timeIncrement) {
 	debugC(5, kDebugCharacter, "update(%d)", timeIncrement);
-	if ((_flags & 0x1) && _currentPathNodeCount > 0) {
-		if (_currentPathNode < _currentPathNodeCount) {
-			if (_currentPathNode < _currentPathNodeCount - 10) {
-				int32 delta = MIN<int32>(10, _currentPathNodeCount - _currentPathNode);
-				int32 dx = _currentPathX[_currentPathNode+delta] - _x;
-				int32 dy = _currentPathY[_currentPathNode+delta] - _y;
+	if ((_flags & 0x1) && _currentPath.size() > 0) {
+		if (_currentPathNode < _currentPath.size()) {
+			if (_currentPathNode < _currentPath.size() - 10) {
+				int32 delta = MIN<int32>(10, _currentPath.size() - _currentPathNode);
+				int16 dx = _currentPath[_currentPathNode+delta].x - _x;
+				int16 dy = _currentPath[_currentPathNode+delta].y - _y;
 				setFacing(getFacingFromDirection(dx, dy));
 				playWalkAnim(0, 0);
 			}
@@ -362,9 +359,9 @@ void Character::update(int32 timeIncrement) {
 			_numPixelToWalk += _speed * (_vm->getSystem()->getMillis() - _lastWalkTime) * _scale / 1024;
 			_lastWalkTime =  _vm->getSystem()->getMillis();
 
-			while (_numPixelToWalk > 1000 && _currentPathNode < _currentPathNodeCount) {
-				_x = _currentPathX[_currentPathNode];
-				_y = _currentPathY[_currentPathNode];
+			while (_numPixelToWalk > 1000 && _currentPathNode < _currentPath.size()) {
+				_x = _currentPath[_currentPathNode].x;
+				_y = _currentPath[_currentPathNode].y;
 				_currentPathNode += 1;
 				_numPixelToWalk -= 1000;
 			}
@@ -372,7 +369,7 @@ void Character::update(int32 timeIncrement) {
 		} else {
 			playStandingAnim();
 			_flags &= ~0x1;
-			_currentPathNodeCount = 0;
+			_currentPath.clear();
 		}
 	}
 
@@ -664,7 +661,7 @@ void Character::stopWalk() {
 	_finalY = _y;
 	_flags &= ~0x1;
 	_currentPathNode = 0;
-	_currentPathNodeCount = 0;
+	_currentPath.clear();
 }
 
 const SpecialCharacterAnimation *Character::getSpecialAnimation(int32 characterId, int32 animationId) {
@@ -996,8 +993,8 @@ bool Character::loadShadowAnimation(const Common::String &animName) {
 }
 
 void Character::plotPath(Graphics::Surface& surface) {
-	for (int i = 0; i < _currentPathNodeCount; i++) {
-		 *(byte *)surface.getBasePtr(_currentPathX[i], _currentPathY[i]) = ( i < _currentPathNode);
+	for (uint32 i = 0; i < _currentPath.size(); i++) {
+		 *(byte *)surface.getBasePtr(_currentPath[i].x, _currentPath[i].y) = (i < _currentPathNode);
 	}
 }
 
diff --git a/engines/toon/character.h b/engines/toon/character.h
index d2d84a8..d33c314 100644
--- a/engines/toon/character.h
+++ b/engines/toon/character.h
@@ -23,6 +23,9 @@
 #ifndef TOON_CHARACTER_H
 #define TOON_CHARACTER_H
 
+#include "common/array.h"
+#include "common/rect.h"
+
 #include "toon/toon.h"
 
 namespace Toon {
@@ -137,10 +140,8 @@ protected:
 	Animation *_shadowAnim;
 	Animation *_specialAnim;
 
-	int16 _currentPathX[4096];
-	int16 _currentPathY[4096];
-	int32 _currentPathNodeCount;
-	int32 _currentPathNode;
+	Common::Array<Common::Point> _currentPath;
+	uint32 _currentPathNode;
 	int32 _currentWalkStamp;
 };
 


Commit: 4aa0ec7fc4eae0941efb15affe664544c33822ea
    https://github.com/scummvm/scummvm/commit/4aa0ec7fc4eae0941efb15affe664544c33822ea
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-14T09:23:01-07:00

Commit Message:
TOON: Change Pathfinding weight buffers to uint16.

This should result in a significant saving in RAM usage.
Have added warning outputs if the weights exceed the maximum limit.

Changed paths:
    engines/toon/path.cpp
    engines/toon/path.h



diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index 735801e..7914aed 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -60,7 +60,7 @@ void PathFindingHeap::clear() {
 	memset(_data, 0, sizeof(HeapDataGrid) * _size);
 }
 
-void PathFindingHeap::push(int16 x, int16 y, int16 weight) {
+void PathFindingHeap::push(int16 x, int16 y, uint16 weight) {
 	debugC(2, kDebugPath, "push(%d, %d, %d)", x, y, weight);
 
 	if (_count == _size) {
@@ -104,7 +104,7 @@ void PathFindingHeap::push(int16 x, int16 y, int16 weight) {
 	}
 }
 
-void PathFindingHeap::pop(int16 *x, int16 *y, int16 *weight) {
+void PathFindingHeap::pop(int16 *x, int16 *y, uint16 *weight) {
 	debugC(2, kDebugPath, "pop(x, y, weight)");
 
 	if (!_count) {
@@ -170,7 +170,7 @@ void PathFinding::init(Picture *mask) {
 	_heap->unload();
 	_heap->init(500);
 	delete[] _sq;
-	_sq = new int32[_width * _height];
+	_sq = new uint16[_width * _height];
 }
 
 bool PathFinding::isLikelyWalkable(int16 x, int16 y) {
@@ -304,18 +304,16 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 	}
 
 	// no direct line, we use the standard A* algorithm
-	memset(_sq , 0, _width * _height * sizeof(int32));
+	memset(_sq , 0, _width * _height * sizeof(uint16));
 	_heap->clear();
 	int16 curX = x;
 	int16 curY = y;
-	int16 curWeight = 0;
+	uint16 curWeight = 0;
 
 	_sq[curX + curY *_width] = 1;
 	_heap->push(curX, curY, abs(destx - x) + abs(desty - y));
 
-	int16 wei;
 	while (_heap->getCount()) {
-		wei = 0;
 		_heap->pop(&curX, &curY, &curWeight);
 		int32 curNode = curX + curY * _width;
 
@@ -328,15 +326,23 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 		for (int16 px = startX; px <= endX && !next; px++) {
 			for (int16 py = startY; py <= endY && !next; py++) {
 				if (px != curX || py != curY) {
-					wei = abs(px - curX) + abs(py - curY);
+					uint16 wei = abs(px - curX) + abs(py - curY);
 
-					int32 curPNode = px + py * _width;
 					if (isWalkable(px, py)) { // walkable ?
-						int32 sum = _sq[curNode] + wei * (1 + (isLikelyWalkable(px, py) ? 5 : 0));
+						int32 curPNode = px + py * _width;
+						uint32 sum = _sq[curNode] + wei * (1 + (isLikelyWalkable(px, py) ? 5 : 0));
+						if (sum > (uint32)0xFFFF) {
+							warning("PathFinding::findPath sum exceeds maximum representable!");
+							sum = (uint32)0xFFFF;
+						}
 						if (_sq[curPNode] > sum || !_sq[curPNode]) {
-							int32 newWeight = abs(destx - px) + abs(desty - py);
 							_sq[curPNode] = sum;
-							_heap->push(px, py, _sq[curPNode] + newWeight);
+							uint32 newWeight = _sq[curPNode] + abs(destx - px) + abs(desty - py);
+							if (newWeight > (uint32)0xFFFF) {
+								warning("PathFinding::findPath newWeight exceeds maximum representable!");
+								newWeight = (uint16)0xFFFF;
+							}
+							_heap->push(px, py, newWeight);
 							if (!newWeight)
 								next = true; // we found it !
 						}
@@ -359,7 +365,7 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 	Common::Array<Common::Point> retPath;
 	retPath.push_back(Common::Point(curX, curY));
 
-	int32 bestscore = _sq[destx + desty * _width];
+	uint16 bestscore = _sq[destx + desty * _width];
 
 	bool retVal = false;
 	while (true) {
@@ -374,8 +380,6 @@ bool PathFinding::findPath(int16 x, int16 y, int16 destx, int16 desty) {
 		for (int16 px = startX; px <= endX; px++) {
 			for (int16 py = startY; py <= endY; py++) {
 				if (px != curX || py != curY) {
-					wei = abs(px - curX) + abs(py - curY);
-
 					int32 PNode = px + py * _width;
 					if (_sq[PNode] && (isWalkable(px, py))) {
 						if (_sq[PNode] < bestscore) {
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 2476dc3..59f74ef 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -36,8 +36,8 @@ public:
 	PathFindingHeap();
 	~PathFindingHeap();
 
-	void push(int16 x, int16 y, int16 weight);
-	void pop(int16 *x, int16 *y, int16 *weight);
+	void push(int16 x, int16 y, uint16 weight);
+	void pop(int16 *x, int16 *y, uint16 *weight);
 	void init(int32 size);
 	void clear();
 	void unload();
@@ -46,7 +46,7 @@ public:
 private:
 	struct HeapDataGrid {
 		int16 _x, _y;
-		int16 _weight;
+		uint16 _weight;
 	};
 
 	HeapDataGrid *_data;
@@ -84,7 +84,7 @@ private:
 
 	PathFindingHeap *_heap;
 
-	int32 *_sq;
+	uint16 *_sq;
 	int16 _width;
 	int16 _height;
 


Commit: 57d34d2576d38a2820afeae0ba860dc863a34b08
    https://github.com/scummvm/scummvm/commit/57d34d2576d38a2820afeae0ba860dc863a34b08
Author: D G Turner (digitall at scummvm.org)
Date: 2012-06-14T09:45:30-07:00

Commit Message:
Merge branch 'toon-RAM-reduction'

Changed paths:
    engines/toon/character.cpp
    engines/toon/character.h
    engines/toon/drew.cpp
    engines/toon/drew.h
    engines/toon/flux.cpp
    engines/toon/flux.h
    engines/toon/path.cpp
    engines/toon/path.h
    engines/toon/toon.cpp









More information about the Scummvm-git-logs mailing list