From 600a4711224e5a699143013f111e9bf69dd7f13f Mon Sep 17 00:00:00 2001 From: Andrew Kurushin Date: Fri, 1 May 2009 10:37:41 +0000 Subject: SAGA: fix SAGA_DEBUG&ACTOR_DEBUG enabled compilation; move Actor::_debugPoints into a Common::Array svn-id: r40227 --- engines/saga/actor.cpp | 6 +----- engines/saga/actor.h | 28 +++++++++++++++++++--------- engines/saga/actor_path.cpp | 40 ++++++++++++++++++---------------------- engines/saga/objectmap.cpp | 3 +++ 4 files changed, 41 insertions(+), 36 deletions(-) (limited to 'engines/saga') diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp index 6ca96c46e9..f0efc8e85d 100644 --- a/engines/saga/actor.cpp +++ b/engines/saga/actor.cpp @@ -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(); diff --git a/engines/saga/actor.h b/engines/saga/actor.h index 85df356cec..01f0f8d775 100644 --- a/engines/saga/actor.h +++ b/engines/saga/actor.h @@ -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 PathNodeList; Rect _barrierList[ACTOR_BARRIERS_MAX]; int _barrierCount; @@ -647,25 +648,34 @@ private: _pathList[_pathListIndex] = point; } - Common::Array _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 _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 }; diff --git a/engines/saga/actor_path.cpp b/engines/saga/actor_path.cpp index ad3b0413df..a0a80f7ada 100644 --- a/engines/saga/actor_path.cpp +++ b/engines/saga/actor_path.cpp @@ -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 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 diff --git a/engines/saga/objectmap.cpp b/engines/saga/objectmap.cpp index d259472d3d..475eedc048 100644 --- a/engines/saga/objectmap.cpp +++ b/engines/saga/objectmap.cpp @@ -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 { -- cgit v1.2.3