[Scummvm-cvs-logs] SF.net SVN: scummvm:[40227] scummvm/trunk/engines/saga

h00ligan at users.sourceforge.net h00ligan at users.sourceforge.net
Fri May 1 12:37:42 CEST 2009


Revision: 40227
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40227&view=rev
Author:   h00ligan
Date:     2009-05-01 10:37:41 +0000 (Fri, 01 May 2009)

Log Message:
-----------
SAGA: fix SAGA_DEBUG&ACTOR_DEBUG enabled compilation; move Actor::_debugPoints into a Common::Array<DebugPoint>

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/actor.h
    scummvm/trunk/engines/saga/actor_path.cpp
    scummvm/trunk/engines/saga/objectmap.cpp

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2009-05-01 09:09:07 UTC (rev 40226)
+++ scummvm/trunk/engines/saga/actor.cpp	2009-05-01 10:37:41 UTC (rev 40227)
@@ -226,8 +226,7 @@
 	_objsCount = 0;
 
 #ifdef ACTOR_DEBUG
-	_debugPoints = NULL;
-	_debugPointsAlloced = _debugPointsCount = 0;
+	_debugPointsCount = 0;
 #endif
 
 	_protagStates = NULL;
@@ -321,9 +320,6 @@
 Actor::~Actor() {
 	debug(9, "Actor::~Actor()");
 
-#ifdef ACTOR_DEBUG
-	free(_debugPoints);
-#endif
 	free(_pathList);
 	free(_pathCell);
 	_actorsStrings.freeMem();

Modified: scummvm/trunk/engines/saga/actor.h
===================================================================
--- scummvm/trunk/engines/saga/actor.h	2009-05-01 09:09:07 UTC (rev 40226)
+++ scummvm/trunk/engines/saga/actor.h	2009-05-01 10:37:41 UTC (rev 40227)
@@ -625,6 +625,7 @@
 		PathNode(const Point &p) : point(p), link(0) {}
 		PathNode(const Point &p, int l) : point(p), link(l) {}
 	};
+	typedef Common::Array<PathNode> PathNodeList;
 
 	Rect _barrierList[ACTOR_BARRIERS_MAX];
 	int _barrierCount;
@@ -647,25 +648,34 @@
 		_pathList[_pathListIndex] = point;
 	}
 
-	Common::Array<PathNode> _pathNodeList;
+	PathNodeList _pathNodeList;
 
 public:
 #ifdef ACTOR_DEBUG
+#ifndef SAGA_DEBUG
+	you must also define SAGA_DEBUG
+#endif
 //path debug - use with care
 	struct DebugPoint {
 		Point point;
 		byte color;
+		
+		DebugPoint() : color(0) {}
+
+		DebugPoint(const Point &p, byte c): point(p), color(c) {}
 	};
-	DebugPoint *_debugPoints;
-	int _debugPointsCount;
-	int _debugPointsAlloced;
+
+	Common::Array<DebugPoint> _debugPoints;
+	uint _debugPointsCount;
+	// we still need this trick to speedup debug points addition
 	void addDebugPoint(const Point &point, byte color) {
-		if (_debugPointsCount + 1 > _debugPointsAlloced) {
-			_debugPointsAlloced += 1000;
-			_debugPoints = (DebugPoint*) realloc(_debugPoints, _debugPointsAlloced * sizeof(*_debugPoints));
+		if (_debugPointsCount < _debugPoints.size()) {
+			_debugPoints[_debugPointsCount].point = point;
+			_debugPoints[_debugPointsCount].color = color;
+		} else {
+			_debugPoints.push_back(DebugPoint(point, color));
 		}
-		_debugPoints[_debugPointsCount].color = color;
-		_debugPoints[_debugPointsCount++].point = point;
+		++_debugPointsCount;
 	}
 #endif
 };

