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

View file

@ -625,6 +625,7 @@ private:
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 @@ private:
_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
};

View file

@ -411,22 +411,23 @@ int pathLine(Point *pointList, const Point &point1, const Point &point2) {
}
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 @@ void Actor::removeNodes() {
}
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 @@ void Actor::removeNodes() {
// 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 @@ void Actor::condenseNodeList() {
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 @@ void Actor::condenseNodeList() {
_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 @@ void Actor::removePathPoints() {
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 @@ void Actor::removePathPoints() {
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 @@ void Actor::removePathPoints() {
// 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 @@ void Actor::removePathPoints() {
#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

View file

@ -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 {