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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Apr 28 14:33:39 CEST 2009


Revision: 40179
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40179&view=rev
Author:   fingolfin
Date:     2009-04-28 12:33:38 +0000 (Tue, 28 Apr 2009)

Log Message:
-----------
SAGA: Moved some code from actor.h to actor.cpp; replaced Actor::_pathDirectionList and related members by a Common::Array<PathDirectionData> inside Actor::fillPathArray()

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

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2009-04-28 12:32:59 UTC (rev 40178)
+++ scummvm/trunk/engines/saga/actor.cpp	2009-04-28 12:33:38 UTC (rev 40179)
@@ -41,6 +41,140 @@
 
 namespace Saga {
 
+ActorData::ActorData() {
+	memset(this, 0, sizeof(*this));
+}
+
+ActorData::~ActorData() {
+	if (!_shareFrames)
+		free(_frames);
+	free(_tileDirections);
+	free(_walkStepsPoints);
+	freeSpriteList();
+}
+void ActorData::saveState(Common::OutSaveFile *out) {
+	int i = 0;
+	CommonObjectData::saveState(out);
+	out->writeUint16LE(_actorFlags);
+	out->writeSint32LE(_currentAction);
+	out->writeSint32LE(_facingDirection);
+	out->writeSint32LE(_actionDirection);
+	out->writeSint32LE(_actionCycle);
+	out->writeUint16LE(_targetObject);
+
+	out->writeSint32LE(_cycleFrameSequence);
+	out->writeByte(_cycleDelay);
+	out->writeByte(_cycleTimeCount);
+	out->writeByte(_cycleFlags);
+	out->writeSint16LE(_fallVelocity);
+	out->writeSint16LE(_fallAcceleration);
+	out->writeSint16LE(_fallPosition);
+	out->writeByte(_dragonBaseFrame);
+	out->writeByte(_dragonStepCycle);
+	out->writeByte(_dragonMoveType);
+	out->writeSint32LE(_frameNumber);
+
+	out->writeSint32LE(_tileDirectionsAlloced);
+	for (i = 0; i < _tileDirectionsAlloced; i++) {
+		out->writeByte(_tileDirections[i]);
+	}
+
+	out->writeSint32LE(_walkStepsAlloced);
+	for (i = 0; i < _walkStepsAlloced; i++) {
+		out->writeSint16LE(_walkStepsPoints[i].x);
+		out->writeSint16LE(_walkStepsPoints[i].y);
+	}
+
+	out->writeSint32LE(_walkStepsCount);
+	out->writeSint32LE(_walkStepIndex);
+	_finalTarget.saveState(out);
+	_partialTarget.saveState(out);
+	out->writeSint32LE(_walkFrameSequence);
+}
+
+void ActorData::loadState(uint32 version, Common::InSaveFile *in) {
+	int i = 0;
+	CommonObjectData::loadState(in);
+	_actorFlags = in->readUint16LE();
+	_currentAction = in->readSint32LE();
+	_facingDirection = in->readSint32LE();
+	_actionDirection = in->readSint32LE();
+	_actionCycle = in->readSint32LE();
+	_targetObject = in->readUint16LE();
+
+	_lastZone = NULL;
+	_cycleFrameSequence = in->readSint32LE();
+	_cycleDelay = in->readByte();
+	_cycleTimeCount = in->readByte();
+	_cycleFlags = in->readByte();
+	if (version > 1) {
+		_fallVelocity = in->readSint16LE();
+		_fallAcceleration = in->readSint16LE();
+		_fallPosition = in->readSint16LE();
+	} else {
+		_fallVelocity = _fallAcceleration = _fallPosition = 0;
+	}
+	if (version > 2) {
+		_dragonBaseFrame = in->readByte();
+		_dragonStepCycle = in->readByte();
+		_dragonMoveType = in->readByte();
+	} else {
+		_dragonBaseFrame = _dragonStepCycle = _dragonMoveType = 0;
+	}
+
+	_frameNumber = in->readSint32LE();
+
+
+	setTileDirectionsSize(in->readSint32LE(), true);
+	for (i = 0; i < _tileDirectionsAlloced; i++) {
+		_tileDirections[i] = in->readByte();
+	}
+
+	setWalkStepsPointsSize(in->readSint32LE(), true);
+	for (i = 0; i < _walkStepsAlloced; i++) {
+		_walkStepsPoints[i].x = in->readSint16LE();
+		_walkStepsPoints[i].y = in->readSint16LE();
+	}
+
+	_walkStepsCount = in->readSint32LE();
+	_walkStepIndex = in->readSint32LE();
+	_finalTarget.loadState(in);
+	_partialTarget.loadState(in);
+	_walkFrameSequence = in->readSint32LE();
+}
+
+void ActorData::setTileDirectionsSize(int size, bool forceRealloc) {
+	if ((size <= _tileDirectionsAlloced) && !forceRealloc) {
+		return;
+	}
+	_tileDirectionsAlloced = size;
+	_tileDirections = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
+}
+
+void ActorData::cycleWrap(int cycleLimit) {
+	if (_actionCycle >= cycleLimit)
+		_actionCycle = 0;
+}
+
+void ActorData::setWalkStepsPointsSize(int size, bool forceRealloc) {
+	if ((size <= _walkStepsAlloced) && !forceRealloc) {
+		return;
+	}
+	_walkStepsAlloced = size;
+	_walkStepsPoints = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
+}
+
+void ActorData::addWalkStepPoint(const Point &point) {
+	setWalkStepsPointsSize(_walkStepsCount + 1, false);
+	_walkStepsPoints[_walkStepsCount++] = point;
+}
+
+void ActorData::freeSpriteList() {
+	_spriteList.freeMem();
+}
+
+
+
 static int commonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) {
 	int p1 = obj1->_location.y - obj1->_location.z;
 	int p2 = obj2->_location.y - obj2->_location.z;
@@ -101,11 +235,8 @@
 
 	_pathNodeList = _newPathNodeList = NULL;
 	_pathList = NULL;
-	_pathDirectionList = NULL;
 	_pathListAlloced = _pathNodeListAlloced = _newPathNodeListAlloced = 0;
 	_pathListIndex = _pathNodeListIndex = _newPathNodeListIndex = -1;
-	_pathDirectionListCount = 0;
-	_pathDirectionListAlloced = 0;
 
 	_centerActor = _protagonist = NULL;
 	_protagState = 0;
@@ -194,7 +325,6 @@
 #ifdef ACTOR_DEBUG
 	free(_debugPoints);
 #endif
-	free(_pathDirectionList);
 	free(_pathNodeList);
 	free(_newPathNodeList);
 	free(_pathList);

Modified: scummvm/trunk/engines/saga/actor.h
===================================================================
--- scummvm/trunk/engines/saga/actor.h	2009-04-28 12:32:59 UTC (rev 40178)
+++ scummvm/trunk/engines/saga/actor.h	2009-04-28 12:33:38 UTC (rev 40179)
@@ -390,137 +390,17 @@
 	int32 _walkFrameSequence;
 
 public:
-	void saveState(Common::OutSaveFile *out) {
-		int i = 0;
-		CommonObjectData::saveState(out);
-		out->writeUint16LE(_actorFlags);
-		out->writeSint32LE(_currentAction);
-		out->writeSint32LE(_facingDirection);
-		out->writeSint32LE(_actionDirection);
-		out->writeSint32LE(_actionCycle);
-		out->writeUint16LE(_targetObject);
+	ActorData();
+	~ActorData();
 
-		out->writeSint32LE(_cycleFrameSequence);
-		out->writeByte(_cycleDelay);
-		out->writeByte(_cycleTimeCount);
-		out->writeByte(_cycleFlags);
-		out->writeSint16LE(_fallVelocity);
-		out->writeSint16LE(_fallAcceleration);
-		out->writeSint16LE(_fallPosition);
-		out->writeByte(_dragonBaseFrame);
-		out->writeByte(_dragonStepCycle);
-		out->writeByte(_dragonMoveType);
-		out->writeSint32LE(_frameNumber);
+	void saveState(Common::OutSaveFile *out);
+	void loadState(uint32 version, Common::InSaveFile *in);
 
-		out->writeSint32LE(_tileDirectionsAlloced);
-		for (i = 0; i < _tileDirectionsAlloced; i++) {
-			out->writeByte(_tileDirections[i]);
-		}
-
-		out->writeSint32LE(_walkStepsAlloced);
-		for (i = 0; i < _walkStepsAlloced; i++) {
-			out->writeSint16LE(_walkStepsPoints[i].x);
-			out->writeSint16LE(_walkStepsPoints[i].y);
-		}
-
-		out->writeSint32LE(_walkStepsCount);
-		out->writeSint32LE(_walkStepIndex);
-		_finalTarget.saveState(out);
-		_partialTarget.saveState(out);
-		out->writeSint32LE(_walkFrameSequence);
-	}
-
-	void loadState(uint32 version, Common::InSaveFile *in) {
-		int i = 0;
-		CommonObjectData::loadState(in);
-		_actorFlags = in->readUint16LE();
-		_currentAction = in->readSint32LE();
-		_facingDirection = in->readSint32LE();
-		_actionDirection = in->readSint32LE();
-		_actionCycle = in->readSint32LE();
-		_targetObject = in->readUint16LE();
-
-		_lastZone = NULL;
-		_cycleFrameSequence = in->readSint32LE();
-		_cycleDelay = in->readByte();
-		_cycleTimeCount = in->readByte();
-		_cycleFlags = in->readByte();
-		if (version > 1) {
-			_fallVelocity = in->readSint16LE();
-			_fallAcceleration = in->readSint16LE();
-			_fallPosition = in->readSint16LE();
-		} else {
-			_fallVelocity = _fallAcceleration = _fallPosition = 0;
-		}
-		if (version > 2) {
-			_dragonBaseFrame = in->readByte();
-			_dragonStepCycle = in->readByte();
-			_dragonMoveType = in->readByte();
-		} else {
-			_dragonBaseFrame = _dragonStepCycle = _dragonMoveType = 0;
-		}
-
-		_frameNumber = in->readSint32LE();
-
-
-		setTileDirectionsSize(in->readSint32LE(), true);
-		for (i = 0; i < _tileDirectionsAlloced; i++) {
-			_tileDirections[i] = in->readByte();
-		}
-
-		setWalkStepsPointsSize(in->readSint32LE(), true);
-		for (i = 0; i < _walkStepsAlloced; i++) {
-			_walkStepsPoints[i].x = in->readSint16LE();
-			_walkStepsPoints[i].y = in->readSint16LE();
-		}
-
-		_walkStepsCount = in->readSint32LE();
-		_walkStepIndex = in->readSint32LE();
-		_finalTarget.loadState(in);
-		_partialTarget.loadState(in);
-		_walkFrameSequence = in->readSint32LE();
-	}
-
-	void setTileDirectionsSize(int size, bool forceRealloc) {
-		if ((size <= _tileDirectionsAlloced) && !forceRealloc) {
-			return;
-		}
-		_tileDirectionsAlloced = size;
-		_tileDirections = (byte*)realloc(_tileDirections, _tileDirectionsAlloced * sizeof(*_tileDirections));
-	}
-
-	void cycleWrap(int cycleLimit) {
-		if (_actionCycle >= cycleLimit)
-			_actionCycle = 0;
-	}
-
-	void setWalkStepsPointsSize(int size, bool forceRealloc) {
-		if ((size <= _walkStepsAlloced) && !forceRealloc) {
-			return;
-		}
-		_walkStepsAlloced = size;
-		_walkStepsPoints = (Point*)realloc(_walkStepsPoints, _walkStepsAlloced * sizeof(*_walkStepsPoints));
-	}
-
-	void addWalkStepPoint(const Point &point) {
-		setWalkStepsPointsSize(_walkStepsCount + 1, false);
-		_walkStepsPoints[_walkStepsCount++] = point;
-	}
-
-	void freeSpriteList() {
-		_spriteList.freeMem();
-	}
-
-	ActorData() {
-		memset(this, 0, sizeof(*this));
-	}
-	~ActorData() {
-		if (!_shareFrames)
-			free(_frames);
-		free(_tileDirections);
-		free(_walkStepsPoints);
-		freeSpriteList();
-	}
+	void setTileDirectionsSize(int size, bool forceRealloc);
+	void cycleWrap(int cycleLimit);
+	void setWalkStepsPointsSize(int size, bool forceRealloc);
+	void addWalkStepPoint(const Point &point);
+	void freeSpriteList();
 };
 
 struct ProtagStateData {
@@ -750,17 +630,6 @@
 	int _yCellCount;
 	Rect _pathRect;
 
-	PathDirectionData *_pathDirectionList;
-	int _pathDirectionListCount;
-	int _pathDirectionListAlloced;
-	PathDirectionData * addPathDirectionListData() {
-		if (_pathDirectionListCount + 1 >= _pathDirectionListAlloced) {
-			_pathDirectionListAlloced += 100;
-			_pathDirectionList = (PathDirectionData*) realloc(_pathDirectionList, _pathDirectionListAlloced * sizeof(*_pathDirectionList));
-		}
-		return &_pathDirectionList[_pathDirectionListCount++];
-	}
-
 	Point *_pathList;
 	int _pathListIndex;
 	int _pathListAlloced;

Modified: scummvm/trunk/engines/saga/actor_path.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor_path.cpp	2009-04-28 12:32:59 UTC (rev 40178)
+++ scummvm/trunk/engines/saga/actor_path.cpp	2009-04-28 12:33:38 UTC (rev 40179)
@@ -224,27 +224,23 @@
 int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &bestPoint) {
 	int bestRating;
 	int currentRating;
-	int i;
 	Point bestPath;
 	int pointCounter;
 	int startDirection;
-	PathDirectionData *pathDirection;
-	PathDirectionData *newPathDirection;
 	const PathDirectionData *samplePathDirection;
 	Point nextPoint;
 	int directionCount;
 	int16 compressX = (_vm->getGameId() == GID_ITE) ? 2 : 1;
 
-	_pathDirectionListCount = 0;
+	Common::Array<PathDirectionData> pathDirectionList;
+
 	pointCounter = 0;
 	bestRating = quickDistance(fromPoint, toPoint, compressX);
 	bestPath = fromPoint;
 
 	for (startDirection = 0; startDirection < 4; startDirection++) {
-		newPathDirection = addPathDirectionListData();
-		newPathDirection->x = fromPoint.x;
-		newPathDirection->y = fromPoint.y;
-		newPathDirection->direction = startDirection;
+		PathDirectionData tmp = { startDirection, fromPoint.x, fromPoint.y };
+		pathDirectionList.push_back(tmp);
 	}
 
 	if (validPathCellPoint(fromPoint)) {
@@ -255,13 +251,10 @@
 #endif
 	}
 
-	i = 0;
-
-	do {
-		pathDirection = &_pathDirectionList[i];
+	for (uint i = 0; i < pathDirectionList.size(); ++i) {
 		for (directionCount = 0; directionCount < 3; directionCount++) {
-			samplePathDirection = &pathDirectionLUT[pathDirection->direction][directionCount];
-			nextPoint = Point(pathDirection->x, pathDirection->y);
+			samplePathDirection = &pathDirectionLUT[pathDirectionList[i].direction][directionCount];
+			nextPoint = Point(pathDirectionList[i].x, pathDirectionList[i].y);
 			nextPoint.x += samplePathDirection->x;
 			nextPoint.y += samplePathDirection->y;
 
@@ -278,10 +271,10 @@
 #ifdef ACTOR_DEBUG
 			addDebugPoint(nextPoint, samplePathDirection->direction + 96);
 #endif
-			newPathDirection = addPathDirectionListData();
-			newPathDirection->x = nextPoint.x;
-			newPathDirection->y = nextPoint.y;
-			newPathDirection->direction = samplePathDirection->direction;
+			PathDirectionData tmp = {
+				samplePathDirection->direction,
+				nextPoint.x, nextPoint.y };
+			pathDirectionList.push_back(tmp);
 			++pointCounter;
 			if (nextPoint == toPoint) {
 				bestPoint = toPoint;
@@ -292,10 +285,8 @@
 				bestRating = currentRating;
 				bestPath = nextPoint;
 			}
-			pathDirection = &_pathDirectionList[i];
 		}
-		++i;
-	} while (i < _pathDirectionListCount);
+	}
 
 	bestPoint = bestPath;
 	return pointCounter;


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