Modified: scummvm/trunk/engines/saga/actor_path.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor_path.cpp	2009-05-01 09:09:07 UTC (rev 40226)
+++ scummvm/trunk/engines/saga/actor_path.cpp	2009-05-01 10:37:41 UTC (rev 40227)
@@ -411,22 +411,23 @@
 }
 
 void Actor::nodeToPath() {
-	int i;
+	uint i;
+	int j;
 	Point point1, point2;
 	Point *point;
 
-	for (i = 0, point = _pathList; i < _pathListAlloced; i++, point++) {
+	for (j = 0, point = _pathList; j < _pathListAlloced; j++, point++) {
 		point->x = point->y = PATH_NODE_EMPTY;
 	}
 
 	_pathListIndex = 1;
 	_pathList[0] = _pathNodeList[0].point;
 	_pathNodeList[0].link = 0;
-	for (i = 0; i < (int)_pathNodeList.size() - 1; i++) {
+	for (i = 0; i < _pathNodeList.size() - 1; i++) {
 		point1 = _pathNodeList[i].point;
-		point2 = _pathNodeList[i+1].point;
+		point2 = _pathNodeList[i + 1].point;
 		_pathListIndex += pathLine(&_pathList[_pathListIndex], point1, point2);
-		_pathNodeList[i+1].link = _pathListIndex - 1;
+		_pathNodeList[i + 1].link = _pathListIndex - 1;
 	}
 	_pathListIndex--;
 	_pathNodeList.back().link = _pathListIndex;
@@ -475,7 +476,7 @@
 		}
 
 		if (scanPathLine(_pathNodeList.back().point, _pathNodeList[i].point)) {
-			for (j = i + 1; j < _pathNodeList.size()-1; j++) {
+			for (j = i + 1; j < _pathNodeList.size() - 1; j++) {
 				_pathNodeList[j].point.x = PATH_NODE_EMPTY;
 			}
 			break;
@@ -485,11 +486,11 @@
 
 	// Finally, try arbitrary combinations of non-adjacent nodes and see
 	// if we can skip over any of them.
-	for (i = 1; i < _pathNodeList.size()-1 - 1; i++) {
+	for (i = 1; i < _pathNodeList.size() - 2; i++) {
 		if (_pathNodeList[i].point.x == PATH_NODE_EMPTY) {
 			continue;
 		}
-		for (j = i + 2; j < _pathNodeList.size()-1; j++) {
+		for (j = i + 2; j < _pathNodeList.size() - 1; j++) {
 			if (_pathNodeList[j].point.x == PATH_NODE_EMPTY) {
 				continue;
 			}
@@ -509,7 +510,7 @@
 	uint i, j, count;
 
 	count = _pathNodeList.size();
-	for (i = 1; i < _pathNodeList.size()-1; i++) {
+	for (i = 1; i < _pathNodeList.size() - 1; i++) {
 		if (_pathNodeList[i].point.x == PATH_NODE_EMPTY) {
 			j = i + 1;
 			while (_pathNodeList[j].point.x == PATH_NODE_EMPTY) {
@@ -518,7 +519,7 @@
 			_pathNodeList[i] = _pathNodeList[j];
 			count = i + 1;
 			_pathNodeList[j].point.x = PATH_NODE_EMPTY;
-			if (j == _pathNodeList.size()-1) {
+			if (j == _pathNodeList.size() - 1) {
 				break;
 			}
 		}
@@ -535,13 +536,13 @@
 	if (_pathNodeList.size() <= 2)
 		return;
 
-	Common::Array<PathNode> newPathNodeList;
+	PathNodeList newPathNodeList;
 
 	// Add the first node
 	newPathNodeList.push_back(_pathNodeList.front());
 
 	// Process all nodes between the first and the last.
-	for (i = 1; i < _pathNodeList.size()-1; i++) {
+	for (i = 1; i < _pathNodeList.size() - 1; i++) {
 		newPathNodeList.push_back(_pathNodeList[i]);
 
 		for (j = 5; j > 0; j--) {
@@ -561,10 +562,10 @@
 			if (scanPathLine(point1, point2)) {
 				for (l = 1; l < newPathNodeList.size(); l++) {
 					if (start <= newPathNodeList[l].link) {
-						newPathNodeList.resize(l+1);
+						newPathNodeList.resize(l + 1);
 						newPathNodeList.back().point = point1;
 						newPathNodeList.back().link = start;
-						newPathNodeList.resize(l+2);
+						newPathNodeList.resize(l + 2);
 						break;
 					}
 				}
@@ -585,7 +586,7 @@
 	// Copy newPathNodeList into _pathNodeList, skipping any duplicate points
 	_pathNodeList.clear();
 	for (i = 0; i < newPathNodeList.size(); i++) {
-		if (newPathNodeList.size()-1 == i || (newPathNodeList[i].point != newPathNodeList[i+1].point)) {
+		if (((newPathNodeList.size() - 1) == i) || (newPathNodeList[i].point != newPathNodeList[i + 1].point)) {
 			_pathNodeList.push_back(newPathNodeList[i]);
 		}
 	}
@@ -593,15 +594,10 @@
 
 #ifdef ACTOR_DEBUG
 void Actor::drawPathTest() {
-	int i;
-	Surface *surface;
-	surface = _vm->_gfx->getBackBuffer();
-	if (_debugPoints == NULL) {
-		return;
-	}
+	uint i;
 
 	for (i = 0; i < _debugPointsCount; i++) {
-		*((byte *)surface->pixels + (_debugPoints[i].point.y * surface->pitch) + _debugPoints[i].point.x) = _debugPoints[i].color;
+		_vm->_gfx->setPixelColor(_debugPoints[i].point.x, _debugPoints[i].point.y, _debugPoints[i].color);
 	}
 }
 #endif

Modified: scummvm/trunk/engines/saga/objectmap.cpp
===================================================================
--- scummvm/trunk/engines/saga/objectmap.cpp	2009-05-01 09:09:07 UTC (rev 40226)
+++ scummvm/trunk/engines/saga/objectmap.cpp	2009-05-01 10:37:41 UTC (rev 40227)
@@ -39,6 +39,9 @@
 #include "saga/actor.h"
 #include "saga/scene.h"
 #include "saga/isomap.h"
+#ifdef SAGA_DEBUG
+#include "saga/render.h"
+#endif
 
 namespace Saga {
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list