diff options
author | Max Horn | 2009-04-28 12:33:38 +0000 |
---|---|---|
committer | Max Horn | 2009-04-28 12:33:38 +0000 |
commit | 7cfa3bb6d905b429d82ef0ead88354209a1f53a5 (patch) | |
tree | 23a7e351db669c7ff1992aca4c3481964bb31af5 /engines | |
parent | e6a7b8ef343f7e4fd2637500afe800794fe03a78 (diff) | |
download | scummvm-rg350-7cfa3bb6d905b429d82ef0ead88354209a1f53a5.tar.gz scummvm-rg350-7cfa3bb6d905b429d82ef0ead88354209a1f53a5.tar.bz2 scummvm-rg350-7cfa3bb6d905b429d82ef0ead88354209a1f53a5.zip |
SAGA: Moved some code from actor.h to actor.cpp; replaced Actor::_pathDirectionList and related members by a Common::Array<PathDirectionData> inside Actor::fillPathArray()
svn-id: r40179
Diffstat (limited to 'engines')
-rw-r--r-- | engines/saga/actor.cpp | 138 | ||||
-rw-r--r-- | engines/saga/actor.h | 149 | ||||
-rw-r--r-- | engines/saga/actor_path.cpp | 33 |
3 files changed, 155 insertions, 165 deletions
diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp index 9e44a47522..c6d3e38732 100644 --- a/engines/saga/actor.cpp +++ b/engines/saga/actor.cpp @@ -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 @@ Actor::Actor(SagaEngine *vm) : _vm(vm) { _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 @@ Actor::~Actor() { #ifdef ACTOR_DEBUG free(_debugPoints); #endif - free(_pathDirectionList); free(_pathNodeList); free(_newPathNodeList); free(_pathList); diff --git a/engines/saga/actor.h b/engines/saga/actor.h index a46de5d292..263ba8a3e7 100644 --- a/engines/saga/actor.h +++ b/engines/saga/actor.h @@ -390,137 +390,17 @@ public: 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); - - 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 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; - } + ActorData(); + ~ActorData(); - _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(); - } + void saveState(Common::OutSaveFile *out); + void loadState(uint32 version, Common::InSaveFile *in); - 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 @@ private: 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; diff --git a/engines/saga/actor_path.cpp b/engines/saga/actor_path.cpp index 716a0742a2..1112f4d853 100644 --- a/engines/saga/actor_path.cpp +++ b/engines/saga/actor_path.cpp @@ -224,27 +224,23 @@ bool Actor::scanPathLine(const Point &point1, const Point &point2) { 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 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be #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 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be #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 @@ int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &be bestRating = currentRating; bestPath = nextPoint; } - pathDirection = &_pathDirectionList[i]; } - ++i; - } while (i < _pathDirectionListCount); + } bestPoint = bestPath; return pointCounter; |