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

svn-id: r40227
This commit is contained in:
Andrew Kurushin 2009-05-01 10:37:41 +00:00
parent bb2540a4d1
commit 600a471122
4 changed files with 41 additions and 36 deletions

View file

@ -226,8 +226,7 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {
_objsCount = 0; _objsCount = 0;
#ifdef ACTOR_DEBUG #ifdef ACTOR_DEBUG
_debugPoints = NULL; _debugPointsCount = 0;
_debugPointsAlloced = _debugPointsCount = 0;
#endif #endif
_protagStates = NULL; _protagStates = NULL;
@ -321,9 +320,6 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) {
Actor::~Actor() { Actor::~Actor() {
debug(9, "Actor::~Actor()"); debug(9, "Actor::~Actor()");
#ifdef ACTOR_DEBUG
free(_debugPoints);
#endif
free(_pathList); free(_pathList);
free(_pathCell); free(_pathCell);
_actorsStrings.freeMem(); _actorsStrings.freeMem();

View file

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

View file

@ -411,18 +411,19 @@ int pathLine(Point *pointList, const Point &point1, const Point &point2) {
} }
void Actor::nodeToPath() { void Actor::nodeToPath() {
int i; uint i;
int j;
Point point1, point2; Point point1, point2;
Point *point; 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; point->x = point->y = PATH_NODE_EMPTY;
} }
_pathListIndex = 1; _pathListIndex = 1;
_pathList[0] = _pathNodeList[0].point; _pathList[0] = _pathNodeList[0].point;
_pathNodeList[0].link = 0; _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; point1 = _pathNodeList[i].point;
point2 = _pathNodeList[i + 1].point; point2 = _pathNodeList[i + 1].point;
_pathListIndex += pathLine(&_pathList[_pathListIndex], point1, point2); _pathListIndex += pathLine(&_pathList[_pathListIndex], point1, point2);
@ -485,7 +486,7 @@ void Actor::removeNodes() {
// Finally, try arbitrary combinations of non-adjacent nodes and see // Finally, try arbitrary combinations of non-adjacent nodes and see
// if we can skip over any of them. // 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) { if (_pathNodeList[i].point.x == PATH_NODE_EMPTY) {
continue; continue;
} }
@ -535,7 +536,7 @@ void Actor::removePathPoints() {
if (_pathNodeList.size() <= 2) if (_pathNodeList.size() <= 2)
return; return;
Common::Array<PathNode> newPathNodeList; PathNodeList newPathNodeList;
// Add the first node // Add the first node
newPathNodeList.push_back(_pathNodeList.front()); newPathNodeList.push_back(_pathNodeList.front());
@ -585,7 +586,7 @@ void Actor::removePathPoints() {
// Copy newPathNodeList into _pathNodeList, skipping any duplicate points // Copy newPathNodeList into _pathNodeList, skipping any duplicate points
_pathNodeList.clear(); _pathNodeList.clear();
for (i = 0; i < newPathNodeList.size(); i++) { 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]); _pathNodeList.push_back(newPathNodeList[i]);
} }
} }
@ -593,15 +594,10 @@ void Actor::removePathPoints() {
#ifdef ACTOR_DEBUG #ifdef ACTOR_DEBUG
void Actor::drawPathTest() { void Actor::drawPathTest() {
int i; uint i;
Surface *surface;
surface = _vm->_gfx->getBackBuffer();
if (_debugPoints == NULL) {
return;
}
for (i = 0; i < _debugPointsCount; 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 #endif

View file

@ -39,6 +39,9 @@
#include "saga/actor.h" #include "saga/actor.h"
#include "saga/scene.h" #include "saga/scene.h"
#include "saga/isomap.h" #include "saga/isomap.h"
#ifdef SAGA_DEBUG
#include "saga/render.h"
#endif
namespace Saga { namespace Saga {